]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.4.5-201207161807.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.5-201207161807.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b4a898f..a0e01d0 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,9 +51,11 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 @@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41 +PERF*
42 SCCS
43 System.map*
44 TAGS
45 @@ -80,6 +86,7 @@ aic7*seq.h*
46 aicasm
47 aicdb.h*
48 altivec*.c
49 +ashldi3.S
50 asm-offsets.h
51 asm_offsets.h
52 autoconf.h*
53 @@ -92,19 +99,24 @@ bounds.h
54 bsetup
55 btfixupprep
56 build
57 +builtin-policy.h
58 bvmlinux
59 bzImage*
60 capability_names.h
61 capflags.c
62 classlist.h*
63 +clut_vga16.c
64 +common-cmds.h
65 comp*.log
66 compile.h*
67 conf
68 config
69 config-*
70 config_data.h*
71 +config.c
72 config.mak
73 config.mak.autogen
74 +config.tmp
75 conmakehash
76 consolemap_deftbl.c*
77 cpustr.h
78 @@ -115,9 +127,11 @@ devlist.h*
79 dnotify_test
80 docproc
81 dslm
82 +dtc-lexer.lex.c
83 elf2ecoff
84 elfconfig.h*
85 evergreen_reg_safe.h
86 +exception_policy.conf
87 fixdep
88 flask.h
89 fore200e_mkfirm
90 @@ -125,12 +139,15 @@ fore200e_pca_fw.c*
91 gconf
92 gconf.glade.h
93 gen-devlist
94 +gen-kdb_cmds.c
95 gen_crc32table
96 gen_init_cpio
97 generated
98 genheaders
99 genksyms
100 *_gray256.c
101 +hash
102 +hid-example
103 hpet_example
104 hugepage-mmap
105 hugepage-shm
106 @@ -145,7 +162,7 @@ int32.c
107 int4.c
108 int8.c
109 kallsyms
110 -kconfig
111 +kern_constants.h
112 keywords.c
113 ksym.c*
114 ksym.h*
115 @@ -153,7 +170,7 @@ kxgettext
116 lkc_defs.h
117 lex.c
118 lex.*.c
119 -linux
120 +lib1funcs.S
121 logo_*.c
122 logo_*_clut224.c
123 logo_*_mono.c
124 @@ -164,14 +181,15 @@ machtypes.h
125 map
126 map_hugetlb
127 maui_boot.h
128 -media
129 mconf
130 +mdp
131 miboot*
132 mk_elfconfig
133 mkboot
134 mkbugboot
135 mkcpustr
136 mkdep
137 +mkpiggy
138 mkprep
139 mkregtable
140 mktables
141 @@ -188,6 +206,7 @@ oui.c*
142 page-types
143 parse.c
144 parse.h
145 +parse-events*
146 patches*
147 pca200e.bin
148 pca200e_ecd.bin2
149 @@ -197,6 +216,7 @@ perf-archive
150 piggyback
151 piggy.gzip
152 piggy.S
153 +pmu-*
154 pnmtologo
155 ppc_defs.h*
156 pss_boot.h
157 @@ -207,6 +227,7 @@ r300_reg_safe.h
158 r420_reg_safe.h
159 r600_reg_safe.h
160 recordmcount
161 +regdb.c
162 relocs
163 rlim_names.h
164 rn50_reg_safe.h
165 @@ -216,7 +237,9 @@ series
166 setup
167 setup.bin
168 setup.elf
169 +size_overflow_hash.h
170 sImage
171 +slabinfo
172 sm_tbl*
173 split-include
174 syscalltab.h
175 @@ -227,6 +250,7 @@ tftpboot.img
176 timeconst.h
177 times.h*
178 trix_boot.h
179 +user_constants.h
180 utsrelease.h*
181 vdso-syms.lds
182 vdso.lds
183 @@ -238,13 +262,17 @@ vdso32.lds
184 vdso32.so.dbg
185 vdso64.lds
186 vdso64.so.dbg
187 +vdsox32.lds
188 +vdsox32-syms.lds
189 version.h*
190 vmImage
191 vmlinux
192 vmlinux-*
193 vmlinux.aout
194 vmlinux.bin.all
195 +vmlinux.bin.bz2
196 vmlinux.lds
197 +vmlinux.relocs
198 vmlinuz
199 voffset.h
200 vsyscall.lds
201 @@ -252,9 +280,11 @@ vsyscall_32.lds
202 wanxlfw.inc
203 uImage
204 unifdef
205 +utsrelease.h
206 wakeup.bin
207 wakeup.elf
208 wakeup.lds
209 zImage*
210 zconf.hash.c
211 +zconf.lex.c
212 zoffset.h
213 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
214 index c1601e5..08557ce 100644
215 --- a/Documentation/kernel-parameters.txt
216 +++ b/Documentation/kernel-parameters.txt
217 @@ -2021,6 +2021,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
218 the specified number of seconds. This is to be used if
219 your oopses keep scrolling off the screen.
220
221 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
222 + virtualization environments that don't cope well with the
223 + expand down segment used by UDEREF on X86-32 or the frequent
224 + page table updates on X86-64.
225 +
226 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
227 +
228 pcbit= [HW,ISDN]
229
230 pcd. [PARIDE]
231 diff --git a/Makefile b/Makefile
232 index a2e69a0..cc487da 100644
233 --- a/Makefile
234 +++ b/Makefile
235 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
236
237 HOSTCC = gcc
238 HOSTCXX = g++
239 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
240 -HOSTCXXFLAGS = -O2
241 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
242 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
243 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
244
245 # Decide whether to build built-in, modular, or both.
246 # Normally, just do built-in.
247 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
248 # Rules shared between *config targets and build targets
249
250 # Basic helpers built in scripts/
251 -PHONY += scripts_basic
252 -scripts_basic:
253 +PHONY += scripts_basic gcc-plugins
254 +scripts_basic: gcc-plugins
255 $(Q)$(MAKE) $(build)=scripts/basic
256 $(Q)rm -f .tmp_quiet_recordmcount
257
258 @@ -564,6 +565,56 @@ else
259 KBUILD_CFLAGS += -O2
260 endif
261
262 +ifndef DISABLE_PAX_PLUGINS
263 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
264 +ifneq ($(PLUGINCC),)
265 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
266 +ifndef CONFIG_UML
267 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
268 +endif
269 +endif
270 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
271 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
272 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
273 +endif
274 +ifdef CONFIG_KALLOCSTAT_PLUGIN
275 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
276 +endif
277 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
278 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
279 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
280 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
281 +endif
282 +ifdef CONFIG_CHECKER_PLUGIN
283 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
284 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
285 +endif
286 +endif
287 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
288 +ifdef CONFIG_PAX_SIZE_OVERFLOW
289 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
290 +endif
291 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
292 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
293 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
294 +export PLUGINCC CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
295 +ifeq ($(KBUILD_EXTMOD),)
296 +gcc-plugins:
297 + $(Q)$(MAKE) $(build)=tools/gcc
298 +else
299 +gcc-plugins: ;
300 +endif
301 +else
302 +gcc-plugins:
303 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
304 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
305 +else
306 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
307 +endif
308 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
309 +endif
310 +endif
311 +
312 include $(srctree)/arch/$(SRCARCH)/Makefile
313
314 ifneq ($(CONFIG_FRAME_WARN),0)
315 @@ -708,7 +759,7 @@ export mod_strip_cmd
316
317
318 ifeq ($(KBUILD_EXTMOD),)
319 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
320 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
321
322 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
323 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
324 @@ -932,6 +983,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
325
326 # The actual objects are generated when descending,
327 # make sure no implicit rule kicks in
328 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
329 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
330 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
331
332 # Handle descending into subdirectories listed in $(vmlinux-dirs)
333 @@ -941,7 +994,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
334 # Error messages still appears in the original language
335
336 PHONY += $(vmlinux-dirs)
337 -$(vmlinux-dirs): prepare scripts
338 +$(vmlinux-dirs): gcc-plugins prepare scripts
339 $(Q)$(MAKE) $(build)=$@
340
341 # Store (new) KERNELRELASE string in include/config/kernel.release
342 @@ -985,6 +1038,7 @@ prepare0: archprepare FORCE
343 $(Q)$(MAKE) $(build)=.
344
345 # All the preparing..
346 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
347 prepare: prepare0
348
349 # Generate some files
350 @@ -1092,6 +1146,8 @@ all: modules
351 # using awk while concatenating to the final file.
352
353 PHONY += modules
354 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
357 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
358 @$(kecho) ' Building modules, stage 2.';
359 @@ -1107,7 +1163,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
360
361 # Target to prepare building external modules
362 PHONY += modules_prepare
363 -modules_prepare: prepare scripts
364 +modules_prepare: gcc-plugins prepare scripts
365
366 # Target to install modules
367 PHONY += modules_install
368 @@ -1166,7 +1222,7 @@ CLEAN_FILES += vmlinux System.map \
369 MRPROPER_DIRS += include/config usr/include include/generated \
370 arch/*/include/generated
371 MRPROPER_FILES += .config .config.old .version .old_version \
372 - include/linux/version.h \
373 + include/linux/version.h tools/gcc/size_overflow_hash.h\
374 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
375
376 # clean - Delete most, but leave enough to build external modules
377 @@ -1204,6 +1260,7 @@ distclean: mrproper
378 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
379 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
380 -o -name '.*.rej' \
381 + -o -name '.*.rej' -o -name '*.so' \
382 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
383 -type f -print | xargs rm -f
384
385 @@ -1364,6 +1421,8 @@ PHONY += $(module-dirs) modules
386 $(module-dirs): crmodverdir $(objtree)/Module.symvers
387 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
388
389 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 modules: $(module-dirs)
392 @$(kecho) ' Building modules, stage 2.';
393 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
394 @@ -1490,17 +1549,21 @@ else
395 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
396 endif
397
398 -%.s: %.c prepare scripts FORCE
399 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
400 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
401 +%.s: %.c gcc-plugins prepare scripts FORCE
402 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
403 %.i: %.c prepare scripts FORCE
404 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
405 -%.o: %.c prepare scripts FORCE
406 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
407 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
408 +%.o: %.c gcc-plugins prepare scripts FORCE
409 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
410 %.lst: %.c prepare scripts FORCE
411 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
412 -%.s: %.S prepare scripts FORCE
413 +%.s: %.S gcc-plugins prepare scripts FORCE
414 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
415 -%.o: %.S prepare scripts FORCE
416 +%.o: %.S gcc-plugins prepare scripts FORCE
417 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
418 %.symtypes: %.c prepare scripts FORCE
419 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
420 @@ -1510,11 +1573,15 @@ endif
421 $(cmd_crmodverdir)
422 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
423 $(build)=$(build-dir)
424 -%/: prepare scripts FORCE
425 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%/: gcc-plugins prepare scripts FORCE
428 $(cmd_crmodverdir)
429 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
430 $(build)=$(build-dir)
431 -%.ko: prepare scripts FORCE
432 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.ko: gcc-plugins prepare scripts FORCE
435 $(cmd_crmodverdir)
436 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
437 $(build)=$(build-dir) $(@:.ko=.o)
438 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
439 index 3bb7ffe..347a54c 100644
440 --- a/arch/alpha/include/asm/atomic.h
441 +++ b/arch/alpha/include/asm/atomic.h
442 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
443 #define atomic_dec(v) atomic_sub(1,(v))
444 #define atomic64_dec(v) atomic64_sub(1,(v))
445
446 +#define atomic64_read_unchecked(v) atomic64_read(v)
447 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
448 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
449 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
450 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
451 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
452 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
453 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
454 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
455 +
456 #define smp_mb__before_atomic_dec() smp_mb()
457 #define smp_mb__after_atomic_dec() smp_mb()
458 #define smp_mb__before_atomic_inc() smp_mb()
459 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
460 index ad368a9..fbe0f25 100644
461 --- a/arch/alpha/include/asm/cache.h
462 +++ b/arch/alpha/include/asm/cache.h
463 @@ -4,19 +4,19 @@
464 #ifndef __ARCH_ALPHA_CACHE_H
465 #define __ARCH_ALPHA_CACHE_H
466
467 +#include <linux/const.h>
468
469 /* Bytes per L1 (data) cache line. */
470 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
471 -# define L1_CACHE_BYTES 64
472 # define L1_CACHE_SHIFT 6
473 #else
474 /* Both EV4 and EV5 are write-through, read-allocate,
475 direct-mapped, physical.
476 */
477 -# define L1_CACHE_BYTES 32
478 # define L1_CACHE_SHIFT 5
479 #endif
480
481 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
482 #define SMP_CACHE_BYTES L1_CACHE_BYTES
483
484 #endif
485 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
486 index 968d999..d36b2df 100644
487 --- a/arch/alpha/include/asm/elf.h
488 +++ b/arch/alpha/include/asm/elf.h
489 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
490
491 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
492
493 +#ifdef CONFIG_PAX_ASLR
494 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
495 +
496 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
497 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
498 +#endif
499 +
500 /* $0 is set by ld.so to a pointer to a function which might be
501 registered using atexit. This provides a mean for the dynamic
502 linker to call DT_FINI functions for shared libraries that have
503 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
504 index bc2a0da..8ad11ee 100644
505 --- a/arch/alpha/include/asm/pgalloc.h
506 +++ b/arch/alpha/include/asm/pgalloc.h
507 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
508 pgd_set(pgd, pmd);
509 }
510
511 +static inline void
512 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
513 +{
514 + pgd_populate(mm, pgd, pmd);
515 +}
516 +
517 extern pgd_t *pgd_alloc(struct mm_struct *mm);
518
519 static inline void
520 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
521 index 81a4342..348b927 100644
522 --- a/arch/alpha/include/asm/pgtable.h
523 +++ b/arch/alpha/include/asm/pgtable.h
524 @@ -102,6 +102,17 @@ struct vm_area_struct;
525 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
526 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
527 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
528 +
529 +#ifdef CONFIG_PAX_PAGEEXEC
530 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
531 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
532 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
533 +#else
534 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
535 +# define PAGE_COPY_NOEXEC PAGE_COPY
536 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
537 +#endif
538 +
539 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
540
541 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
542 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
543 index 2fd00b7..cfd5069 100644
544 --- a/arch/alpha/kernel/module.c
545 +++ b/arch/alpha/kernel/module.c
546 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
547
548 /* The small sections were sorted to the end of the segment.
549 The following should definitely cover them. */
550 - gp = (u64)me->module_core + me->core_size - 0x8000;
551 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
552 got = sechdrs[me->arch.gotsecindex].sh_addr;
553
554 for (i = 0; i < n; i++) {
555 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
556 index 49ee319..9ee7d14 100644
557 --- a/arch/alpha/kernel/osf_sys.c
558 +++ b/arch/alpha/kernel/osf_sys.c
559 @@ -1146,7 +1146,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
560 /* At this point: (!vma || addr < vma->vm_end). */
561 if (limit - len < addr)
562 return -ENOMEM;
563 - if (!vma || addr + len <= vma->vm_start)
564 + if (check_heap_stack_gap(vma, addr, len))
565 return addr;
566 addr = vma->vm_end;
567 vma = vma->vm_next;
568 @@ -1182,6 +1182,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
569 merely specific addresses, but regions of memory -- perhaps
570 this feature should be incorporated into all ports? */
571
572 +#ifdef CONFIG_PAX_RANDMMAP
573 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
574 +#endif
575 +
576 if (addr) {
577 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
578 if (addr != (unsigned long) -ENOMEM)
579 @@ -1189,8 +1193,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
580 }
581
582 /* Next, try allocating at TASK_UNMAPPED_BASE. */
583 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
584 - len, limit);
585 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
586 +
587 if (addr != (unsigned long) -ENOMEM)
588 return addr;
589
590 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
591 index 5eecab1..609abc0 100644
592 --- a/arch/alpha/mm/fault.c
593 +++ b/arch/alpha/mm/fault.c
594 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
595 __reload_thread(pcb);
596 }
597
598 +#ifdef CONFIG_PAX_PAGEEXEC
599 +/*
600 + * PaX: decide what to do with offenders (regs->pc = fault address)
601 + *
602 + * returns 1 when task should be killed
603 + * 2 when patched PLT trampoline was detected
604 + * 3 when unpatched PLT trampoline was detected
605 + */
606 +static int pax_handle_fetch_fault(struct pt_regs *regs)
607 +{
608 +
609 +#ifdef CONFIG_PAX_EMUPLT
610 + int err;
611 +
612 + do { /* PaX: patched PLT emulation #1 */
613 + unsigned int ldah, ldq, jmp;
614 +
615 + err = get_user(ldah, (unsigned int *)regs->pc);
616 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
617 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
618 +
619 + if (err)
620 + break;
621 +
622 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
623 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
624 + jmp == 0x6BFB0000U)
625 + {
626 + unsigned long r27, addr;
627 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
628 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
629 +
630 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
631 + err = get_user(r27, (unsigned long *)addr);
632 + if (err)
633 + break;
634 +
635 + regs->r27 = r27;
636 + regs->pc = r27;
637 + return 2;
638 + }
639 + } while (0);
640 +
641 + do { /* PaX: patched PLT emulation #2 */
642 + unsigned int ldah, lda, br;
643 +
644 + err = get_user(ldah, (unsigned int *)regs->pc);
645 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
646 + err |= get_user(br, (unsigned int *)(regs->pc+8));
647 +
648 + if (err)
649 + break;
650 +
651 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
652 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
653 + (br & 0xFFE00000U) == 0xC3E00000U)
654 + {
655 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
656 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
657 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
658 +
659 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
660 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
661 + return 2;
662 + }
663 + } while (0);
664 +
665 + do { /* PaX: unpatched PLT emulation */
666 + unsigned int br;
667 +
668 + err = get_user(br, (unsigned int *)regs->pc);
669 +
670 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
671 + unsigned int br2, ldq, nop, jmp;
672 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
673 +
674 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
675 + err = get_user(br2, (unsigned int *)addr);
676 + err |= get_user(ldq, (unsigned int *)(addr+4));
677 + err |= get_user(nop, (unsigned int *)(addr+8));
678 + err |= get_user(jmp, (unsigned int *)(addr+12));
679 + err |= get_user(resolver, (unsigned long *)(addr+16));
680 +
681 + if (err)
682 + break;
683 +
684 + if (br2 == 0xC3600000U &&
685 + ldq == 0xA77B000CU &&
686 + nop == 0x47FF041FU &&
687 + jmp == 0x6B7B0000U)
688 + {
689 + regs->r28 = regs->pc+4;
690 + regs->r27 = addr+16;
691 + regs->pc = resolver;
692 + return 3;
693 + }
694 + }
695 + } while (0);
696 +#endif
697 +
698 + return 1;
699 +}
700 +
701 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
702 +{
703 + unsigned long i;
704 +
705 + printk(KERN_ERR "PAX: bytes at PC: ");
706 + for (i = 0; i < 5; i++) {
707 + unsigned int c;
708 + if (get_user(c, (unsigned int *)pc+i))
709 + printk(KERN_CONT "???????? ");
710 + else
711 + printk(KERN_CONT "%08x ", c);
712 + }
713 + printk("\n");
714 +}
715 +#endif
716
717 /*
718 * This routine handles page faults. It determines the address,
719 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
720 good_area:
721 si_code = SEGV_ACCERR;
722 if (cause < 0) {
723 - if (!(vma->vm_flags & VM_EXEC))
724 + if (!(vma->vm_flags & VM_EXEC)) {
725 +
726 +#ifdef CONFIG_PAX_PAGEEXEC
727 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
728 + goto bad_area;
729 +
730 + up_read(&mm->mmap_sem);
731 + switch (pax_handle_fetch_fault(regs)) {
732 +
733 +#ifdef CONFIG_PAX_EMUPLT
734 + case 2:
735 + case 3:
736 + return;
737 +#endif
738 +
739 + }
740 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
741 + do_group_exit(SIGKILL);
742 +#else
743 goto bad_area;
744 +#endif
745 +
746 + }
747 } else if (!cause) {
748 /* Allow reads even for write-only mappings */
749 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
750 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
751 index 68374ba..cff7196 100644
752 --- a/arch/arm/include/asm/atomic.h
753 +++ b/arch/arm/include/asm/atomic.h
754 @@ -17,17 +17,35 @@
755 #include <asm/barrier.h>
756 #include <asm/cmpxchg.h>
757
758 +#ifdef CONFIG_GENERIC_ATOMIC64
759 +#include <asm-generic/atomic64.h>
760 +#endif
761 +
762 #define ATOMIC_INIT(i) { (i) }
763
764 #ifdef __KERNEL__
765
766 +#define _ASM_EXTABLE(from, to) \
767 +" .pushsection __ex_table,\"a\"\n"\
768 +" .align 3\n" \
769 +" .long " #from ", " #to"\n" \
770 +" .popsection"
771 +
772 /*
773 * On ARM, ordinary assignment (str instruction) doesn't clear the local
774 * strex/ldrex monitor on some implementations. The reason we can use it for
775 * atomic_set() is the clrex or dummy strex done on every exception return.
776 */
777 #define atomic_read(v) (*(volatile int *)&(v)->counter)
778 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
779 +{
780 + return v->counter;
781 +}
782 #define atomic_set(v,i) (((v)->counter) = (i))
783 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
784 +{
785 + v->counter = i;
786 +}
787
788 #if __LINUX_ARM_ARCH__ >= 6
789
790 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_add\n"
794 +"1: ldrex %1, [%3]\n"
795 +" adds %0, %1, %4\n"
796 +
797 +#ifdef CONFIG_PAX_REFCOUNT
798 +" bvc 3f\n"
799 +"2: bkpt 0xf103\n"
800 +"3:\n"
801 +#endif
802 +
803 +" strex %1, %0, [%3]\n"
804 +" teq %1, #0\n"
805 +" bne 1b"
806 +
807 +#ifdef CONFIG_PAX_REFCOUNT
808 +"\n4:\n"
809 + _ASM_EXTABLE(2b, 4b)
810 +#endif
811 +
812 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813 + : "r" (&v->counter), "Ir" (i)
814 + : "cc");
815 +}
816 +
817 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
818 +{
819 + unsigned long tmp;
820 + int result;
821 +
822 + __asm__ __volatile__("@ atomic_add_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " add %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_add_return\n"
830 +"1: ldrex %1, [%3]\n"
831 +" adds %0, %1, %4\n"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +" bvc 3f\n"
835 +" mov %0, %1\n"
836 +"2: bkpt 0xf103\n"
837 +"3:\n"
838 +#endif
839 +
840 +" strex %1, %0, [%3]\n"
841 +" teq %1, #0\n"
842 +" bne 1b"
843 +
844 +#ifdef CONFIG_PAX_REFCOUNT
845 +"\n4:\n"
846 + _ASM_EXTABLE(2b, 4b)
847 +#endif
848 +
849 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
850 + : "r" (&v->counter), "Ir" (i)
851 + : "cc");
852 +
853 + smp_mb();
854 +
855 + return result;
856 +}
857 +
858 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
859 +{
860 + unsigned long tmp;
861 + int result;
862 +
863 + smp_mb();
864 +
865 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
866 "1: ldrex %0, [%3]\n"
867 " add %0, %0, %4\n"
868 " strex %1, %0, [%3]\n"
869 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
870 int result;
871
872 __asm__ __volatile__("@ atomic_sub\n"
873 +"1: ldrex %1, [%3]\n"
874 +" subs %0, %1, %4\n"
875 +
876 +#ifdef CONFIG_PAX_REFCOUNT
877 +" bvc 3f\n"
878 +"2: bkpt 0xf103\n"
879 +"3:\n"
880 +#endif
881 +
882 +" strex %1, %0, [%3]\n"
883 +" teq %1, #0\n"
884 +" bne 1b"
885 +
886 +#ifdef CONFIG_PAX_REFCOUNT
887 +"\n4:\n"
888 + _ASM_EXTABLE(2b, 4b)
889 +#endif
890 +
891 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
892 + : "r" (&v->counter), "Ir" (i)
893 + : "cc");
894 +}
895 +
896 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
897 +{
898 + unsigned long tmp;
899 + int result;
900 +
901 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
902 "1: ldrex %0, [%3]\n"
903 " sub %0, %0, %4\n"
904 " strex %1, %0, [%3]\n"
905 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
906 smp_mb();
907
908 __asm__ __volatile__("@ atomic_sub_return\n"
909 -"1: ldrex %0, [%3]\n"
910 -" sub %0, %0, %4\n"
911 +"1: ldrex %1, [%3]\n"
912 +" sub %0, %1, %4\n"
913 +
914 +#ifdef CONFIG_PAX_REFCOUNT
915 +" bvc 3f\n"
916 +" mov %0, %1\n"
917 +"2: bkpt 0xf103\n"
918 +"3:\n"
919 +#endif
920 +
921 " strex %1, %0, [%3]\n"
922 " teq %1, #0\n"
923 " bne 1b"
924 +
925 +#ifdef CONFIG_PAX_REFCOUNT
926 +"\n4:\n"
927 + _ASM_EXTABLE(2b, 4b)
928 +#endif
929 +
930 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
931 : "r" (&v->counter), "Ir" (i)
932 : "cc");
933 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
934 return oldval;
935 }
936
937 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
938 +{
939 + unsigned long oldval, res;
940 +
941 + smp_mb();
942 +
943 + do {
944 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
945 + "ldrex %1, [%3]\n"
946 + "mov %0, #0\n"
947 + "teq %1, %4\n"
948 + "strexeq %0, %5, [%3]\n"
949 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
950 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
951 + : "cc");
952 + } while (res);
953 +
954 + smp_mb();
955 +
956 + return oldval;
957 +}
958 +
959 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
960 {
961 unsigned long tmp, tmp2;
962 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
963
964 return val;
965 }
966 +
967 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
968 +{
969 + return atomic_add_return(i, v);
970 +}
971 +
972 #define atomic_add(i, v) (void) atomic_add_return(i, v)
973 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
974 +{
975 + (void) atomic_add_return(i, v);
976 +}
977
978 static inline int atomic_sub_return(int i, atomic_t *v)
979 {
980 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
981 return val;
982 }
983 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
984 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
985 +{
986 + (void) atomic_sub_return(i, v);
987 +}
988
989 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
990 {
991 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
992 return ret;
993 }
994
995 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
996 +{
997 + return atomic_cmpxchg(v, old, new);
998 +}
999 +
1000 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1001 {
1002 unsigned long flags;
1003 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1004 #endif /* __LINUX_ARM_ARCH__ */
1005
1006 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1007 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1008 +{
1009 + return xchg(&v->counter, new);
1010 +}
1011
1012 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1013 {
1014 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1015 }
1016
1017 #define atomic_inc(v) atomic_add(1, v)
1018 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1019 +{
1020 + atomic_add_unchecked(1, v);
1021 +}
1022 #define atomic_dec(v) atomic_sub(1, v)
1023 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1024 +{
1025 + atomic_sub_unchecked(1, v);
1026 +}
1027
1028 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1029 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1030 +{
1031 + return atomic_add_return_unchecked(1, v) == 0;
1032 +}
1033 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1034 #define atomic_inc_return(v) (atomic_add_return(1, v))
1035 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1036 +{
1037 + return atomic_add_return_unchecked(1, v);
1038 +}
1039 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1040 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1041
1042 @@ -241,6 +428,14 @@ typedef struct {
1043 u64 __aligned(8) counter;
1044 } atomic64_t;
1045
1046 +#ifdef CONFIG_PAX_REFCOUNT
1047 +typedef struct {
1048 + u64 __aligned(8) counter;
1049 +} atomic64_unchecked_t;
1050 +#else
1051 +typedef atomic64_t atomic64_unchecked_t;
1052 +#endif
1053 +
1054 #define ATOMIC64_INIT(i) { (i) }
1055
1056 static inline u64 atomic64_read(atomic64_t *v)
1057 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1058 return result;
1059 }
1060
1061 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1062 +{
1063 + u64 result;
1064 +
1065 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1066 +" ldrexd %0, %H0, [%1]"
1067 + : "=&r" (result)
1068 + : "r" (&v->counter), "Qo" (v->counter)
1069 + );
1070 +
1071 + return result;
1072 +}
1073 +
1074 static inline void atomic64_set(atomic64_t *v, u64 i)
1075 {
1076 u64 tmp;
1077 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1078 : "cc");
1079 }
1080
1081 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1082 +{
1083 + u64 tmp;
1084 +
1085 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1086 +"1: ldrexd %0, %H0, [%2]\n"
1087 +" strexd %0, %3, %H3, [%2]\n"
1088 +" teq %0, #0\n"
1089 +" bne 1b"
1090 + : "=&r" (tmp), "=Qo" (v->counter)
1091 + : "r" (&v->counter), "r" (i)
1092 + : "cc");
1093 +}
1094 +
1095 static inline void atomic64_add(u64 i, atomic64_t *v)
1096 {
1097 u64 result;
1098 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1099 __asm__ __volatile__("@ atomic64_add\n"
1100 "1: ldrexd %0, %H0, [%3]\n"
1101 " adds %0, %0, %4\n"
1102 +" adcs %H0, %H0, %H4\n"
1103 +
1104 +#ifdef CONFIG_PAX_REFCOUNT
1105 +" bvc 3f\n"
1106 +"2: bkpt 0xf103\n"
1107 +"3:\n"
1108 +#endif
1109 +
1110 +" strexd %1, %0, %H0, [%3]\n"
1111 +" teq %1, #0\n"
1112 +" bne 1b"
1113 +
1114 +#ifdef CONFIG_PAX_REFCOUNT
1115 +"\n4:\n"
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1120 + : "r" (&v->counter), "r" (i)
1121 + : "cc");
1122 +}
1123 +
1124 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1125 +{
1126 + u64 result;
1127 + unsigned long tmp;
1128 +
1129 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1130 +"1: ldrexd %0, %H0, [%3]\n"
1131 +" adds %0, %0, %4\n"
1132 " adc %H0, %H0, %H4\n"
1133 " strexd %1, %0, %H0, [%3]\n"
1134 " teq %1, #0\n"
1135 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1136
1137 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1138 {
1139 - u64 result;
1140 - unsigned long tmp;
1141 + u64 result, tmp;
1142
1143 smp_mb();
1144
1145 __asm__ __volatile__("@ atomic64_add_return\n"
1146 +"1: ldrexd %1, %H1, [%3]\n"
1147 +" adds %0, %1, %4\n"
1148 +" adcs %H0, %H1, %H4\n"
1149 +
1150 +#ifdef CONFIG_PAX_REFCOUNT
1151 +" bvc 3f\n"
1152 +" mov %0, %1\n"
1153 +" mov %H0, %H1\n"
1154 +"2: bkpt 0xf103\n"
1155 +"3:\n"
1156 +#endif
1157 +
1158 +" strexd %1, %0, %H0, [%3]\n"
1159 +" teq %1, #0\n"
1160 +" bne 1b"
1161 +
1162 +#ifdef CONFIG_PAX_REFCOUNT
1163 +"\n4:\n"
1164 + _ASM_EXTABLE(2b, 4b)
1165 +#endif
1166 +
1167 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1168 + : "r" (&v->counter), "r" (i)
1169 + : "cc");
1170 +
1171 + smp_mb();
1172 +
1173 + return result;
1174 +}
1175 +
1176 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1177 +{
1178 + u64 result;
1179 + unsigned long tmp;
1180 +
1181 + smp_mb();
1182 +
1183 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1184 "1: ldrexd %0, %H0, [%3]\n"
1185 " adds %0, %0, %4\n"
1186 " adc %H0, %H0, %H4\n"
1187 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1188 __asm__ __volatile__("@ atomic64_sub\n"
1189 "1: ldrexd %0, %H0, [%3]\n"
1190 " subs %0, %0, %4\n"
1191 +" sbcs %H0, %H0, %H4\n"
1192 +
1193 +#ifdef CONFIG_PAX_REFCOUNT
1194 +" bvc 3f\n"
1195 +"2: bkpt 0xf103\n"
1196 +"3:\n"
1197 +#endif
1198 +
1199 +" strexd %1, %0, %H0, [%3]\n"
1200 +" teq %1, #0\n"
1201 +" bne 1b"
1202 +
1203 +#ifdef CONFIG_PAX_REFCOUNT
1204 +"\n4:\n"
1205 + _ASM_EXTABLE(2b, 4b)
1206 +#endif
1207 +
1208 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1209 + : "r" (&v->counter), "r" (i)
1210 + : "cc");
1211 +}
1212 +
1213 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1214 +{
1215 + u64 result;
1216 + unsigned long tmp;
1217 +
1218 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1219 +"1: ldrexd %0, %H0, [%3]\n"
1220 +" subs %0, %0, %4\n"
1221 " sbc %H0, %H0, %H4\n"
1222 " strexd %1, %0, %H0, [%3]\n"
1223 " teq %1, #0\n"
1224 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1225
1226 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1227 {
1228 - u64 result;
1229 - unsigned long tmp;
1230 + u64 result, tmp;
1231
1232 smp_mb();
1233
1234 __asm__ __volatile__("@ atomic64_sub_return\n"
1235 -"1: ldrexd %0, %H0, [%3]\n"
1236 -" subs %0, %0, %4\n"
1237 -" sbc %H0, %H0, %H4\n"
1238 +"1: ldrexd %1, %H1, [%3]\n"
1239 +" subs %0, %1, %4\n"
1240 +" sbc %H0, %H1, %H4\n"
1241 +
1242 +#ifdef CONFIG_PAX_REFCOUNT
1243 +" bvc 3f\n"
1244 +" mov %0, %1\n"
1245 +" mov %H0, %H1\n"
1246 +"2: bkpt 0xf103\n"
1247 +"3:\n"
1248 +#endif
1249 +
1250 " strexd %1, %0, %H0, [%3]\n"
1251 " teq %1, #0\n"
1252 " bne 1b"
1253 +
1254 +#ifdef CONFIG_PAX_REFCOUNT
1255 +"\n4:\n"
1256 + _ASM_EXTABLE(2b, 4b)
1257 +#endif
1258 +
1259 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1260 : "r" (&v->counter), "r" (i)
1261 : "cc");
1262 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1263 return oldval;
1264 }
1265
1266 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1267 +{
1268 + u64 oldval;
1269 + unsigned long res;
1270 +
1271 + smp_mb();
1272 +
1273 + do {
1274 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1275 + "ldrexd %1, %H1, [%3]\n"
1276 + "mov %0, #0\n"
1277 + "teq %1, %4\n"
1278 + "teqeq %H1, %H4\n"
1279 + "strexdeq %0, %5, %H5, [%3]"
1280 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1281 + : "r" (&ptr->counter), "r" (old), "r" (new)
1282 + : "cc");
1283 + } while (res);
1284 +
1285 + smp_mb();
1286 +
1287 + return oldval;
1288 +}
1289 +
1290 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1291 {
1292 u64 result;
1293 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1294
1295 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1296 {
1297 - u64 result;
1298 - unsigned long tmp;
1299 + u64 result, tmp;
1300
1301 smp_mb();
1302
1303 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1304 -"1: ldrexd %0, %H0, [%3]\n"
1305 -" subs %0, %0, #1\n"
1306 -" sbc %H0, %H0, #0\n"
1307 +"1: ldrexd %1, %H1, [%3]\n"
1308 +" subs %0, %1, #1\n"
1309 +" sbc %H0, %H1, #0\n"
1310 +
1311 +#ifdef CONFIG_PAX_REFCOUNT
1312 +" bvc 3f\n"
1313 +" mov %0, %1\n"
1314 +" mov %H0, %H1\n"
1315 +"2: bkpt 0xf103\n"
1316 +"3:\n"
1317 +#endif
1318 +
1319 " teq %H0, #0\n"
1320 -" bmi 2f\n"
1321 +" bmi 4f\n"
1322 " strexd %1, %0, %H0, [%3]\n"
1323 " teq %1, #0\n"
1324 " bne 1b\n"
1325 -"2:"
1326 +"4:\n"
1327 +
1328 +#ifdef CONFIG_PAX_REFCOUNT
1329 + _ASM_EXTABLE(2b, 4b)
1330 +#endif
1331 +
1332 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1333 : "r" (&v->counter)
1334 : "cc");
1335 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1336 " teq %0, %5\n"
1337 " teqeq %H0, %H5\n"
1338 " moveq %1, #0\n"
1339 -" beq 2f\n"
1340 +" beq 4f\n"
1341 " adds %0, %0, %6\n"
1342 " adc %H0, %H0, %H6\n"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +" bvc 3f\n"
1346 +"2: bkpt 0xf103\n"
1347 +"3:\n"
1348 +#endif
1349 +
1350 " strexd %2, %0, %H0, [%4]\n"
1351 " teq %2, #0\n"
1352 " bne 1b\n"
1353 -"2:"
1354 +"4:\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 + _ASM_EXTABLE(2b, 4b)
1358 +#endif
1359 +
1360 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1361 : "r" (&v->counter), "r" (u), "r" (a)
1362 : "cc");
1363 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1364
1365 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1366 #define atomic64_inc(v) atomic64_add(1LL, (v))
1367 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1368 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1369 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1370 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1371 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1372 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1373 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1374 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1375 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1376 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1377 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1378 index 75fe66b..2255c86 100644
1379 --- a/arch/arm/include/asm/cache.h
1380 +++ b/arch/arm/include/asm/cache.h
1381 @@ -4,8 +4,10 @@
1382 #ifndef __ASMARM_CACHE_H
1383 #define __ASMARM_CACHE_H
1384
1385 +#include <linux/const.h>
1386 +
1387 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1388 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1389 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1390
1391 /*
1392 * Memory returned by kmalloc() may be used for DMA, so we must make
1393 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1394 index 1252a26..9dc17b5 100644
1395 --- a/arch/arm/include/asm/cacheflush.h
1396 +++ b/arch/arm/include/asm/cacheflush.h
1397 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1398 void (*dma_unmap_area)(const void *, size_t, int);
1399
1400 void (*dma_flush_range)(const void *, const void *);
1401 -};
1402 +} __no_const;
1403
1404 /*
1405 * Select the calling method
1406 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1407 index d41d7cb..9bea5e0 100644
1408 --- a/arch/arm/include/asm/cmpxchg.h
1409 +++ b/arch/arm/include/asm/cmpxchg.h
1410 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1411
1412 #define xchg(ptr,x) \
1413 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1414 +#define xchg_unchecked(ptr,x) \
1415 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1416
1417 #include <asm-generic/cmpxchg-local.h>
1418
1419 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1420 index 38050b1..9d90e8b 100644
1421 --- a/arch/arm/include/asm/elf.h
1422 +++ b/arch/arm/include/asm/elf.h
1423 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1424 the loader. We need to make sure that it is out of the way of the program
1425 that it will "exec", and that there is sufficient room for the brk. */
1426
1427 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1428 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1429 +
1430 +#ifdef CONFIG_PAX_ASLR
1431 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1432 +
1433 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1434 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1435 +#endif
1436
1437 /* When the program starts, a1 contains a pointer to a function to be
1438 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1439 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1440 extern void elf_set_personality(const struct elf32_hdr *);
1441 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1442
1443 -struct mm_struct;
1444 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1445 -#define arch_randomize_brk arch_randomize_brk
1446 -
1447 #endif
1448 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1449 index e51b1e8..32a3113 100644
1450 --- a/arch/arm/include/asm/kmap_types.h
1451 +++ b/arch/arm/include/asm/kmap_types.h
1452 @@ -21,6 +21,7 @@ enum km_type {
1453 KM_L1_CACHE,
1454 KM_L2_CACHE,
1455 KM_KDB,
1456 + KM_CLEARPAGE,
1457 KM_TYPE_NR
1458 };
1459
1460 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1461 index 53426c6..c7baff3 100644
1462 --- a/arch/arm/include/asm/outercache.h
1463 +++ b/arch/arm/include/asm/outercache.h
1464 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1465 #endif
1466 void (*set_debug)(unsigned long);
1467 void (*resume)(void);
1468 -};
1469 +} __no_const;
1470
1471 #ifdef CONFIG_OUTER_CACHE
1472
1473 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1474 index 5838361..da6e813 100644
1475 --- a/arch/arm/include/asm/page.h
1476 +++ b/arch/arm/include/asm/page.h
1477 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1478 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1479 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1480 unsigned long vaddr, struct vm_area_struct *vma);
1481 -};
1482 +} __no_const;
1483
1484 #ifdef MULTI_USER
1485 extern struct cpu_user_fns cpu_user;
1486 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1487 index 943504f..bf8d667 100644
1488 --- a/arch/arm/include/asm/pgalloc.h
1489 +++ b/arch/arm/include/asm/pgalloc.h
1490 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1491 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1492 }
1493
1494 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1495 +{
1496 + pud_populate(mm, pud, pmd);
1497 +}
1498 +
1499 #else /* !CONFIG_ARM_LPAE */
1500
1501 /*
1502 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1503 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1504 #define pmd_free(mm, pmd) do { } while (0)
1505 #define pud_populate(mm,pmd,pte) BUG()
1506 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1507
1508 #endif /* CONFIG_ARM_LPAE */
1509
1510 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1511 index 0f04d84..2be5648 100644
1512 --- a/arch/arm/include/asm/thread_info.h
1513 +++ b/arch/arm/include/asm/thread_info.h
1514 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1515 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1516 #define TIF_SYSCALL_TRACE 8
1517 #define TIF_SYSCALL_AUDIT 9
1518 +
1519 +/* within 8 bits of TIF_SYSCALL_TRACE
1520 + to meet flexible second operand requirements
1521 +*/
1522 +#define TIF_GRSEC_SETXID 10
1523 +
1524 #define TIF_POLLING_NRFLAG 16
1525 #define TIF_USING_IWMMXT 17
1526 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1527 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1528 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1529 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1530 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1531 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1532
1533 /* Checks for any syscall work in entry-common.S */
1534 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1535 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1536 + _TIF_GRSEC_SETXID)
1537
1538 /*
1539 * Change these and you break ASM code in entry-common.S
1540 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1541 index 71f6536..602f279 100644
1542 --- a/arch/arm/include/asm/uaccess.h
1543 +++ b/arch/arm/include/asm/uaccess.h
1544 @@ -22,6 +22,8 @@
1545 #define VERIFY_READ 0
1546 #define VERIFY_WRITE 1
1547
1548 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1549 +
1550 /*
1551 * The exception table consists of pairs of addresses: the first is the
1552 * address of an instruction that is allowed to fault, and the second is
1553 @@ -387,8 +389,23 @@ do { \
1554
1555
1556 #ifdef CONFIG_MMU
1557 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1558 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1559 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1560 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1561 +
1562 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1563 +{
1564 + if (!__builtin_constant_p(n))
1565 + check_object_size(to, n, false);
1566 + return ___copy_from_user(to, from, n);
1567 +}
1568 +
1569 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1570 +{
1571 + if (!__builtin_constant_p(n))
1572 + check_object_size(from, n, true);
1573 + return ___copy_to_user(to, from, n);
1574 +}
1575 +
1576 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1577 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1578 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1579 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1580
1581 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1582 {
1583 + if ((long)n < 0)
1584 + return n;
1585 +
1586 if (access_ok(VERIFY_READ, from, n))
1587 n = __copy_from_user(to, from, n);
1588 else /* security hole - plug it */
1589 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1590
1591 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1592 {
1593 + if ((long)n < 0)
1594 + return n;
1595 +
1596 if (access_ok(VERIFY_WRITE, to, n))
1597 n = __copy_to_user(to, from, n);
1598 return n;
1599 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1600 index b57c75e..ed2d6b2 100644
1601 --- a/arch/arm/kernel/armksyms.c
1602 +++ b/arch/arm/kernel/armksyms.c
1603 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1604 #ifdef CONFIG_MMU
1605 EXPORT_SYMBOL(copy_page);
1606
1607 -EXPORT_SYMBOL(__copy_from_user);
1608 -EXPORT_SYMBOL(__copy_to_user);
1609 +EXPORT_SYMBOL(___copy_from_user);
1610 +EXPORT_SYMBOL(___copy_to_user);
1611 EXPORT_SYMBOL(__clear_user);
1612
1613 EXPORT_SYMBOL(__get_user_1);
1614 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1615 index 2b7b017..c380fa2 100644
1616 --- a/arch/arm/kernel/process.c
1617 +++ b/arch/arm/kernel/process.c
1618 @@ -28,7 +28,6 @@
1619 #include <linux/tick.h>
1620 #include <linux/utsname.h>
1621 #include <linux/uaccess.h>
1622 -#include <linux/random.h>
1623 #include <linux/hw_breakpoint.h>
1624 #include <linux/cpuidle.h>
1625
1626 @@ -275,9 +274,10 @@ void machine_power_off(void)
1627 machine_shutdown();
1628 if (pm_power_off)
1629 pm_power_off();
1630 + BUG();
1631 }
1632
1633 -void machine_restart(char *cmd)
1634 +__noreturn void machine_restart(char *cmd)
1635 {
1636 machine_shutdown();
1637
1638 @@ -519,12 +519,6 @@ unsigned long get_wchan(struct task_struct *p)
1639 return 0;
1640 }
1641
1642 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1643 -{
1644 - unsigned long range_end = mm->brk + 0x02000000;
1645 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1646 -}
1647 -
1648 #ifdef CONFIG_MMU
1649 /*
1650 * The vectors page is always readable from user space for the
1651 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1652 index 9650c14..ae30cdd 100644
1653 --- a/arch/arm/kernel/ptrace.c
1654 +++ b/arch/arm/kernel/ptrace.c
1655 @@ -906,10 +906,19 @@ long arch_ptrace(struct task_struct *child, long request,
1656 return ret;
1657 }
1658
1659 +#ifdef CONFIG_GRKERNSEC_SETXID
1660 +extern void gr_delayed_cred_worker(void);
1661 +#endif
1662 +
1663 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1664 {
1665 unsigned long ip;
1666
1667 +#ifdef CONFIG_GRKERNSEC_SETXID
1668 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1669 + gr_delayed_cred_worker();
1670 +#endif
1671 +
1672 if (why)
1673 audit_syscall_exit(regs);
1674 else
1675 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1676 index ebfac78..cbea9c0 100644
1677 --- a/arch/arm/kernel/setup.c
1678 +++ b/arch/arm/kernel/setup.c
1679 @@ -111,13 +111,13 @@ struct processor processor __read_mostly;
1680 struct cpu_tlb_fns cpu_tlb __read_mostly;
1681 #endif
1682 #ifdef MULTI_USER
1683 -struct cpu_user_fns cpu_user __read_mostly;
1684 +struct cpu_user_fns cpu_user __read_only;
1685 #endif
1686 #ifdef MULTI_CACHE
1687 -struct cpu_cache_fns cpu_cache __read_mostly;
1688 +struct cpu_cache_fns cpu_cache __read_only;
1689 #endif
1690 #ifdef CONFIG_OUTER_CACHE
1691 -struct outer_cache_fns outer_cache __read_mostly;
1692 +struct outer_cache_fns outer_cache __read_only;
1693 EXPORT_SYMBOL(outer_cache);
1694 #endif
1695
1696 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1697 index 63d402f..db1d714 100644
1698 --- a/arch/arm/kernel/traps.c
1699 +++ b/arch/arm/kernel/traps.c
1700 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1701
1702 static DEFINE_RAW_SPINLOCK(die_lock);
1703
1704 +extern void gr_handle_kernel_exploit(void);
1705 +
1706 /*
1707 * This function is protected against re-entrancy.
1708 */
1709 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1710 panic("Fatal exception in interrupt");
1711 if (panic_on_oops)
1712 panic("Fatal exception");
1713 +
1714 + gr_handle_kernel_exploit();
1715 +
1716 if (ret != NOTIFY_STOP)
1717 do_exit(SIGSEGV);
1718 }
1719 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1720 index 66a477a..bee61d3 100644
1721 --- a/arch/arm/lib/copy_from_user.S
1722 +++ b/arch/arm/lib/copy_from_user.S
1723 @@ -16,7 +16,7 @@
1724 /*
1725 * Prototype:
1726 *
1727 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1728 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1729 *
1730 * Purpose:
1731 *
1732 @@ -84,11 +84,11 @@
1733
1734 .text
1735
1736 -ENTRY(__copy_from_user)
1737 +ENTRY(___copy_from_user)
1738
1739 #include "copy_template.S"
1740
1741 -ENDPROC(__copy_from_user)
1742 +ENDPROC(___copy_from_user)
1743
1744 .pushsection .fixup,"ax"
1745 .align 0
1746 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1747 index 6ee2f67..d1cce76 100644
1748 --- a/arch/arm/lib/copy_page.S
1749 +++ b/arch/arm/lib/copy_page.S
1750 @@ -10,6 +10,7 @@
1751 * ASM optimised string functions
1752 */
1753 #include <linux/linkage.h>
1754 +#include <linux/const.h>
1755 #include <asm/assembler.h>
1756 #include <asm/asm-offsets.h>
1757 #include <asm/cache.h>
1758 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1759 index d066df6..df28194 100644
1760 --- a/arch/arm/lib/copy_to_user.S
1761 +++ b/arch/arm/lib/copy_to_user.S
1762 @@ -16,7 +16,7 @@
1763 /*
1764 * Prototype:
1765 *
1766 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1767 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1768 *
1769 * Purpose:
1770 *
1771 @@ -88,11 +88,11 @@
1772 .text
1773
1774 ENTRY(__copy_to_user_std)
1775 -WEAK(__copy_to_user)
1776 +WEAK(___copy_to_user)
1777
1778 #include "copy_template.S"
1779
1780 -ENDPROC(__copy_to_user)
1781 +ENDPROC(___copy_to_user)
1782 ENDPROC(__copy_to_user_std)
1783
1784 .pushsection .fixup,"ax"
1785 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1786 index 5c908b1..e712687 100644
1787 --- a/arch/arm/lib/uaccess.S
1788 +++ b/arch/arm/lib/uaccess.S
1789 @@ -20,7 +20,7 @@
1790
1791 #define PAGE_SHIFT 12
1792
1793 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1794 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1795 * Purpose : copy a block to user memory from kernel memory
1796 * Params : to - user memory
1797 * : from - kernel memory
1798 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1799 sub r2, r2, ip
1800 b .Lc2u_dest_aligned
1801
1802 -ENTRY(__copy_to_user)
1803 +ENTRY(___copy_to_user)
1804 stmfd sp!, {r2, r4 - r7, lr}
1805 cmp r2, #4
1806 blt .Lc2u_not_enough
1807 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1808 ldrgtb r3, [r1], #0
1809 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1810 b .Lc2u_finished
1811 -ENDPROC(__copy_to_user)
1812 +ENDPROC(___copy_to_user)
1813
1814 .pushsection .fixup,"ax"
1815 .align 0
1816 9001: ldmfd sp!, {r0, r4 - r7, pc}
1817 .popsection
1818
1819 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1820 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1821 * Purpose : copy a block from user memory to kernel memory
1822 * Params : to - kernel memory
1823 * : from - user memory
1824 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1825 sub r2, r2, ip
1826 b .Lcfu_dest_aligned
1827
1828 -ENTRY(__copy_from_user)
1829 +ENTRY(___copy_from_user)
1830 stmfd sp!, {r0, r2, r4 - r7, lr}
1831 cmp r2, #4
1832 blt .Lcfu_not_enough
1833 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1834 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1835 strgtb r3, [r0], #1
1836 b .Lcfu_finished
1837 -ENDPROC(__copy_from_user)
1838 +ENDPROC(___copy_from_user)
1839
1840 .pushsection .fixup,"ax"
1841 .align 0
1842 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1843 index 025f742..8432b08 100644
1844 --- a/arch/arm/lib/uaccess_with_memcpy.c
1845 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1846 @@ -104,7 +104,7 @@ out:
1847 }
1848
1849 unsigned long
1850 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1851 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1852 {
1853 /*
1854 * This test is stubbed out of the main function above to keep
1855 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1856 index 518091c..eae9a76 100644
1857 --- a/arch/arm/mach-omap2/board-n8x0.c
1858 +++ b/arch/arm/mach-omap2/board-n8x0.c
1859 @@ -596,7 +596,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1860 }
1861 #endif
1862
1863 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1864 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1865 .late_init = n8x0_menelaus_late_init,
1866 };
1867
1868 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1869 index 5bb4835..4760f68 100644
1870 --- a/arch/arm/mm/fault.c
1871 +++ b/arch/arm/mm/fault.c
1872 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1873 }
1874 #endif
1875
1876 +#ifdef CONFIG_PAX_PAGEEXEC
1877 + if (fsr & FSR_LNX_PF) {
1878 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1879 + do_group_exit(SIGKILL);
1880 + }
1881 +#endif
1882 +
1883 tsk->thread.address = addr;
1884 tsk->thread.error_code = fsr;
1885 tsk->thread.trap_no = 14;
1886 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1887 }
1888 #endif /* CONFIG_MMU */
1889
1890 +#ifdef CONFIG_PAX_PAGEEXEC
1891 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1892 +{
1893 + long i;
1894 +
1895 + printk(KERN_ERR "PAX: bytes at PC: ");
1896 + for (i = 0; i < 20; i++) {
1897 + unsigned char c;
1898 + if (get_user(c, (__force unsigned char __user *)pc+i))
1899 + printk(KERN_CONT "?? ");
1900 + else
1901 + printk(KERN_CONT "%02x ", c);
1902 + }
1903 + printk("\n");
1904 +
1905 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1906 + for (i = -1; i < 20; i++) {
1907 + unsigned long c;
1908 + if (get_user(c, (__force unsigned long __user *)sp+i))
1909 + printk(KERN_CONT "???????? ");
1910 + else
1911 + printk(KERN_CONT "%08lx ", c);
1912 + }
1913 + printk("\n");
1914 +}
1915 +#endif
1916 +
1917 /*
1918 * First Level Translation Fault Handler
1919 *
1920 @@ -577,6 +611,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1921 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1922 struct siginfo info;
1923
1924 +#ifdef CONFIG_PAX_REFCOUNT
1925 + if (fsr_fs(ifsr) == 2) {
1926 + unsigned int bkpt;
1927 +
1928 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1929 + current->thread.error_code = ifsr;
1930 + current->thread.trap_no = 0;
1931 + pax_report_refcount_overflow(regs);
1932 + fixup_exception(regs);
1933 + return;
1934 + }
1935 + }
1936 +#endif
1937 +
1938 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1939 return;
1940
1941 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1942 index ce8cb19..3ec539d 100644
1943 --- a/arch/arm/mm/mmap.c
1944 +++ b/arch/arm/mm/mmap.c
1945 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1946 if (len > TASK_SIZE)
1947 return -ENOMEM;
1948
1949 +#ifdef CONFIG_PAX_RANDMMAP
1950 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1951 +#endif
1952 +
1953 if (addr) {
1954 if (do_align)
1955 addr = COLOUR_ALIGN(addr, pgoff);
1956 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1957 addr = PAGE_ALIGN(addr);
1958
1959 vma = find_vma(mm, addr);
1960 - if (TASK_SIZE - len >= addr &&
1961 - (!vma || addr + len <= vma->vm_start))
1962 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1963 return addr;
1964 }
1965 if (len > mm->cached_hole_size) {
1966 - start_addr = addr = mm->free_area_cache;
1967 + start_addr = addr = mm->free_area_cache;
1968 } else {
1969 - start_addr = addr = mm->mmap_base;
1970 - mm->cached_hole_size = 0;
1971 + start_addr = addr = mm->mmap_base;
1972 + mm->cached_hole_size = 0;
1973 }
1974
1975 full_search:
1976 @@ -124,14 +127,14 @@ full_search:
1977 * Start a new search - just in case we missed
1978 * some holes.
1979 */
1980 - if (start_addr != TASK_UNMAPPED_BASE) {
1981 - start_addr = addr = TASK_UNMAPPED_BASE;
1982 + if (start_addr != mm->mmap_base) {
1983 + start_addr = addr = mm->mmap_base;
1984 mm->cached_hole_size = 0;
1985 goto full_search;
1986 }
1987 return -ENOMEM;
1988 }
1989 - if (!vma || addr + len <= vma->vm_start) {
1990 + if (check_heap_stack_gap(vma, addr, len)) {
1991 /*
1992 * Remember the place where we stopped the search:
1993 */
1994 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1995
1996 if (mmap_is_legacy()) {
1997 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1998 +
1999 +#ifdef CONFIG_PAX_RANDMMAP
2000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2001 + mm->mmap_base += mm->delta_mmap;
2002 +#endif
2003 +
2004 mm->get_unmapped_area = arch_get_unmapped_area;
2005 mm->unmap_area = arch_unmap_area;
2006 } else {
2007 mm->mmap_base = mmap_base(random_factor);
2008 +
2009 +#ifdef CONFIG_PAX_RANDMMAP
2010 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2011 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2012 +#endif
2013 +
2014 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2015 mm->unmap_area = arch_unmap_area_topdown;
2016 }
2017 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2018 index fd556f7..af2e7d2 100644
2019 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2020 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2021 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2022 value in bridge_virt_base */
2023 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2024 const int win);
2025 -};
2026 +} __no_const;
2027
2028 /*
2029 * Information needed to setup one address mapping.
2030 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2031 index 71a6827..e7fbc23 100644
2032 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2033 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2035 int (*started)(unsigned ch);
2036 int (*flush)(unsigned ch);
2037 int (*stop)(unsigned ch);
2038 -};
2039 +} __no_const;
2040
2041 extern void *samsung_dmadev_get_ops(void);
2042 extern void *s3c_dma_get_ops(void);
2043 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2044 index 5f28cae..3d23723 100644
2045 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2046 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2047 @@ -14,7 +14,7 @@
2048 struct s5p_ehci_platdata {
2049 int (*phy_init)(struct platform_device *pdev, int type);
2050 int (*phy_exit)(struct platform_device *pdev, int type);
2051 -};
2052 +} __no_const;
2053
2054 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2055
2056 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2057 index c3a58a1..78fbf54 100644
2058 --- a/arch/avr32/include/asm/cache.h
2059 +++ b/arch/avr32/include/asm/cache.h
2060 @@ -1,8 +1,10 @@
2061 #ifndef __ASM_AVR32_CACHE_H
2062 #define __ASM_AVR32_CACHE_H
2063
2064 +#include <linux/const.h>
2065 +
2066 #define L1_CACHE_SHIFT 5
2067 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2068 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2069
2070 /*
2071 * Memory returned by kmalloc() may be used for DMA, so we must make
2072 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2073 index 3b3159b..425ea94 100644
2074 --- a/arch/avr32/include/asm/elf.h
2075 +++ b/arch/avr32/include/asm/elf.h
2076 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2077 the loader. We need to make sure that it is out of the way of the program
2078 that it will "exec", and that there is sufficient room for the brk. */
2079
2080 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2081 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2082
2083 +#ifdef CONFIG_PAX_ASLR
2084 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2085 +
2086 +#define PAX_DELTA_MMAP_LEN 15
2087 +#define PAX_DELTA_STACK_LEN 15
2088 +#endif
2089
2090 /* This yields a mask that user programs can use to figure out what
2091 instruction set this CPU supports. This could be done in user space,
2092 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2093 index b7f5c68..556135c 100644
2094 --- a/arch/avr32/include/asm/kmap_types.h
2095 +++ b/arch/avr32/include/asm/kmap_types.h
2096 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2097 D(11) KM_IRQ1,
2098 D(12) KM_SOFTIRQ0,
2099 D(13) KM_SOFTIRQ1,
2100 -D(14) KM_TYPE_NR
2101 +D(14) KM_CLEARPAGE,
2102 +D(15) KM_TYPE_NR
2103 };
2104
2105 #undef D
2106 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2107 index f7040a1..db9f300 100644
2108 --- a/arch/avr32/mm/fault.c
2109 +++ b/arch/avr32/mm/fault.c
2110 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2111
2112 int exception_trace = 1;
2113
2114 +#ifdef CONFIG_PAX_PAGEEXEC
2115 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2116 +{
2117 + unsigned long i;
2118 +
2119 + printk(KERN_ERR "PAX: bytes at PC: ");
2120 + for (i = 0; i < 20; i++) {
2121 + unsigned char c;
2122 + if (get_user(c, (unsigned char *)pc+i))
2123 + printk(KERN_CONT "???????? ");
2124 + else
2125 + printk(KERN_CONT "%02x ", c);
2126 + }
2127 + printk("\n");
2128 +}
2129 +#endif
2130 +
2131 /*
2132 * This routine handles page faults. It determines the address and the
2133 * problem, and then passes it off to one of the appropriate routines.
2134 @@ -156,6 +173,16 @@ bad_area:
2135 up_read(&mm->mmap_sem);
2136
2137 if (user_mode(regs)) {
2138 +
2139 +#ifdef CONFIG_PAX_PAGEEXEC
2140 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2141 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2142 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2143 + do_group_exit(SIGKILL);
2144 + }
2145 + }
2146 +#endif
2147 +
2148 if (exception_trace && printk_ratelimit())
2149 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2150 "sp %08lx ecr %lu\n",
2151 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2152 index 568885a..f8008df 100644
2153 --- a/arch/blackfin/include/asm/cache.h
2154 +++ b/arch/blackfin/include/asm/cache.h
2155 @@ -7,6 +7,7 @@
2156 #ifndef __ARCH_BLACKFIN_CACHE_H
2157 #define __ARCH_BLACKFIN_CACHE_H
2158
2159 +#include <linux/const.h>
2160 #include <linux/linkage.h> /* for asmlinkage */
2161
2162 /*
2163 @@ -14,7 +15,7 @@
2164 * Blackfin loads 32 bytes for cache
2165 */
2166 #define L1_CACHE_SHIFT 5
2167 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2168 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2169 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2170
2171 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2172 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2173 index aea2718..3639a60 100644
2174 --- a/arch/cris/include/arch-v10/arch/cache.h
2175 +++ b/arch/cris/include/arch-v10/arch/cache.h
2176 @@ -1,8 +1,9 @@
2177 #ifndef _ASM_ARCH_CACHE_H
2178 #define _ASM_ARCH_CACHE_H
2179
2180 +#include <linux/const.h>
2181 /* Etrax 100LX have 32-byte cache-lines. */
2182 -#define L1_CACHE_BYTES 32
2183 #define L1_CACHE_SHIFT 5
2184 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2185
2186 #endif /* _ASM_ARCH_CACHE_H */
2187 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2188 index 1de779f..336fad3 100644
2189 --- a/arch/cris/include/arch-v32/arch/cache.h
2190 +++ b/arch/cris/include/arch-v32/arch/cache.h
2191 @@ -1,11 +1,12 @@
2192 #ifndef _ASM_CRIS_ARCH_CACHE_H
2193 #define _ASM_CRIS_ARCH_CACHE_H
2194
2195 +#include <linux/const.h>
2196 #include <arch/hwregs/dma.h>
2197
2198 /* A cache-line is 32 bytes. */
2199 -#define L1_CACHE_BYTES 32
2200 #define L1_CACHE_SHIFT 5
2201 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2202
2203 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2204
2205 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2206 index b86329d..6709906 100644
2207 --- a/arch/frv/include/asm/atomic.h
2208 +++ b/arch/frv/include/asm/atomic.h
2209 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2210 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2211 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2212
2213 +#define atomic64_read_unchecked(v) atomic64_read(v)
2214 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2215 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2216 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2217 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2218 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2219 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2220 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2221 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2222 +
2223 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2224 {
2225 int c, old;
2226 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2227 index 2797163..c2a401d 100644
2228 --- a/arch/frv/include/asm/cache.h
2229 +++ b/arch/frv/include/asm/cache.h
2230 @@ -12,10 +12,11 @@
2231 #ifndef __ASM_CACHE_H
2232 #define __ASM_CACHE_H
2233
2234 +#include <linux/const.h>
2235
2236 /* bytes per L1 cache line */
2237 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2238 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2239 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2240
2241 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2242 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2243 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2244 index f8e16b2..c73ff79 100644
2245 --- a/arch/frv/include/asm/kmap_types.h
2246 +++ b/arch/frv/include/asm/kmap_types.h
2247 @@ -23,6 +23,7 @@ enum km_type {
2248 KM_IRQ1,
2249 KM_SOFTIRQ0,
2250 KM_SOFTIRQ1,
2251 + KM_CLEARPAGE,
2252 KM_TYPE_NR
2253 };
2254
2255 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2256 index 385fd30..6c3d97e 100644
2257 --- a/arch/frv/mm/elf-fdpic.c
2258 +++ b/arch/frv/mm/elf-fdpic.c
2259 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2260 if (addr) {
2261 addr = PAGE_ALIGN(addr);
2262 vma = find_vma(current->mm, addr);
2263 - if (TASK_SIZE - len >= addr &&
2264 - (!vma || addr + len <= vma->vm_start))
2265 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2266 goto success;
2267 }
2268
2269 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2270 for (; vma; vma = vma->vm_next) {
2271 if (addr > limit)
2272 break;
2273 - if (addr + len <= vma->vm_start)
2274 + if (check_heap_stack_gap(vma, addr, len))
2275 goto success;
2276 addr = vma->vm_end;
2277 }
2278 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2279 for (; vma; vma = vma->vm_next) {
2280 if (addr > limit)
2281 break;
2282 - if (addr + len <= vma->vm_start)
2283 + if (check_heap_stack_gap(vma, addr, len))
2284 goto success;
2285 addr = vma->vm_end;
2286 }
2287 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2288 index c635028..6d9445a 100644
2289 --- a/arch/h8300/include/asm/cache.h
2290 +++ b/arch/h8300/include/asm/cache.h
2291 @@ -1,8 +1,10 @@
2292 #ifndef __ARCH_H8300_CACHE_H
2293 #define __ARCH_H8300_CACHE_H
2294
2295 +#include <linux/const.h>
2296 +
2297 /* bytes per L1 cache line */
2298 -#define L1_CACHE_BYTES 4
2299 +#define L1_CACHE_BYTES _AC(4,UL)
2300
2301 /* m68k-elf-gcc 2.95.2 doesn't like these */
2302
2303 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2304 index 0f01de2..d37d309 100644
2305 --- a/arch/hexagon/include/asm/cache.h
2306 +++ b/arch/hexagon/include/asm/cache.h
2307 @@ -21,9 +21,11 @@
2308 #ifndef __ASM_CACHE_H
2309 #define __ASM_CACHE_H
2310
2311 +#include <linux/const.h>
2312 +
2313 /* Bytes per L1 cache line */
2314 -#define L1_CACHE_SHIFT (5)
2315 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2316 +#define L1_CACHE_SHIFT 5
2317 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2318
2319 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2320 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2321 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2322 index 7d91166..88ab87e 100644
2323 --- a/arch/ia64/include/asm/atomic.h
2324 +++ b/arch/ia64/include/asm/atomic.h
2325 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2326 #define atomic64_inc(v) atomic64_add(1, (v))
2327 #define atomic64_dec(v) atomic64_sub(1, (v))
2328
2329 +#define atomic64_read_unchecked(v) atomic64_read(v)
2330 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2331 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2332 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2333 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2334 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2335 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2336 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2337 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2338 +
2339 /* Atomic operations are already serializing */
2340 #define smp_mb__before_atomic_dec() barrier()
2341 #define smp_mb__after_atomic_dec() barrier()
2342 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2343 index 988254a..e1ee885 100644
2344 --- a/arch/ia64/include/asm/cache.h
2345 +++ b/arch/ia64/include/asm/cache.h
2346 @@ -1,6 +1,7 @@
2347 #ifndef _ASM_IA64_CACHE_H
2348 #define _ASM_IA64_CACHE_H
2349
2350 +#include <linux/const.h>
2351
2352 /*
2353 * Copyright (C) 1998-2000 Hewlett-Packard Co
2354 @@ -9,7 +10,7 @@
2355
2356 /* Bytes per L1 (data) cache line. */
2357 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2360
2361 #ifdef CONFIG_SMP
2362 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2363 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2364 index b5298eb..67c6e62 100644
2365 --- a/arch/ia64/include/asm/elf.h
2366 +++ b/arch/ia64/include/asm/elf.h
2367 @@ -42,6 +42,13 @@
2368 */
2369 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2370
2371 +#ifdef CONFIG_PAX_ASLR
2372 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2373 +
2374 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2375 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2376 +#endif
2377 +
2378 #define PT_IA_64_UNWIND 0x70000001
2379
2380 /* IA-64 relocations: */
2381 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2382 index 96a8d92..617a1cf 100644
2383 --- a/arch/ia64/include/asm/pgalloc.h
2384 +++ b/arch/ia64/include/asm/pgalloc.h
2385 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2386 pgd_val(*pgd_entry) = __pa(pud);
2387 }
2388
2389 +static inline void
2390 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2391 +{
2392 + pgd_populate(mm, pgd_entry, pud);
2393 +}
2394 +
2395 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2396 {
2397 return quicklist_alloc(0, GFP_KERNEL, NULL);
2398 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2399 pud_val(*pud_entry) = __pa(pmd);
2400 }
2401
2402 +static inline void
2403 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2404 +{
2405 + pud_populate(mm, pud_entry, pmd);
2406 +}
2407 +
2408 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2409 {
2410 return quicklist_alloc(0, GFP_KERNEL, NULL);
2411 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2412 index 815810c..d60bd4c 100644
2413 --- a/arch/ia64/include/asm/pgtable.h
2414 +++ b/arch/ia64/include/asm/pgtable.h
2415 @@ -12,7 +12,7 @@
2416 * David Mosberger-Tang <davidm@hpl.hp.com>
2417 */
2418
2419 -
2420 +#include <linux/const.h>
2421 #include <asm/mman.h>
2422 #include <asm/page.h>
2423 #include <asm/processor.h>
2424 @@ -142,6 +142,17 @@
2425 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2426 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2427 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2428 +
2429 +#ifdef CONFIG_PAX_PAGEEXEC
2430 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2431 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2432 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 +#else
2434 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2435 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2436 +# define PAGE_COPY_NOEXEC PAGE_COPY
2437 +#endif
2438 +
2439 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2440 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2441 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2442 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2443 index 54ff557..70c88b7 100644
2444 --- a/arch/ia64/include/asm/spinlock.h
2445 +++ b/arch/ia64/include/asm/spinlock.h
2446 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2447 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2448
2449 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2450 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2451 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2452 }
2453
2454 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2455 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2456 index 449c8c0..432a3d2 100644
2457 --- a/arch/ia64/include/asm/uaccess.h
2458 +++ b/arch/ia64/include/asm/uaccess.h
2459 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2460 const void *__cu_from = (from); \
2461 long __cu_len = (n); \
2462 \
2463 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2464 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2465 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2466 __cu_len; \
2467 })
2468 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2469 long __cu_len = (n); \
2470 \
2471 __chk_user_ptr(__cu_from); \
2472 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2473 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2474 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2475 __cu_len; \
2476 })
2477 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2478 index 24603be..948052d 100644
2479 --- a/arch/ia64/kernel/module.c
2480 +++ b/arch/ia64/kernel/module.c
2481 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2482 void
2483 module_free (struct module *mod, void *module_region)
2484 {
2485 - if (mod && mod->arch.init_unw_table &&
2486 - module_region == mod->module_init) {
2487 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2488 unw_remove_unwind_table(mod->arch.init_unw_table);
2489 mod->arch.init_unw_table = NULL;
2490 }
2491 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2492 }
2493
2494 static inline int
2495 +in_init_rx (const struct module *mod, uint64_t addr)
2496 +{
2497 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2498 +}
2499 +
2500 +static inline int
2501 +in_init_rw (const struct module *mod, uint64_t addr)
2502 +{
2503 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2504 +}
2505 +
2506 +static inline int
2507 in_init (const struct module *mod, uint64_t addr)
2508 {
2509 - return addr - (uint64_t) mod->module_init < mod->init_size;
2510 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2511 +}
2512 +
2513 +static inline int
2514 +in_core_rx (const struct module *mod, uint64_t addr)
2515 +{
2516 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2517 +}
2518 +
2519 +static inline int
2520 +in_core_rw (const struct module *mod, uint64_t addr)
2521 +{
2522 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2523 }
2524
2525 static inline int
2526 in_core (const struct module *mod, uint64_t addr)
2527 {
2528 - return addr - (uint64_t) mod->module_core < mod->core_size;
2529 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2530 }
2531
2532 static inline int
2533 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2534 break;
2535
2536 case RV_BDREL:
2537 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2538 + if (in_init_rx(mod, val))
2539 + val -= (uint64_t) mod->module_init_rx;
2540 + else if (in_init_rw(mod, val))
2541 + val -= (uint64_t) mod->module_init_rw;
2542 + else if (in_core_rx(mod, val))
2543 + val -= (uint64_t) mod->module_core_rx;
2544 + else if (in_core_rw(mod, val))
2545 + val -= (uint64_t) mod->module_core_rw;
2546 break;
2547
2548 case RV_LTV:
2549 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2550 * addresses have been selected...
2551 */
2552 uint64_t gp;
2553 - if (mod->core_size > MAX_LTOFF)
2554 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2555 /*
2556 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2557 * at the end of the module.
2558 */
2559 - gp = mod->core_size - MAX_LTOFF / 2;
2560 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2561 else
2562 - gp = mod->core_size / 2;
2563 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2564 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2565 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2566 mod->arch.gp = gp;
2567 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2568 }
2569 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2570 index 609d500..7dde2a8 100644
2571 --- a/arch/ia64/kernel/sys_ia64.c
2572 +++ b/arch/ia64/kernel/sys_ia64.c
2573 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 if (REGION_NUMBER(addr) == RGN_HPAGE)
2575 addr = 0;
2576 #endif
2577 +
2578 +#ifdef CONFIG_PAX_RANDMMAP
2579 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2580 + addr = mm->free_area_cache;
2581 + else
2582 +#endif
2583 +
2584 if (!addr)
2585 addr = mm->free_area_cache;
2586
2587 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2588 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2589 /* At this point: (!vma || addr < vma->vm_end). */
2590 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2591 - if (start_addr != TASK_UNMAPPED_BASE) {
2592 + if (start_addr != mm->mmap_base) {
2593 /* Start a new search --- just in case we missed some holes. */
2594 - addr = TASK_UNMAPPED_BASE;
2595 + addr = mm->mmap_base;
2596 goto full_search;
2597 }
2598 return -ENOMEM;
2599 }
2600 - if (!vma || addr + len <= vma->vm_start) {
2601 + if (check_heap_stack_gap(vma, addr, len)) {
2602 /* Remember the address where we stopped this search: */
2603 mm->free_area_cache = addr + len;
2604 return addr;
2605 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2606 index 0ccb28f..8992469 100644
2607 --- a/arch/ia64/kernel/vmlinux.lds.S
2608 +++ b/arch/ia64/kernel/vmlinux.lds.S
2609 @@ -198,7 +198,7 @@ SECTIONS {
2610 /* Per-cpu data: */
2611 . = ALIGN(PERCPU_PAGE_SIZE);
2612 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2613 - __phys_per_cpu_start = __per_cpu_load;
2614 + __phys_per_cpu_start = per_cpu_load;
2615 /*
2616 * ensure percpu data fits
2617 * into percpu page size
2618 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2619 index 02d29c2..ea893df 100644
2620 --- a/arch/ia64/mm/fault.c
2621 +++ b/arch/ia64/mm/fault.c
2622 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2623 return pte_present(pte);
2624 }
2625
2626 +#ifdef CONFIG_PAX_PAGEEXEC
2627 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2628 +{
2629 + unsigned long i;
2630 +
2631 + printk(KERN_ERR "PAX: bytes at PC: ");
2632 + for (i = 0; i < 8; i++) {
2633 + unsigned int c;
2634 + if (get_user(c, (unsigned int *)pc+i))
2635 + printk(KERN_CONT "???????? ");
2636 + else
2637 + printk(KERN_CONT "%08x ", c);
2638 + }
2639 + printk("\n");
2640 +}
2641 +#endif
2642 +
2643 void __kprobes
2644 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2645 {
2646 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2647 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2648 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2649
2650 - if ((vma->vm_flags & mask) != mask)
2651 + if ((vma->vm_flags & mask) != mask) {
2652 +
2653 +#ifdef CONFIG_PAX_PAGEEXEC
2654 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2655 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2656 + goto bad_area;
2657 +
2658 + up_read(&mm->mmap_sem);
2659 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2660 + do_group_exit(SIGKILL);
2661 + }
2662 +#endif
2663 +
2664 goto bad_area;
2665
2666 + }
2667 +
2668 /*
2669 * If for any reason at all we couldn't handle the fault, make
2670 * sure we exit gracefully rather than endlessly redo the
2671 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2672 index 5ca674b..e0e1b70 100644
2673 --- a/arch/ia64/mm/hugetlbpage.c
2674 +++ b/arch/ia64/mm/hugetlbpage.c
2675 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2676 /* At this point: (!vmm || addr < vmm->vm_end). */
2677 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2678 return -ENOMEM;
2679 - if (!vmm || (addr + len) <= vmm->vm_start)
2680 + if (check_heap_stack_gap(vmm, addr, len))
2681 return addr;
2682 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2683 }
2684 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2685 index 0eab454..bd794f2 100644
2686 --- a/arch/ia64/mm/init.c
2687 +++ b/arch/ia64/mm/init.c
2688 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2689 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2690 vma->vm_end = vma->vm_start + PAGE_SIZE;
2691 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2692 +
2693 +#ifdef CONFIG_PAX_PAGEEXEC
2694 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2695 + vma->vm_flags &= ~VM_EXEC;
2696 +
2697 +#ifdef CONFIG_PAX_MPROTECT
2698 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2699 + vma->vm_flags &= ~VM_MAYEXEC;
2700 +#endif
2701 +
2702 + }
2703 +#endif
2704 +
2705 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2706 down_write(&current->mm->mmap_sem);
2707 if (insert_vm_struct(current->mm, vma)) {
2708 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2709 index 40b3ee9..8c2c112 100644
2710 --- a/arch/m32r/include/asm/cache.h
2711 +++ b/arch/m32r/include/asm/cache.h
2712 @@ -1,8 +1,10 @@
2713 #ifndef _ASM_M32R_CACHE_H
2714 #define _ASM_M32R_CACHE_H
2715
2716 +#include <linux/const.h>
2717 +
2718 /* L1 cache line size */
2719 #define L1_CACHE_SHIFT 4
2720 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2721 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2722
2723 #endif /* _ASM_M32R_CACHE_H */
2724 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2725 index 82abd15..d95ae5d 100644
2726 --- a/arch/m32r/lib/usercopy.c
2727 +++ b/arch/m32r/lib/usercopy.c
2728 @@ -14,6 +14,9 @@
2729 unsigned long
2730 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2731 {
2732 + if ((long)n < 0)
2733 + return n;
2734 +
2735 prefetch(from);
2736 if (access_ok(VERIFY_WRITE, to, n))
2737 __copy_user(to,from,n);
2738 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2739 unsigned long
2740 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2741 {
2742 + if ((long)n < 0)
2743 + return n;
2744 +
2745 prefetchw(to);
2746 if (access_ok(VERIFY_READ, from, n))
2747 __copy_user_zeroing(to,from,n);
2748 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2749 index 0395c51..5f26031 100644
2750 --- a/arch/m68k/include/asm/cache.h
2751 +++ b/arch/m68k/include/asm/cache.h
2752 @@ -4,9 +4,11 @@
2753 #ifndef __ARCH_M68K_CACHE_H
2754 #define __ARCH_M68K_CACHE_H
2755
2756 +#include <linux/const.h>
2757 +
2758 /* bytes per L1 cache line */
2759 #define L1_CACHE_SHIFT 4
2760 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2761 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2762
2763 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2764
2765 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2766 index 4efe96a..60e8699 100644
2767 --- a/arch/microblaze/include/asm/cache.h
2768 +++ b/arch/microblaze/include/asm/cache.h
2769 @@ -13,11 +13,12 @@
2770 #ifndef _ASM_MICROBLAZE_CACHE_H
2771 #define _ASM_MICROBLAZE_CACHE_H
2772
2773 +#include <linux/const.h>
2774 #include <asm/registers.h>
2775
2776 #define L1_CACHE_SHIFT 5
2777 /* word-granular cache in microblaze */
2778 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2779 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2780
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782
2783 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2784 index 3f4c5cb..3439c6e 100644
2785 --- a/arch/mips/include/asm/atomic.h
2786 +++ b/arch/mips/include/asm/atomic.h
2787 @@ -21,6 +21,10 @@
2788 #include <asm/cmpxchg.h>
2789 #include <asm/war.h>
2790
2791 +#ifdef CONFIG_GENERIC_ATOMIC64
2792 +#include <asm-generic/atomic64.h>
2793 +#endif
2794 +
2795 #define ATOMIC_INIT(i) { (i) }
2796
2797 /*
2798 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2799 */
2800 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2801
2802 +#define atomic64_read_unchecked(v) atomic64_read(v)
2803 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2804 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2805 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2806 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2807 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2808 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2809 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2810 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2811 +
2812 #endif /* CONFIG_64BIT */
2813
2814 /*
2815 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2816 index b4db69f..8f3b093 100644
2817 --- a/arch/mips/include/asm/cache.h
2818 +++ b/arch/mips/include/asm/cache.h
2819 @@ -9,10 +9,11 @@
2820 #ifndef _ASM_CACHE_H
2821 #define _ASM_CACHE_H
2822
2823 +#include <linux/const.h>
2824 #include <kmalloc.h>
2825
2826 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2827 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2828 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2829
2830 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2831 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2832 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2833 index 455c0ac..ad65fbe 100644
2834 --- a/arch/mips/include/asm/elf.h
2835 +++ b/arch/mips/include/asm/elf.h
2836 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2837 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2838 #endif
2839
2840 +#ifdef CONFIG_PAX_ASLR
2841 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2842 +
2843 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2844 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#endif
2846 +
2847 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2848 struct linux_binprm;
2849 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2850 int uses_interp);
2851
2852 -struct mm_struct;
2853 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2854 -#define arch_randomize_brk arch_randomize_brk
2855 -
2856 #endif /* _ASM_ELF_H */
2857 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2858 index c1f6afa..38cc6e9 100644
2859 --- a/arch/mips/include/asm/exec.h
2860 +++ b/arch/mips/include/asm/exec.h
2861 @@ -12,6 +12,6 @@
2862 #ifndef _ASM_EXEC_H
2863 #define _ASM_EXEC_H
2864
2865 -extern unsigned long arch_align_stack(unsigned long sp);
2866 +#define arch_align_stack(x) ((x) & ~0xfUL)
2867
2868 #endif /* _ASM_EXEC_H */
2869 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2870 index da9bd7d..91aa7ab 100644
2871 --- a/arch/mips/include/asm/page.h
2872 +++ b/arch/mips/include/asm/page.h
2873 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2874 #ifdef CONFIG_CPU_MIPS32
2875 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2876 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2877 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2878 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2879 #else
2880 typedef struct { unsigned long long pte; } pte_t;
2881 #define pte_val(x) ((x).pte)
2882 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2883 index 881d18b..cea38bc 100644
2884 --- a/arch/mips/include/asm/pgalloc.h
2885 +++ b/arch/mips/include/asm/pgalloc.h
2886 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2887 {
2888 set_pud(pud, __pud((unsigned long)pmd));
2889 }
2890 +
2891 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2892 +{
2893 + pud_populate(mm, pud, pmd);
2894 +}
2895 #endif
2896
2897 /*
2898 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2899 index 0d85d8e..ec71487 100644
2900 --- a/arch/mips/include/asm/thread_info.h
2901 +++ b/arch/mips/include/asm/thread_info.h
2902 @@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2903 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2904 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2905 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2906 +/* li takes a 32bit immediate */
2907 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2908 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2909
2910 #ifdef CONFIG_MIPS32_O32
2911 @@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2912 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2913 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2914 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2915 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2916 +
2917 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2918
2919 /* work to do in syscall_trace_leave() */
2920 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2921 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2922
2923 /* work to do on interrupt/exception return */
2924 #define _TIF_WORK_MASK (0x0000ffef & \
2925 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2926 /* work to do on any return to u-space */
2927 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2928 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2929
2930 #endif /* __KERNEL__ */
2931
2932 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2933 index 9fdd8bc..4bd7f1a 100644
2934 --- a/arch/mips/kernel/binfmt_elfn32.c
2935 +++ b/arch/mips/kernel/binfmt_elfn32.c
2936 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2937 #undef ELF_ET_DYN_BASE
2938 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2939
2940 +#ifdef CONFIG_PAX_ASLR
2941 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2942 +
2943 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2944 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#endif
2946 +
2947 #include <asm/processor.h>
2948 #include <linux/module.h>
2949 #include <linux/elfcore.h>
2950 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2951 index ff44823..97f8906 100644
2952 --- a/arch/mips/kernel/binfmt_elfo32.c
2953 +++ b/arch/mips/kernel/binfmt_elfo32.c
2954 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2955 #undef ELF_ET_DYN_BASE
2956 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2957
2958 +#ifdef CONFIG_PAX_ASLR
2959 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2960 +
2961 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2962 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#endif
2964 +
2965 #include <asm/processor.h>
2966
2967 /*
2968 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2969 index e9a5fd7..378809a 100644
2970 --- a/arch/mips/kernel/process.c
2971 +++ b/arch/mips/kernel/process.c
2972 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2973 out:
2974 return pc;
2975 }
2976 -
2977 -/*
2978 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2979 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2980 - */
2981 -unsigned long arch_align_stack(unsigned long sp)
2982 -{
2983 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2984 - sp -= get_random_int() & ~PAGE_MASK;
2985 -
2986 - return sp & ALMASK;
2987 -}
2988 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2989 index 7c24c29..e2f1981 100644
2990 --- a/arch/mips/kernel/ptrace.c
2991 +++ b/arch/mips/kernel/ptrace.c
2992 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2993 return arch;
2994 }
2995
2996 +#ifdef CONFIG_GRKERNSEC_SETXID
2997 +extern void gr_delayed_cred_worker(void);
2998 +#endif
2999 +
3000 /*
3001 * Notification of system call entry/exit
3002 * - triggered by current->work.syscall_trace
3003 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3004 /* do the secure computing check first */
3005 secure_computing(regs->regs[2]);
3006
3007 +#ifdef CONFIG_GRKERNSEC_SETXID
3008 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3009 + gr_delayed_cred_worker();
3010 +#endif
3011 +
3012 if (!(current->ptrace & PT_PTRACED))
3013 goto out;
3014
3015 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3016 index a632bc1..0b77c7c 100644
3017 --- a/arch/mips/kernel/scall32-o32.S
3018 +++ b/arch/mips/kernel/scall32-o32.S
3019 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3020
3021 stack_done:
3022 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3023 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3024 + li t1, _TIF_SYSCALL_WORK
3025 and t0, t1
3026 bnez t0, syscall_trace_entry # -> yes
3027
3028 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3029 index 3b5a5e9..e1ee86d 100644
3030 --- a/arch/mips/kernel/scall64-64.S
3031 +++ b/arch/mips/kernel/scall64-64.S
3032 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3033
3034 sd a3, PT_R26(sp) # save a3 for syscall restarting
3035
3036 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3037 + li t1, _TIF_SYSCALL_WORK
3038 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3039 and t0, t1, t0
3040 bnez t0, syscall_trace_entry
3041 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3042 index 6be6f70..1859577 100644
3043 --- a/arch/mips/kernel/scall64-n32.S
3044 +++ b/arch/mips/kernel/scall64-n32.S
3045 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3046
3047 sd a3, PT_R26(sp) # save a3 for syscall restarting
3048
3049 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3050 + li t1, _TIF_SYSCALL_WORK
3051 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3052 and t0, t1, t0
3053 bnez t0, n32_syscall_trace_entry
3054 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3055 index 5422855..74e63a3 100644
3056 --- a/arch/mips/kernel/scall64-o32.S
3057 +++ b/arch/mips/kernel/scall64-o32.S
3058 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3059 PTR 4b, bad_stack
3060 .previous
3061
3062 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3063 + li t1, _TIF_SYSCALL_WORK
3064 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3065 and t0, t1, t0
3066 bnez t0, trace_a_syscall
3067 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3068 index c14f6df..537e729 100644
3069 --- a/arch/mips/mm/fault.c
3070 +++ b/arch/mips/mm/fault.c
3071 @@ -27,6 +27,23 @@
3072 #include <asm/highmem.h> /* For VMALLOC_END */
3073 #include <linux/kdebug.h>
3074
3075 +#ifdef CONFIG_PAX_PAGEEXEC
3076 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3077 +{
3078 + unsigned long i;
3079 +
3080 + printk(KERN_ERR "PAX: bytes at PC: ");
3081 + for (i = 0; i < 5; i++) {
3082 + unsigned int c;
3083 + if (get_user(c, (unsigned int *)pc+i))
3084 + printk(KERN_CONT "???????? ");
3085 + else
3086 + printk(KERN_CONT "%08x ", c);
3087 + }
3088 + printk("\n");
3089 +}
3090 +#endif
3091 +
3092 /*
3093 * This routine handles page faults. It determines the address,
3094 * and the problem, and then passes it off to one of the appropriate
3095 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3096 index 302d779..7d35bf8 100644
3097 --- a/arch/mips/mm/mmap.c
3098 +++ b/arch/mips/mm/mmap.c
3099 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3100 do_color_align = 1;
3101
3102 /* requesting a specific address */
3103 +
3104 +#ifdef CONFIG_PAX_RANDMMAP
3105 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3106 +#endif
3107 +
3108 if (addr) {
3109 if (do_color_align)
3110 addr = COLOUR_ALIGN(addr, pgoff);
3111 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3112 addr = PAGE_ALIGN(addr);
3113
3114 vma = find_vma(mm, addr);
3115 - if (TASK_SIZE - len >= addr &&
3116 - (!vma || addr + len <= vma->vm_start))
3117 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3118 return addr;
3119 }
3120
3121 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3122 /* At this point: (!vma || addr < vma->vm_end). */
3123 if (TASK_SIZE - len < addr)
3124 return -ENOMEM;
3125 - if (!vma || addr + len <= vma->vm_start)
3126 + if (check_heap_stack_gap(vmm, addr, len))
3127 return addr;
3128 addr = vma->vm_end;
3129 if (do_color_align)
3130 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3131 /* make sure it can fit in the remaining address space */
3132 if (likely(addr > len)) {
3133 vma = find_vma(mm, addr - len);
3134 - if (!vma || addr <= vma->vm_start) {
3135 + if (check_heap_stack_gap(vmm, addr - len, len))
3136 /* cache the address as a hint for next time */
3137 return mm->free_area_cache = addr - len;
3138 }
3139 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3140 * return with success:
3141 */
3142 vma = find_vma(mm, addr);
3143 - if (likely(!vma || addr + len <= vma->vm_start)) {
3144 + if (check_heap_stack_gap(vmm, addr, len)) {
3145 /* cache the address as a hint for next time */
3146 return mm->free_area_cache = addr;
3147 }
3148 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3149 mm->unmap_area = arch_unmap_area_topdown;
3150 }
3151 }
3152 -
3153 -static inline unsigned long brk_rnd(void)
3154 -{
3155 - unsigned long rnd = get_random_int();
3156 -
3157 - rnd = rnd << PAGE_SHIFT;
3158 - /* 8MB for 32bit, 256MB for 64bit */
3159 - if (TASK_IS_32BIT_ADDR)
3160 - rnd = rnd & 0x7ffffful;
3161 - else
3162 - rnd = rnd & 0xffffffful;
3163 -
3164 - return rnd;
3165 -}
3166 -
3167 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3168 -{
3169 - unsigned long base = mm->brk;
3170 - unsigned long ret;
3171 -
3172 - ret = PAGE_ALIGN(base + brk_rnd());
3173 -
3174 - if (ret < mm->brk)
3175 - return mm->brk;
3176 -
3177 - return ret;
3178 -}
3179 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3180 index 967d144..db12197 100644
3181 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3182 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 @@ -11,12 +11,14 @@
3184 #ifndef _ASM_PROC_CACHE_H
3185 #define _ASM_PROC_CACHE_H
3186
3187 +#include <linux/const.h>
3188 +
3189 /* L1 cache */
3190
3191 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3192 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3193 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3194 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3195 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3196 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3197
3198 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3199 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3200 index bcb5df2..84fabd2 100644
3201 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3202 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 @@ -16,13 +16,15 @@
3204 #ifndef _ASM_PROC_CACHE_H
3205 #define _ASM_PROC_CACHE_H
3206
3207 +#include <linux/const.h>
3208 +
3209 /*
3210 * L1 cache
3211 */
3212 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3213 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3214 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3215 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3216 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3217 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3218
3219 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3220 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3221 index 4ce7a01..449202a 100644
3222 --- a/arch/openrisc/include/asm/cache.h
3223 +++ b/arch/openrisc/include/asm/cache.h
3224 @@ -19,11 +19,13 @@
3225 #ifndef __ASM_OPENRISC_CACHE_H
3226 #define __ASM_OPENRISC_CACHE_H
3227
3228 +#include <linux/const.h>
3229 +
3230 /* FIXME: How can we replace these with values from the CPU...
3231 * they shouldn't be hard-coded!
3232 */
3233
3234 -#define L1_CACHE_BYTES 16
3235 #define L1_CACHE_SHIFT 4
3236 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3237
3238 #endif /* __ASM_OPENRISC_CACHE_H */
3239 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3240 index 6c6defc..d30653d 100644
3241 --- a/arch/parisc/include/asm/atomic.h
3242 +++ b/arch/parisc/include/asm/atomic.h
3243 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3244
3245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3246
3247 +#define atomic64_read_unchecked(v) atomic64_read(v)
3248 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3249 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3250 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3251 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3252 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3253 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3254 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3255 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3256 +
3257 #endif /* !CONFIG_64BIT */
3258
3259
3260 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3261 index 47f11c7..3420df2 100644
3262 --- a/arch/parisc/include/asm/cache.h
3263 +++ b/arch/parisc/include/asm/cache.h
3264 @@ -5,6 +5,7 @@
3265 #ifndef __ARCH_PARISC_CACHE_H
3266 #define __ARCH_PARISC_CACHE_H
3267
3268 +#include <linux/const.h>
3269
3270 /*
3271 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3272 @@ -15,13 +16,13 @@
3273 * just ruin performance.
3274 */
3275 #ifdef CONFIG_PA20
3276 -#define L1_CACHE_BYTES 64
3277 #define L1_CACHE_SHIFT 6
3278 #else
3279 -#define L1_CACHE_BYTES 32
3280 #define L1_CACHE_SHIFT 5
3281 #endif
3282
3283 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3284 +
3285 #ifndef __ASSEMBLY__
3286
3287 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3288 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3289 index 19f6cb1..6c78cf2 100644
3290 --- a/arch/parisc/include/asm/elf.h
3291 +++ b/arch/parisc/include/asm/elf.h
3292 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3293
3294 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3295
3296 +#ifdef CONFIG_PAX_ASLR
3297 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3298 +
3299 +#define PAX_DELTA_MMAP_LEN 16
3300 +#define PAX_DELTA_STACK_LEN 16
3301 +#endif
3302 +
3303 /* This yields a mask that user programs can use to figure out what
3304 instruction set this CPU supports. This could be done in user space,
3305 but it's not easy, and we've already done it here. */
3306 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3307 index fc987a1..6e068ef 100644
3308 --- a/arch/parisc/include/asm/pgalloc.h
3309 +++ b/arch/parisc/include/asm/pgalloc.h
3310 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3311 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3312 }
3313
3314 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3315 +{
3316 + pgd_populate(mm, pgd, pmd);
3317 +}
3318 +
3319 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3320 {
3321 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3322 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3323 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3324 #define pmd_free(mm, x) do { } while (0)
3325 #define pgd_populate(mm, pmd, pte) BUG()
3326 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3327
3328 #endif
3329
3330 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3331 index ee99f23..802b0a1 100644
3332 --- a/arch/parisc/include/asm/pgtable.h
3333 +++ b/arch/parisc/include/asm/pgtable.h
3334 @@ -212,6 +212,17 @@ struct vm_area_struct;
3335 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3336 #define PAGE_COPY PAGE_EXECREAD
3337 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3338 +
3339 +#ifdef CONFIG_PAX_PAGEEXEC
3340 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3341 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3342 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +#else
3344 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3345 +# define PAGE_COPY_NOEXEC PAGE_COPY
3346 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3347 +#endif
3348 +
3349 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3350 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3351 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3352 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3353 index 9ac0660..6ed15c4 100644
3354 --- a/arch/parisc/include/asm/uaccess.h
3355 +++ b/arch/parisc/include/asm/uaccess.h
3356 @@ -252,10 +252,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3357 const void __user *from,
3358 unsigned long n)
3359 {
3360 - int sz = __compiletime_object_size(to);
3361 + size_t sz = __compiletime_object_size(to);
3362 int ret = -EFAULT;
3363
3364 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3365 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3366 ret = __copy_from_user(to, from, n);
3367 else
3368 copy_from_user_overflow();
3369 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3370 index 5e34ccf..672bc9c 100644
3371 --- a/arch/parisc/kernel/module.c
3372 +++ b/arch/parisc/kernel/module.c
3373 @@ -98,16 +98,38 @@
3374
3375 /* three functions to determine where in the module core
3376 * or init pieces the location is */
3377 +static inline int in_init_rx(struct module *me, void *loc)
3378 +{
3379 + return (loc >= me->module_init_rx &&
3380 + loc < (me->module_init_rx + me->init_size_rx));
3381 +}
3382 +
3383 +static inline int in_init_rw(struct module *me, void *loc)
3384 +{
3385 + return (loc >= me->module_init_rw &&
3386 + loc < (me->module_init_rw + me->init_size_rw));
3387 +}
3388 +
3389 static inline int in_init(struct module *me, void *loc)
3390 {
3391 - return (loc >= me->module_init &&
3392 - loc <= (me->module_init + me->init_size));
3393 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3394 +}
3395 +
3396 +static inline int in_core_rx(struct module *me, void *loc)
3397 +{
3398 + return (loc >= me->module_core_rx &&
3399 + loc < (me->module_core_rx + me->core_size_rx));
3400 +}
3401 +
3402 +static inline int in_core_rw(struct module *me, void *loc)
3403 +{
3404 + return (loc >= me->module_core_rw &&
3405 + loc < (me->module_core_rw + me->core_size_rw));
3406 }
3407
3408 static inline int in_core(struct module *me, void *loc)
3409 {
3410 - return (loc >= me->module_core &&
3411 - loc <= (me->module_core + me->core_size));
3412 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3413 }
3414
3415 static inline int in_local(struct module *me, void *loc)
3416 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3417 }
3418
3419 /* align things a bit */
3420 - me->core_size = ALIGN(me->core_size, 16);
3421 - me->arch.got_offset = me->core_size;
3422 - me->core_size += gots * sizeof(struct got_entry);
3423 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3424 + me->arch.got_offset = me->core_size_rw;
3425 + me->core_size_rw += gots * sizeof(struct got_entry);
3426
3427 - me->core_size = ALIGN(me->core_size, 16);
3428 - me->arch.fdesc_offset = me->core_size;
3429 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3430 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431 + me->arch.fdesc_offset = me->core_size_rw;
3432 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3433
3434 me->arch.got_max = gots;
3435 me->arch.fdesc_max = fdescs;
3436 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3437
3438 BUG_ON(value == 0);
3439
3440 - got = me->module_core + me->arch.got_offset;
3441 + got = me->module_core_rw + me->arch.got_offset;
3442 for (i = 0; got[i].addr; i++)
3443 if (got[i].addr == value)
3444 goto out;
3445 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3446 #ifdef CONFIG_64BIT
3447 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3448 {
3449 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3450 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3451
3452 if (!value) {
3453 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3454 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455
3456 /* Create new one */
3457 fdesc->addr = value;
3458 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3459 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3460 return (Elf_Addr)fdesc;
3461 }
3462 #endif /* CONFIG_64BIT */
3463 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3464
3465 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3466 end = table + sechdrs[me->arch.unwind_section].sh_size;
3467 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3468 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3469
3470 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3471 me->arch.unwind_section, table, end, gp);
3472 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3473 index c9b9322..02d8940 100644
3474 --- a/arch/parisc/kernel/sys_parisc.c
3475 +++ b/arch/parisc/kernel/sys_parisc.c
3476 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3477 /* At this point: (!vma || addr < vma->vm_end). */
3478 if (TASK_SIZE - len < addr)
3479 return -ENOMEM;
3480 - if (!vma || addr + len <= vma->vm_start)
3481 + if (check_heap_stack_gap(vma, addr, len))
3482 return addr;
3483 addr = vma->vm_end;
3484 }
3485 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3486 /* At this point: (!vma || addr < vma->vm_end). */
3487 if (TASK_SIZE - len < addr)
3488 return -ENOMEM;
3489 - if (!vma || addr + len <= vma->vm_start)
3490 + if (check_heap_stack_gap(vma, addr, len))
3491 return addr;
3492 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3493 if (addr < vma->vm_end) /* handle wraparound */
3494 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3495 if (flags & MAP_FIXED)
3496 return addr;
3497 if (!addr)
3498 - addr = TASK_UNMAPPED_BASE;
3499 + addr = current->mm->mmap_base;
3500
3501 if (filp) {
3502 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3503 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3504 index 45ba99f..8e22c33 100644
3505 --- a/arch/parisc/kernel/traps.c
3506 +++ b/arch/parisc/kernel/traps.c
3507 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3508
3509 down_read(&current->mm->mmap_sem);
3510 vma = find_vma(current->mm,regs->iaoq[0]);
3511 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3512 - && (vma->vm_flags & VM_EXEC)) {
3513 -
3514 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3515 fault_address = regs->iaoq[0];
3516 fault_space = regs->iasq[0];
3517
3518 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3519 index 18162ce..94de376 100644
3520 --- a/arch/parisc/mm/fault.c
3521 +++ b/arch/parisc/mm/fault.c
3522 @@ -15,6 +15,7 @@
3523 #include <linux/sched.h>
3524 #include <linux/interrupt.h>
3525 #include <linux/module.h>
3526 +#include <linux/unistd.h>
3527
3528 #include <asm/uaccess.h>
3529 #include <asm/traps.h>
3530 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3531 static unsigned long
3532 parisc_acctyp(unsigned long code, unsigned int inst)
3533 {
3534 - if (code == 6 || code == 16)
3535 + if (code == 6 || code == 7 || code == 16)
3536 return VM_EXEC;
3537
3538 switch (inst & 0xf0000000) {
3539 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3540 }
3541 #endif
3542
3543 +#ifdef CONFIG_PAX_PAGEEXEC
3544 +/*
3545 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3546 + *
3547 + * returns 1 when task should be killed
3548 + * 2 when rt_sigreturn trampoline was detected
3549 + * 3 when unpatched PLT trampoline was detected
3550 + */
3551 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3552 +{
3553 +
3554 +#ifdef CONFIG_PAX_EMUPLT
3555 + int err;
3556 +
3557 + do { /* PaX: unpatched PLT emulation */
3558 + unsigned int bl, depwi;
3559 +
3560 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3561 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3562 +
3563 + if (err)
3564 + break;
3565 +
3566 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3567 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3568 +
3569 + err = get_user(ldw, (unsigned int *)addr);
3570 + err |= get_user(bv, (unsigned int *)(addr+4));
3571 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3572 +
3573 + if (err)
3574 + break;
3575 +
3576 + if (ldw == 0x0E801096U &&
3577 + bv == 0xEAC0C000U &&
3578 + ldw2 == 0x0E881095U)
3579 + {
3580 + unsigned int resolver, map;
3581 +
3582 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3583 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3584 + if (err)
3585 + break;
3586 +
3587 + regs->gr[20] = instruction_pointer(regs)+8;
3588 + regs->gr[21] = map;
3589 + regs->gr[22] = resolver;
3590 + regs->iaoq[0] = resolver | 3UL;
3591 + regs->iaoq[1] = regs->iaoq[0] + 4;
3592 + return 3;
3593 + }
3594 + }
3595 + } while (0);
3596 +#endif
3597 +
3598 +#ifdef CONFIG_PAX_EMUTRAMP
3599 +
3600 +#ifndef CONFIG_PAX_EMUSIGRT
3601 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3602 + return 1;
3603 +#endif
3604 +
3605 + do { /* PaX: rt_sigreturn emulation */
3606 + unsigned int ldi1, ldi2, bel, nop;
3607 +
3608 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3609 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3610 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3611 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3612 +
3613 + if (err)
3614 + break;
3615 +
3616 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3617 + ldi2 == 0x3414015AU &&
3618 + bel == 0xE4008200U &&
3619 + nop == 0x08000240U)
3620 + {
3621 + regs->gr[25] = (ldi1 & 2) >> 1;
3622 + regs->gr[20] = __NR_rt_sigreturn;
3623 + regs->gr[31] = regs->iaoq[1] + 16;
3624 + regs->sr[0] = regs->iasq[1];
3625 + regs->iaoq[0] = 0x100UL;
3626 + regs->iaoq[1] = regs->iaoq[0] + 4;
3627 + regs->iasq[0] = regs->sr[2];
3628 + regs->iasq[1] = regs->sr[2];
3629 + return 2;
3630 + }
3631 + } while (0);
3632 +#endif
3633 +
3634 + return 1;
3635 +}
3636 +
3637 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3638 +{
3639 + unsigned long i;
3640 +
3641 + printk(KERN_ERR "PAX: bytes at PC: ");
3642 + for (i = 0; i < 5; i++) {
3643 + unsigned int c;
3644 + if (get_user(c, (unsigned int *)pc+i))
3645 + printk(KERN_CONT "???????? ");
3646 + else
3647 + printk(KERN_CONT "%08x ", c);
3648 + }
3649 + printk("\n");
3650 +}
3651 +#endif
3652 +
3653 int fixup_exception(struct pt_regs *regs)
3654 {
3655 const struct exception_table_entry *fix;
3656 @@ -192,8 +303,33 @@ good_area:
3657
3658 acc_type = parisc_acctyp(code,regs->iir);
3659
3660 - if ((vma->vm_flags & acc_type) != acc_type)
3661 + if ((vma->vm_flags & acc_type) != acc_type) {
3662 +
3663 +#ifdef CONFIG_PAX_PAGEEXEC
3664 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3665 + (address & ~3UL) == instruction_pointer(regs))
3666 + {
3667 + up_read(&mm->mmap_sem);
3668 + switch (pax_handle_fetch_fault(regs)) {
3669 +
3670 +#ifdef CONFIG_PAX_EMUPLT
3671 + case 3:
3672 + return;
3673 +#endif
3674 +
3675 +#ifdef CONFIG_PAX_EMUTRAMP
3676 + case 2:
3677 + return;
3678 +#endif
3679 +
3680 + }
3681 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3682 + do_group_exit(SIGKILL);
3683 + }
3684 +#endif
3685 +
3686 goto bad_area;
3687 + }
3688
3689 /*
3690 * If for any reason at all we couldn't handle the fault, make
3691 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3692 index da29032..f76c24c 100644
3693 --- a/arch/powerpc/include/asm/atomic.h
3694 +++ b/arch/powerpc/include/asm/atomic.h
3695 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3696 return t1;
3697 }
3698
3699 +#define atomic64_read_unchecked(v) atomic64_read(v)
3700 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3701 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3702 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3703 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3704 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3705 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3706 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3707 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3708 +
3709 #endif /* __powerpc64__ */
3710
3711 #endif /* __KERNEL__ */
3712 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3713 index 9e495c9..b6878e5 100644
3714 --- a/arch/powerpc/include/asm/cache.h
3715 +++ b/arch/powerpc/include/asm/cache.h
3716 @@ -3,6 +3,7 @@
3717
3718 #ifdef __KERNEL__
3719
3720 +#include <linux/const.h>
3721
3722 /* bytes per L1 cache line */
3723 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3724 @@ -22,7 +23,7 @@
3725 #define L1_CACHE_SHIFT 7
3726 #endif
3727
3728 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3729 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3730
3731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3732
3733 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3734 index 3bf9cca..e7457d0 100644
3735 --- a/arch/powerpc/include/asm/elf.h
3736 +++ b/arch/powerpc/include/asm/elf.h
3737 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3738 the loader. We need to make sure that it is out of the way of the program
3739 that it will "exec", and that there is sufficient room for the brk. */
3740
3741 -extern unsigned long randomize_et_dyn(unsigned long base);
3742 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3743 +#define ELF_ET_DYN_BASE (0x20000000)
3744 +
3745 +#ifdef CONFIG_PAX_ASLR
3746 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3747 +
3748 +#ifdef __powerpc64__
3749 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3750 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3751 +#else
3752 +#define PAX_DELTA_MMAP_LEN 15
3753 +#define PAX_DELTA_STACK_LEN 15
3754 +#endif
3755 +#endif
3756
3757 /*
3758 * Our registers are always unsigned longs, whether we're a 32 bit
3759 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3760 (0x7ff >> (PAGE_SHIFT - 12)) : \
3761 (0x3ffff >> (PAGE_SHIFT - 12)))
3762
3763 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3764 -#define arch_randomize_brk arch_randomize_brk
3765 -
3766 #endif /* __KERNEL__ */
3767
3768 /*
3769 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3770 index 8196e9c..d83a9f3 100644
3771 --- a/arch/powerpc/include/asm/exec.h
3772 +++ b/arch/powerpc/include/asm/exec.h
3773 @@ -4,6 +4,6 @@
3774 #ifndef _ASM_POWERPC_EXEC_H
3775 #define _ASM_POWERPC_EXEC_H
3776
3777 -extern unsigned long arch_align_stack(unsigned long sp);
3778 +#define arch_align_stack(x) ((x) & ~0xfUL)
3779
3780 #endif /* _ASM_POWERPC_EXEC_H */
3781 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3782 index bca8fdc..61e9580 100644
3783 --- a/arch/powerpc/include/asm/kmap_types.h
3784 +++ b/arch/powerpc/include/asm/kmap_types.h
3785 @@ -27,6 +27,7 @@ enum km_type {
3786 KM_PPC_SYNC_PAGE,
3787 KM_PPC_SYNC_ICACHE,
3788 KM_KDB,
3789 + KM_CLEARPAGE,
3790 KM_TYPE_NR
3791 };
3792
3793 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3794 index d4a7f64..451de1c 100644
3795 --- a/arch/powerpc/include/asm/mman.h
3796 +++ b/arch/powerpc/include/asm/mman.h
3797 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3798 }
3799 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3800
3801 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3802 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3803 {
3804 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3805 }
3806 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3807 index f072e97..b436dee 100644
3808 --- a/arch/powerpc/include/asm/page.h
3809 +++ b/arch/powerpc/include/asm/page.h
3810 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3811 * and needs to be executable. This means the whole heap ends
3812 * up being executable.
3813 */
3814 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3815 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3816 +#define VM_DATA_DEFAULT_FLAGS32 \
3817 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3818 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3819
3820 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3821 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3822 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3823 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3824 #endif
3825
3826 +#define ktla_ktva(addr) (addr)
3827 +#define ktva_ktla(addr) (addr)
3828 +
3829 /*
3830 * Use the top bit of the higher-level page table entries to indicate whether
3831 * the entries we point to contain hugepages. This works because we know that
3832 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3833 index fed85e6..da5c71b 100644
3834 --- a/arch/powerpc/include/asm/page_64.h
3835 +++ b/arch/powerpc/include/asm/page_64.h
3836 @@ -146,15 +146,18 @@ do { \
3837 * stack by default, so in the absence of a PT_GNU_STACK program header
3838 * we turn execute permission off.
3839 */
3840 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3841 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3842 +#define VM_STACK_DEFAULT_FLAGS32 \
3843 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3844 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3845
3846 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3847 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848
3849 +#ifndef CONFIG_PAX_PAGEEXEC
3850 #define VM_STACK_DEFAULT_FLAGS \
3851 (is_32bit_task() ? \
3852 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3853 +#endif
3854
3855 #include <asm-generic/getorder.h>
3856
3857 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3858 index 292725c..f87ae14 100644
3859 --- a/arch/powerpc/include/asm/pgalloc-64.h
3860 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3861 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3862 #ifndef CONFIG_PPC_64K_PAGES
3863
3864 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3865 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3866
3867 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3868 {
3869 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3870 pud_set(pud, (unsigned long)pmd);
3871 }
3872
3873 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3874 +{
3875 + pud_populate(mm, pud, pmd);
3876 +}
3877 +
3878 #define pmd_populate(mm, pmd, pte_page) \
3879 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3880 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3881 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3882 #else /* CONFIG_PPC_64K_PAGES */
3883
3884 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3885 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3886
3887 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3888 pte_t *pte)
3889 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3890 index 2e0e411..7899c68 100644
3891 --- a/arch/powerpc/include/asm/pgtable.h
3892 +++ b/arch/powerpc/include/asm/pgtable.h
3893 @@ -2,6 +2,7 @@
3894 #define _ASM_POWERPC_PGTABLE_H
3895 #ifdef __KERNEL__
3896
3897 +#include <linux/const.h>
3898 #ifndef __ASSEMBLY__
3899 #include <asm/processor.h> /* For TASK_SIZE */
3900 #include <asm/mmu.h>
3901 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3902 index 4aad413..85d86bf 100644
3903 --- a/arch/powerpc/include/asm/pte-hash32.h
3904 +++ b/arch/powerpc/include/asm/pte-hash32.h
3905 @@ -21,6 +21,7 @@
3906 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3907 #define _PAGE_USER 0x004 /* usermode access allowed */
3908 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3909 +#define _PAGE_EXEC _PAGE_GUARDED
3910 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3911 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3912 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3913 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3914 index 9d7f0fb..a28fe69 100644
3915 --- a/arch/powerpc/include/asm/reg.h
3916 +++ b/arch/powerpc/include/asm/reg.h
3917 @@ -212,6 +212,7 @@
3918 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3919 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3920 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3921 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3922 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3923 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3924 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3925 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3926 index 4a741c7..c8162227b 100644
3927 --- a/arch/powerpc/include/asm/thread_info.h
3928 +++ b/arch/powerpc/include/asm/thread_info.h
3929 @@ -104,12 +104,14 @@ static inline struct thread_info *current_thread_info(void)
3930 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3931 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3932 #define TIF_SINGLESTEP 8 /* singlestepping active */
3933 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3934 #define TIF_SECCOMP 10 /* secure computing */
3935 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3936 #define TIF_NOERROR 12 /* Force successful syscall return */
3937 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3938 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3939 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3940 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3941 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3942
3943 /* as above, but as bit values */
3944 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3945 @@ -127,8 +129,11 @@ static inline struct thread_info *current_thread_info(void)
3946 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3947 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3948 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3949 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3950 +
3951 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3952 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3953 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3954 + _TIF_GRSEC_SETXID)
3955
3956 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3957 _TIF_NOTIFY_RESUME)
3958 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3959 index bd0fb84..a42a14b 100644
3960 --- a/arch/powerpc/include/asm/uaccess.h
3961 +++ b/arch/powerpc/include/asm/uaccess.h
3962 @@ -13,6 +13,8 @@
3963 #define VERIFY_READ 0
3964 #define VERIFY_WRITE 1
3965
3966 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3967 +
3968 /*
3969 * The fs value determines whether argument validity checking should be
3970 * performed or not. If get_fs() == USER_DS, checking is performed, with
3971 @@ -327,52 +329,6 @@ do { \
3972 extern unsigned long __copy_tofrom_user(void __user *to,
3973 const void __user *from, unsigned long size);
3974
3975 -#ifndef __powerpc64__
3976 -
3977 -static inline unsigned long copy_from_user(void *to,
3978 - const void __user *from, unsigned long n)
3979 -{
3980 - unsigned long over;
3981 -
3982 - if (access_ok(VERIFY_READ, from, n))
3983 - return __copy_tofrom_user((__force void __user *)to, from, n);
3984 - if ((unsigned long)from < TASK_SIZE) {
3985 - over = (unsigned long)from + n - TASK_SIZE;
3986 - return __copy_tofrom_user((__force void __user *)to, from,
3987 - n - over) + over;
3988 - }
3989 - return n;
3990 -}
3991 -
3992 -static inline unsigned long copy_to_user(void __user *to,
3993 - const void *from, unsigned long n)
3994 -{
3995 - unsigned long over;
3996 -
3997 - if (access_ok(VERIFY_WRITE, to, n))
3998 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3999 - if ((unsigned long)to < TASK_SIZE) {
4000 - over = (unsigned long)to + n - TASK_SIZE;
4001 - return __copy_tofrom_user(to, (__force void __user *)from,
4002 - n - over) + over;
4003 - }
4004 - return n;
4005 -}
4006 -
4007 -#else /* __powerpc64__ */
4008 -
4009 -#define __copy_in_user(to, from, size) \
4010 - __copy_tofrom_user((to), (from), (size))
4011 -
4012 -extern unsigned long copy_from_user(void *to, const void __user *from,
4013 - unsigned long n);
4014 -extern unsigned long copy_to_user(void __user *to, const void *from,
4015 - unsigned long n);
4016 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4017 - unsigned long n);
4018 -
4019 -#endif /* __powerpc64__ */
4020 -
4021 static inline unsigned long __copy_from_user_inatomic(void *to,
4022 const void __user *from, unsigned long n)
4023 {
4024 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4025 if (ret == 0)
4026 return 0;
4027 }
4028 +
4029 + if (!__builtin_constant_p(n))
4030 + check_object_size(to, n, false);
4031 +
4032 return __copy_tofrom_user((__force void __user *)to, from, n);
4033 }
4034
4035 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4036 if (ret == 0)
4037 return 0;
4038 }
4039 +
4040 + if (!__builtin_constant_p(n))
4041 + check_object_size(from, n, true);
4042 +
4043 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4044 }
4045
4046 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4047 return __copy_to_user_inatomic(to, from, size);
4048 }
4049
4050 +#ifndef __powerpc64__
4051 +
4052 +static inline unsigned long __must_check copy_from_user(void *to,
4053 + const void __user *from, unsigned long n)
4054 +{
4055 + unsigned long over;
4056 +
4057 + if ((long)n < 0)
4058 + return n;
4059 +
4060 + if (access_ok(VERIFY_READ, from, n)) {
4061 + if (!__builtin_constant_p(n))
4062 + check_object_size(to, n, false);
4063 + return __copy_tofrom_user((__force void __user *)to, from, n);
4064 + }
4065 + if ((unsigned long)from < TASK_SIZE) {
4066 + over = (unsigned long)from + n - TASK_SIZE;
4067 + if (!__builtin_constant_p(n - over))
4068 + check_object_size(to, n - over, false);
4069 + return __copy_tofrom_user((__force void __user *)to, from,
4070 + n - over) + over;
4071 + }
4072 + return n;
4073 +}
4074 +
4075 +static inline unsigned long __must_check copy_to_user(void __user *to,
4076 + const void *from, unsigned long n)
4077 +{
4078 + unsigned long over;
4079 +
4080 + if ((long)n < 0)
4081 + return n;
4082 +
4083 + if (access_ok(VERIFY_WRITE, to, n)) {
4084 + if (!__builtin_constant_p(n))
4085 + check_object_size(from, n, true);
4086 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4087 + }
4088 + if ((unsigned long)to < TASK_SIZE) {
4089 + over = (unsigned long)to + n - TASK_SIZE;
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n - over, true);
4092 + return __copy_tofrom_user(to, (__force void __user *)from,
4093 + n - over) + over;
4094 + }
4095 + return n;
4096 +}
4097 +
4098 +#else /* __powerpc64__ */
4099 +
4100 +#define __copy_in_user(to, from, size) \
4101 + __copy_tofrom_user((to), (from), (size))
4102 +
4103 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4104 +{
4105 + if ((long)n < 0 || n > INT_MAX)
4106 + return n;
4107 +
4108 + if (!__builtin_constant_p(n))
4109 + check_object_size(to, n, false);
4110 +
4111 + if (likely(access_ok(VERIFY_READ, from, n)))
4112 + n = __copy_from_user(to, from, n);
4113 + else
4114 + memset(to, 0, n);
4115 + return n;
4116 +}
4117 +
4118 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4119 +{
4120 + if ((long)n < 0 || n > INT_MAX)
4121 + return n;
4122 +
4123 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4124 + if (!__builtin_constant_p(n))
4125 + check_object_size(from, n, true);
4126 + n = __copy_to_user(to, from, n);
4127 + }
4128 + return n;
4129 +}
4130 +
4131 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4132 + unsigned long n);
4133 +
4134 +#endif /* __powerpc64__ */
4135 +
4136 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4137
4138 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4139 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4140 index 7215cc2..a9730c1 100644
4141 --- a/arch/powerpc/kernel/exceptions-64e.S
4142 +++ b/arch/powerpc/kernel/exceptions-64e.S
4143 @@ -661,6 +661,7 @@ storage_fault_common:
4144 std r14,_DAR(r1)
4145 std r15,_DSISR(r1)
4146 addi r3,r1,STACK_FRAME_OVERHEAD
4147 + bl .save_nvgprs
4148 mr r4,r14
4149 mr r5,r15
4150 ld r14,PACA_EXGEN+EX_R14(r13)
4151 @@ -669,8 +670,7 @@ storage_fault_common:
4152 cmpdi r3,0
4153 bne- 1f
4154 b .ret_from_except_lite
4155 -1: bl .save_nvgprs
4156 - mr r5,r3
4157 +1: mr r5,r3
4158 addi r3,r1,STACK_FRAME_OVERHEAD
4159 ld r4,_DAR(r1)
4160 bl .bad_page_fault
4161 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4162 index 8f880bc..c5bd2f3 100644
4163 --- a/arch/powerpc/kernel/exceptions-64s.S
4164 +++ b/arch/powerpc/kernel/exceptions-64s.S
4165 @@ -890,10 +890,10 @@ handle_page_fault:
4166 11: ld r4,_DAR(r1)
4167 ld r5,_DSISR(r1)
4168 addi r3,r1,STACK_FRAME_OVERHEAD
4169 + bl .save_nvgprs
4170 bl .do_page_fault
4171 cmpdi r3,0
4172 beq+ 12f
4173 - bl .save_nvgprs
4174 mr r5,r3
4175 addi r3,r1,STACK_FRAME_OVERHEAD
4176 lwz r4,_DAR(r1)
4177 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4178 index 2e3200c..72095ce 100644
4179 --- a/arch/powerpc/kernel/module_32.c
4180 +++ b/arch/powerpc/kernel/module_32.c
4181 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4182 me->arch.core_plt_section = i;
4183 }
4184 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4185 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4186 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4187 return -ENOEXEC;
4188 }
4189
4190 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4191
4192 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4193 /* Init, or core PLT? */
4194 - if (location >= mod->module_core
4195 - && location < mod->module_core + mod->core_size)
4196 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4197 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4198 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4199 - else
4200 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4201 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4202 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4203 + else {
4204 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4205 + return ~0UL;
4206 + }
4207
4208 /* Find this entry, or if that fails, the next avail. entry */
4209 while (entry->jump[0]) {
4210 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4211 index 4937c96..70714b7 100644
4212 --- a/arch/powerpc/kernel/process.c
4213 +++ b/arch/powerpc/kernel/process.c
4214 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4215 * Lookup NIP late so we have the best change of getting the
4216 * above info out without failing
4217 */
4218 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4219 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4220 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4221 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4222 #endif
4223 show_stack(current, (unsigned long *) regs->gpr[1]);
4224 if (!user_mode(regs))
4225 @@ -1186,10 +1186,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4226 newsp = stack[0];
4227 ip = stack[STACK_FRAME_LR_SAVE];
4228 if (!firstframe || ip != lr) {
4229 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4230 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4231 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4232 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4233 - printk(" (%pS)",
4234 + printk(" (%pA)",
4235 (void *)current->ret_stack[curr_frame].ret);
4236 curr_frame--;
4237 }
4238 @@ -1209,7 +1209,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4239 struct pt_regs *regs = (struct pt_regs *)
4240 (sp + STACK_FRAME_OVERHEAD);
4241 lr = regs->link;
4242 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4243 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4244 regs->trap, (void *)regs->nip, (void *)lr);
4245 firstframe = 1;
4246 }
4247 @@ -1282,58 +1282,3 @@ void thread_info_cache_init(void)
4248 }
4249
4250 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4251 -
4252 -unsigned long arch_align_stack(unsigned long sp)
4253 -{
4254 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4255 - sp -= get_random_int() & ~PAGE_MASK;
4256 - return sp & ~0xf;
4257 -}
4258 -
4259 -static inline unsigned long brk_rnd(void)
4260 -{
4261 - unsigned long rnd = 0;
4262 -
4263 - /* 8MB for 32bit, 1GB for 64bit */
4264 - if (is_32bit_task())
4265 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4266 - else
4267 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4268 -
4269 - return rnd << PAGE_SHIFT;
4270 -}
4271 -
4272 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4273 -{
4274 - unsigned long base = mm->brk;
4275 - unsigned long ret;
4276 -
4277 -#ifdef CONFIG_PPC_STD_MMU_64
4278 - /*
4279 - * If we are using 1TB segments and we are allowed to randomise
4280 - * the heap, we can put it above 1TB so it is backed by a 1TB
4281 - * segment. Otherwise the heap will be in the bottom 1TB
4282 - * which always uses 256MB segments and this may result in a
4283 - * performance penalty.
4284 - */
4285 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4286 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4287 -#endif
4288 -
4289 - ret = PAGE_ALIGN(base + brk_rnd());
4290 -
4291 - if (ret < mm->brk)
4292 - return mm->brk;
4293 -
4294 - return ret;
4295 -}
4296 -
4297 -unsigned long randomize_et_dyn(unsigned long base)
4298 -{
4299 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4300 -
4301 - if (ret < base)
4302 - return base;
4303 -
4304 - return ret;
4305 -}
4306 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4307 index 8d8e028..c2aeb50 100644
4308 --- a/arch/powerpc/kernel/ptrace.c
4309 +++ b/arch/powerpc/kernel/ptrace.c
4310 @@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4311 return ret;
4312 }
4313
4314 +#ifdef CONFIG_GRKERNSEC_SETXID
4315 +extern void gr_delayed_cred_worker(void);
4316 +#endif
4317 +
4318 /*
4319 * We must return the syscall number to actually look up in the table.
4320 * This can be -1L to skip running any syscall at all.
4321 @@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4322
4323 secure_computing(regs->gpr[0]);
4324
4325 +#ifdef CONFIG_GRKERNSEC_SETXID
4326 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4327 + gr_delayed_cred_worker();
4328 +#endif
4329 +
4330 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4331 tracehook_report_syscall_entry(regs))
4332 /*
4333 @@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4334 {
4335 int step;
4336
4337 +#ifdef CONFIG_GRKERNSEC_SETXID
4338 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4339 + gr_delayed_cred_worker();
4340 +#endif
4341 +
4342 audit_syscall_exit(regs);
4343
4344 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4345 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4346 index 45eb998..0cb36bc 100644
4347 --- a/arch/powerpc/kernel/signal_32.c
4348 +++ b/arch/powerpc/kernel/signal_32.c
4349 @@ -861,7 +861,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4350 /* Save user registers on the stack */
4351 frame = &rt_sf->uc.uc_mcontext;
4352 addr = frame;
4353 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4354 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4355 if (save_user_regs(regs, frame, 0, 1))
4356 goto badframe;
4357 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4358 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4359 index 2692efd..6673d2e 100644
4360 --- a/arch/powerpc/kernel/signal_64.c
4361 +++ b/arch/powerpc/kernel/signal_64.c
4362 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4363 current->thread.fpscr.val = 0;
4364
4365 /* Set up to return from userspace. */
4366 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4367 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4368 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4369 } else {
4370 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4371 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4372 index 1589723..cefe690 100644
4373 --- a/arch/powerpc/kernel/traps.c
4374 +++ b/arch/powerpc/kernel/traps.c
4375 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4376 return flags;
4377 }
4378
4379 +extern void gr_handle_kernel_exploit(void);
4380 +
4381 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4382 int signr)
4383 {
4384 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4385 panic("Fatal exception in interrupt");
4386 if (panic_on_oops)
4387 panic("Fatal exception");
4388 +
4389 + gr_handle_kernel_exploit();
4390 +
4391 do_exit(signr);
4392 }
4393
4394 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4395 index 9eb5b9b..e45498a 100644
4396 --- a/arch/powerpc/kernel/vdso.c
4397 +++ b/arch/powerpc/kernel/vdso.c
4398 @@ -34,6 +34,7 @@
4399 #include <asm/firmware.h>
4400 #include <asm/vdso.h>
4401 #include <asm/vdso_datapage.h>
4402 +#include <asm/mman.h>
4403
4404 #include "setup.h"
4405
4406 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4407 vdso_base = VDSO32_MBASE;
4408 #endif
4409
4410 - current->mm->context.vdso_base = 0;
4411 + current->mm->context.vdso_base = ~0UL;
4412
4413 /* vDSO has a problem and was disabled, just don't "enable" it for the
4414 * process
4415 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4416 vdso_base = get_unmapped_area(NULL, vdso_base,
4417 (vdso_pages << PAGE_SHIFT) +
4418 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4419 - 0, 0);
4420 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4421 if (IS_ERR_VALUE(vdso_base)) {
4422 rc = vdso_base;
4423 goto fail_mmapsem;
4424 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4425 index 5eea6f3..5d10396 100644
4426 --- a/arch/powerpc/lib/usercopy_64.c
4427 +++ b/arch/powerpc/lib/usercopy_64.c
4428 @@ -9,22 +9,6 @@
4429 #include <linux/module.h>
4430 #include <asm/uaccess.h>
4431
4432 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4433 -{
4434 - if (likely(access_ok(VERIFY_READ, from, n)))
4435 - n = __copy_from_user(to, from, n);
4436 - else
4437 - memset(to, 0, n);
4438 - return n;
4439 -}
4440 -
4441 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4442 -{
4443 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4444 - n = __copy_to_user(to, from, n);
4445 - return n;
4446 -}
4447 -
4448 unsigned long copy_in_user(void __user *to, const void __user *from,
4449 unsigned long n)
4450 {
4451 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4452 return n;
4453 }
4454
4455 -EXPORT_SYMBOL(copy_from_user);
4456 -EXPORT_SYMBOL(copy_to_user);
4457 EXPORT_SYMBOL(copy_in_user);
4458
4459 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4460 index 08ffcf5..a0ab912 100644
4461 --- a/arch/powerpc/mm/fault.c
4462 +++ b/arch/powerpc/mm/fault.c
4463 @@ -32,6 +32,10 @@
4464 #include <linux/perf_event.h>
4465 #include <linux/magic.h>
4466 #include <linux/ratelimit.h>
4467 +#include <linux/slab.h>
4468 +#include <linux/pagemap.h>
4469 +#include <linux/compiler.h>
4470 +#include <linux/unistd.h>
4471
4472 #include <asm/firmware.h>
4473 #include <asm/page.h>
4474 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4475 }
4476 #endif
4477
4478 +#ifdef CONFIG_PAX_PAGEEXEC
4479 +/*
4480 + * PaX: decide what to do with offenders (regs->nip = fault address)
4481 + *
4482 + * returns 1 when task should be killed
4483 + */
4484 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4485 +{
4486 + return 1;
4487 +}
4488 +
4489 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4490 +{
4491 + unsigned long i;
4492 +
4493 + printk(KERN_ERR "PAX: bytes at PC: ");
4494 + for (i = 0; i < 5; i++) {
4495 + unsigned int c;
4496 + if (get_user(c, (unsigned int __user *)pc+i))
4497 + printk(KERN_CONT "???????? ");
4498 + else
4499 + printk(KERN_CONT "%08x ", c);
4500 + }
4501 + printk("\n");
4502 +}
4503 +#endif
4504 +
4505 /*
4506 * Check whether the instruction at regs->nip is a store using
4507 * an update addressing form which will update r1.
4508 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4509 * indicate errors in DSISR but can validly be set in SRR1.
4510 */
4511 if (trap == 0x400)
4512 - error_code &= 0x48200000;
4513 + error_code &= 0x58200000;
4514 else
4515 is_write = error_code & DSISR_ISSTORE;
4516 #else
4517 @@ -366,7 +397,7 @@ good_area:
4518 * "undefined". Of those that can be set, this is the only
4519 * one which seems bad.
4520 */
4521 - if (error_code & 0x10000000)
4522 + if (error_code & DSISR_GUARDED)
4523 /* Guarded storage error. */
4524 goto bad_area;
4525 #endif /* CONFIG_8xx */
4526 @@ -381,7 +412,7 @@ good_area:
4527 * processors use the same I/D cache coherency mechanism
4528 * as embedded.
4529 */
4530 - if (error_code & DSISR_PROTFAULT)
4531 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4532 goto bad_area;
4533 #endif /* CONFIG_PPC_STD_MMU */
4534
4535 @@ -463,6 +494,23 @@ bad_area:
4536 bad_area_nosemaphore:
4537 /* User mode accesses cause a SIGSEGV */
4538 if (user_mode(regs)) {
4539 +
4540 +#ifdef CONFIG_PAX_PAGEEXEC
4541 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4542 +#ifdef CONFIG_PPC_STD_MMU
4543 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4544 +#else
4545 + if (is_exec && regs->nip == address) {
4546 +#endif
4547 + switch (pax_handle_fetch_fault(regs)) {
4548 + }
4549 +
4550 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4551 + do_group_exit(SIGKILL);
4552 + }
4553 + }
4554 +#endif
4555 +
4556 _exception(SIGSEGV, regs, code, address);
4557 return 0;
4558 }
4559 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4560 index 67a42ed..1c7210c 100644
4561 --- a/arch/powerpc/mm/mmap_64.c
4562 +++ b/arch/powerpc/mm/mmap_64.c
4563 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4564 */
4565 if (mmap_is_legacy()) {
4566 mm->mmap_base = TASK_UNMAPPED_BASE;
4567 +
4568 +#ifdef CONFIG_PAX_RANDMMAP
4569 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4570 + mm->mmap_base += mm->delta_mmap;
4571 +#endif
4572 +
4573 mm->get_unmapped_area = arch_get_unmapped_area;
4574 mm->unmap_area = arch_unmap_area;
4575 } else {
4576 mm->mmap_base = mmap_base();
4577 +
4578 +#ifdef CONFIG_PAX_RANDMMAP
4579 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4580 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4581 +#endif
4582 +
4583 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4584 mm->unmap_area = arch_unmap_area_topdown;
4585 }
4586 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4587 index 73709f7..6b90313 100644
4588 --- a/arch/powerpc/mm/slice.c
4589 +++ b/arch/powerpc/mm/slice.c
4590 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4591 if ((mm->task_size - len) < addr)
4592 return 0;
4593 vma = find_vma(mm, addr);
4594 - return (!vma || (addr + len) <= vma->vm_start);
4595 + return check_heap_stack_gap(vma, addr, len);
4596 }
4597
4598 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4599 @@ -256,7 +256,7 @@ full_search:
4600 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4601 continue;
4602 }
4603 - if (!vma || addr + len <= vma->vm_start) {
4604 + if (check_heap_stack_gap(vma, addr, len)) {
4605 /*
4606 * Remember the place where we stopped the search:
4607 */
4608 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4609 }
4610 }
4611
4612 - addr = mm->mmap_base;
4613 - while (addr > len) {
4614 + if (mm->mmap_base < len)
4615 + addr = -ENOMEM;
4616 + else
4617 + addr = mm->mmap_base - len;
4618 +
4619 + while (!IS_ERR_VALUE(addr)) {
4620 /* Go down by chunk size */
4621 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4622 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4623
4624 /* Check for hit with different page size */
4625 mask = slice_range_to_mask(addr, len);
4626 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4627 * return with success:
4628 */
4629 vma = find_vma(mm, addr);
4630 - if (!vma || (addr + len) <= vma->vm_start) {
4631 + if (check_heap_stack_gap(vma, addr, len)) {
4632 /* remember the address as a hint for next time */
4633 if (use_cache)
4634 mm->free_area_cache = addr;
4635 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4636 mm->cached_hole_size = vma->vm_start - addr;
4637
4638 /* try just below the current vma->vm_start */
4639 - addr = vma->vm_start;
4640 + addr = skip_heap_stack_gap(vma, len);
4641 }
4642
4643 /*
4644 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4645 if (fixed && addr > (mm->task_size - len))
4646 return -EINVAL;
4647
4648 +#ifdef CONFIG_PAX_RANDMMAP
4649 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4650 + addr = 0;
4651 +#endif
4652 +
4653 /* If hint, make sure it matches our alignment restrictions */
4654 if (!fixed && addr) {
4655 addr = _ALIGN_UP(addr, 1ul << pshift);
4656 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4657 index 748347b..81bc6c7 100644
4658 --- a/arch/s390/include/asm/atomic.h
4659 +++ b/arch/s390/include/asm/atomic.h
4660 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4661 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4663
4664 +#define atomic64_read_unchecked(v) atomic64_read(v)
4665 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4666 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4667 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4668 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4669 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4670 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4671 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4672 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4673 +
4674 #define smp_mb__before_atomic_dec() smp_mb()
4675 #define smp_mb__after_atomic_dec() smp_mb()
4676 #define smp_mb__before_atomic_inc() smp_mb()
4677 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4678 index 2a30d5a..5e5586f 100644
4679 --- a/arch/s390/include/asm/cache.h
4680 +++ b/arch/s390/include/asm/cache.h
4681 @@ -11,8 +11,10 @@
4682 #ifndef __ARCH_S390_CACHE_H
4683 #define __ARCH_S390_CACHE_H
4684
4685 -#define L1_CACHE_BYTES 256
4686 +#include <linux/const.h>
4687 +
4688 #define L1_CACHE_SHIFT 8
4689 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4690 #define NET_SKB_PAD 32
4691
4692 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4693 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4694 index c4ee39f..352881b 100644
4695 --- a/arch/s390/include/asm/elf.h
4696 +++ b/arch/s390/include/asm/elf.h
4697 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4698 the loader. We need to make sure that it is out of the way of the program
4699 that it will "exec", and that there is sufficient room for the brk. */
4700
4701 -extern unsigned long randomize_et_dyn(unsigned long base);
4702 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4703 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4704 +
4705 +#ifdef CONFIG_PAX_ASLR
4706 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4707 +
4708 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4709 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#endif
4711
4712 /* This yields a mask that user programs can use to figure out what
4713 instruction set this CPU supports. */
4714 @@ -210,7 +216,4 @@ struct linux_binprm;
4715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4716 int arch_setup_additional_pages(struct linux_binprm *, int);
4717
4718 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4719 -#define arch_randomize_brk arch_randomize_brk
4720 -
4721 #endif
4722 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4723 index c4a93d6..4d2a9b4 100644
4724 --- a/arch/s390/include/asm/exec.h
4725 +++ b/arch/s390/include/asm/exec.h
4726 @@ -7,6 +7,6 @@
4727 #ifndef __ASM_EXEC_H
4728 #define __ASM_EXEC_H
4729
4730 -extern unsigned long arch_align_stack(unsigned long sp);
4731 +#define arch_align_stack(x) ((x) & ~0xfUL)
4732
4733 #endif /* __ASM_EXEC_H */
4734 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4735 index 8f2cada..43072c1 100644
4736 --- a/arch/s390/include/asm/uaccess.h
4737 +++ b/arch/s390/include/asm/uaccess.h
4738 @@ -236,6 +236,10 @@ static inline unsigned long __must_check
4739 copy_to_user(void __user *to, const void *from, unsigned long n)
4740 {
4741 might_fault();
4742 +
4743 + if ((long)n < 0)
4744 + return n;
4745 +
4746 if (access_ok(VERIFY_WRITE, to, n))
4747 n = __copy_to_user(to, from, n);
4748 return n;
4749 @@ -261,6 +265,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4750 static inline unsigned long __must_check
4751 __copy_from_user(void *to, const void __user *from, unsigned long n)
4752 {
4753 + if ((long)n < 0)
4754 + return n;
4755 +
4756 if (__builtin_constant_p(n) && (n <= 256))
4757 return uaccess.copy_from_user_small(n, from, to);
4758 else
4759 @@ -292,10 +299,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4760 static inline unsigned long __must_check
4761 copy_from_user(void *to, const void __user *from, unsigned long n)
4762 {
4763 - unsigned int sz = __compiletime_object_size(to);
4764 + size_t sz = __compiletime_object_size(to);
4765
4766 might_fault();
4767 - if (unlikely(sz != -1 && sz < n)) {
4768 +
4769 + if ((long)n < 0)
4770 + return n;
4771 +
4772 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4773 copy_from_user_overflow();
4774 return n;
4775 }
4776 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4777 index dfcb343..eda788a 100644
4778 --- a/arch/s390/kernel/module.c
4779 +++ b/arch/s390/kernel/module.c
4780 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4781
4782 /* Increase core size by size of got & plt and set start
4783 offsets for got and plt. */
4784 - me->core_size = ALIGN(me->core_size, 4);
4785 - me->arch.got_offset = me->core_size;
4786 - me->core_size += me->arch.got_size;
4787 - me->arch.plt_offset = me->core_size;
4788 - me->core_size += me->arch.plt_size;
4789 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4790 + me->arch.got_offset = me->core_size_rw;
4791 + me->core_size_rw += me->arch.got_size;
4792 + me->arch.plt_offset = me->core_size_rx;
4793 + me->core_size_rx += me->arch.plt_size;
4794 return 0;
4795 }
4796
4797 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4798 if (info->got_initialized == 0) {
4799 Elf_Addr *gotent;
4800
4801 - gotent = me->module_core + me->arch.got_offset +
4802 + gotent = me->module_core_rw + me->arch.got_offset +
4803 info->got_offset;
4804 *gotent = val;
4805 info->got_initialized = 1;
4806 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4807 else if (r_type == R_390_GOTENT ||
4808 r_type == R_390_GOTPLTENT)
4809 *(unsigned int *) loc =
4810 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4811 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4812 else if (r_type == R_390_GOT64 ||
4813 r_type == R_390_GOTPLT64)
4814 *(unsigned long *) loc = val;
4815 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4816 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4817 if (info->plt_initialized == 0) {
4818 unsigned int *ip;
4819 - ip = me->module_core + me->arch.plt_offset +
4820 + ip = me->module_core_rx + me->arch.plt_offset +
4821 info->plt_offset;
4822 #ifndef CONFIG_64BIT
4823 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4824 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4825 val - loc + 0xffffUL < 0x1ffffeUL) ||
4826 (r_type == R_390_PLT32DBL &&
4827 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4828 - val = (Elf_Addr) me->module_core +
4829 + val = (Elf_Addr) me->module_core_rx +
4830 me->arch.plt_offset +
4831 info->plt_offset;
4832 val += rela->r_addend - loc;
4833 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4835 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4836 val = val + rela->r_addend -
4837 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4838 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4839 if (r_type == R_390_GOTOFF16)
4840 *(unsigned short *) loc = val;
4841 else if (r_type == R_390_GOTOFF32)
4842 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 break;
4844 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4845 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4846 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4847 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4848 rela->r_addend - loc;
4849 if (r_type == R_390_GOTPC)
4850 *(unsigned int *) loc = val;
4851 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4852 index 60055ce..ee4b252 100644
4853 --- a/arch/s390/kernel/process.c
4854 +++ b/arch/s390/kernel/process.c
4855 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4856 }
4857 return 0;
4858 }
4859 -
4860 -unsigned long arch_align_stack(unsigned long sp)
4861 -{
4862 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4863 - sp -= get_random_int() & ~PAGE_MASK;
4864 - return sp & ~0xf;
4865 -}
4866 -
4867 -static inline unsigned long brk_rnd(void)
4868 -{
4869 - /* 8MB for 32bit, 1GB for 64bit */
4870 - if (is_32bit_task())
4871 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4872 - else
4873 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4874 -}
4875 -
4876 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4877 -{
4878 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4879 -
4880 - if (ret < mm->brk)
4881 - return mm->brk;
4882 - return ret;
4883 -}
4884 -
4885 -unsigned long randomize_et_dyn(unsigned long base)
4886 -{
4887 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4888 -
4889 - if (!(current->flags & PF_RANDOMIZE))
4890 - return base;
4891 - if (ret < base)
4892 - return base;
4893 - return ret;
4894 -}
4895 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4896 index 2857c48..d047481 100644
4897 --- a/arch/s390/mm/mmap.c
4898 +++ b/arch/s390/mm/mmap.c
4899 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4900 */
4901 if (mmap_is_legacy()) {
4902 mm->mmap_base = TASK_UNMAPPED_BASE;
4903 +
4904 +#ifdef CONFIG_PAX_RANDMMAP
4905 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4906 + mm->mmap_base += mm->delta_mmap;
4907 +#endif
4908 +
4909 mm->get_unmapped_area = arch_get_unmapped_area;
4910 mm->unmap_area = arch_unmap_area;
4911 } else {
4912 mm->mmap_base = mmap_base();
4913 +
4914 +#ifdef CONFIG_PAX_RANDMMAP
4915 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4916 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4917 +#endif
4918 +
4919 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4920 mm->unmap_area = arch_unmap_area_topdown;
4921 }
4922 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4923 */
4924 if (mmap_is_legacy()) {
4925 mm->mmap_base = TASK_UNMAPPED_BASE;
4926 +
4927 +#ifdef CONFIG_PAX_RANDMMAP
4928 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4929 + mm->mmap_base += mm->delta_mmap;
4930 +#endif
4931 +
4932 mm->get_unmapped_area = s390_get_unmapped_area;
4933 mm->unmap_area = arch_unmap_area;
4934 } else {
4935 mm->mmap_base = mmap_base();
4936 +
4937 +#ifdef CONFIG_PAX_RANDMMAP
4938 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4939 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4940 +#endif
4941 +
4942 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4943 mm->unmap_area = arch_unmap_area_topdown;
4944 }
4945 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4946 index ae3d59f..f65f075 100644
4947 --- a/arch/score/include/asm/cache.h
4948 +++ b/arch/score/include/asm/cache.h
4949 @@ -1,7 +1,9 @@
4950 #ifndef _ASM_SCORE_CACHE_H
4951 #define _ASM_SCORE_CACHE_H
4952
4953 +#include <linux/const.h>
4954 +
4955 #define L1_CACHE_SHIFT 4
4956 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4957 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4958
4959 #endif /* _ASM_SCORE_CACHE_H */
4960 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4961 index f9f3cd5..58ff438 100644
4962 --- a/arch/score/include/asm/exec.h
4963 +++ b/arch/score/include/asm/exec.h
4964 @@ -1,6 +1,6 @@
4965 #ifndef _ASM_SCORE_EXEC_H
4966 #define _ASM_SCORE_EXEC_H
4967
4968 -extern unsigned long arch_align_stack(unsigned long sp);
4969 +#define arch_align_stack(x) (x)
4970
4971 #endif /* _ASM_SCORE_EXEC_H */
4972 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4973 index 2707023..1c2a3b7 100644
4974 --- a/arch/score/kernel/process.c
4975 +++ b/arch/score/kernel/process.c
4976 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4977
4978 return task_pt_regs(task)->cp0_epc;
4979 }
4980 -
4981 -unsigned long arch_align_stack(unsigned long sp)
4982 -{
4983 - return sp;
4984 -}
4985 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4986 index ef9e555..331bd29 100644
4987 --- a/arch/sh/include/asm/cache.h
4988 +++ b/arch/sh/include/asm/cache.h
4989 @@ -9,10 +9,11 @@
4990 #define __ASM_SH_CACHE_H
4991 #ifdef __KERNEL__
4992
4993 +#include <linux/const.h>
4994 #include <linux/init.h>
4995 #include <cpu/cache.h>
4996
4997 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4998 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4999
5000 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5001
5002 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5003 index afeb710..d1d1289 100644
5004 --- a/arch/sh/mm/mmap.c
5005 +++ b/arch/sh/mm/mmap.c
5006 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5007 addr = PAGE_ALIGN(addr);
5008
5009 vma = find_vma(mm, addr);
5010 - if (TASK_SIZE - len >= addr &&
5011 - (!vma || addr + len <= vma->vm_start))
5012 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5013 return addr;
5014 }
5015
5016 @@ -106,7 +105,7 @@ full_search:
5017 }
5018 return -ENOMEM;
5019 }
5020 - if (likely(!vma || addr + len <= vma->vm_start)) {
5021 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5022 /*
5023 * Remember the place where we stopped the search:
5024 */
5025 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5026 addr = PAGE_ALIGN(addr);
5027
5028 vma = find_vma(mm, addr);
5029 - if (TASK_SIZE - len >= addr &&
5030 - (!vma || addr + len <= vma->vm_start))
5031 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5032 return addr;
5033 }
5034
5035 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5036 /* make sure it can fit in the remaining address space */
5037 if (likely(addr > len)) {
5038 vma = find_vma(mm, addr-len);
5039 - if (!vma || addr <= vma->vm_start) {
5040 + if (check_heap_stack_gap(vma, addr - len, len)) {
5041 /* remember the address as a hint for next time */
5042 return (mm->free_area_cache = addr-len);
5043 }
5044 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5045 if (unlikely(mm->mmap_base < len))
5046 goto bottomup;
5047
5048 - addr = mm->mmap_base-len;
5049 - if (do_colour_align)
5050 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5051 + addr = mm->mmap_base - len;
5052
5053 do {
5054 + if (do_colour_align)
5055 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5056 /*
5057 * Lookup failure means no vma is above this address,
5058 * else if new region fits below vma->vm_start,
5059 * return with success:
5060 */
5061 vma = find_vma(mm, addr);
5062 - if (likely(!vma || addr+len <= vma->vm_start)) {
5063 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5064 /* remember the address as a hint for next time */
5065 return (mm->free_area_cache = addr);
5066 }
5067 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5068 mm->cached_hole_size = vma->vm_start - addr;
5069
5070 /* try just below the current vma->vm_start */
5071 - addr = vma->vm_start-len;
5072 - if (do_colour_align)
5073 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5074 - } while (likely(len < vma->vm_start));
5075 + addr = skip_heap_stack_gap(vma, len);
5076 + } while (!IS_ERR_VALUE(addr));
5077
5078 bottomup:
5079 /*
5080 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5081 index eddcfb3..b117d90 100644
5082 --- a/arch/sparc/Makefile
5083 +++ b/arch/sparc/Makefile
5084 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5085 # Export what is needed by arch/sparc/boot/Makefile
5086 export VMLINUX_INIT VMLINUX_MAIN
5087 VMLINUX_INIT := $(head-y) $(init-y)
5088 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5089 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5090 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5091 VMLINUX_MAIN += $(drivers-y) $(net-y)
5092
5093 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5094 index ce35a1c..2e7b8f9 100644
5095 --- a/arch/sparc/include/asm/atomic_64.h
5096 +++ b/arch/sparc/include/asm/atomic_64.h
5097 @@ -14,18 +14,40 @@
5098 #define ATOMIC64_INIT(i) { (i) }
5099
5100 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5101 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5102 +{
5103 + return v->counter;
5104 +}
5105 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5106 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5107 +{
5108 + return v->counter;
5109 +}
5110
5111 #define atomic_set(v, i) (((v)->counter) = i)
5112 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5113 +{
5114 + v->counter = i;
5115 +}
5116 #define atomic64_set(v, i) (((v)->counter) = i)
5117 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5118 +{
5119 + v->counter = i;
5120 +}
5121
5122 extern void atomic_add(int, atomic_t *);
5123 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5124 extern void atomic64_add(long, atomic64_t *);
5125 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5126 extern void atomic_sub(int, atomic_t *);
5127 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5128 extern void atomic64_sub(long, atomic64_t *);
5129 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5130
5131 extern int atomic_add_ret(int, atomic_t *);
5132 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5133 extern long atomic64_add_ret(long, atomic64_t *);
5134 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5135 extern int atomic_sub_ret(int, atomic_t *);
5136 extern long atomic64_sub_ret(long, atomic64_t *);
5137
5138 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5139 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5140
5141 #define atomic_inc_return(v) atomic_add_ret(1, v)
5142 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5143 +{
5144 + return atomic_add_ret_unchecked(1, v);
5145 +}
5146 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5147 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5148 +{
5149 + return atomic64_add_ret_unchecked(1, v);
5150 +}
5151
5152 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5153 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5154
5155 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5156 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5157 +{
5158 + return atomic_add_ret_unchecked(i, v);
5159 +}
5160 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5161 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5162 +{
5163 + return atomic64_add_ret_unchecked(i, v);
5164 +}
5165
5166 /*
5167 * atomic_inc_and_test - increment and test
5168 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5169 * other cases.
5170 */
5171 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5172 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5173 +{
5174 + return atomic_inc_return_unchecked(v) == 0;
5175 +}
5176 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5177
5178 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5179 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5180 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5181
5182 #define atomic_inc(v) atomic_add(1, v)
5183 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5184 +{
5185 + atomic_add_unchecked(1, v);
5186 +}
5187 #define atomic64_inc(v) atomic64_add(1, v)
5188 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5189 +{
5190 + atomic64_add_unchecked(1, v);
5191 +}
5192
5193 #define atomic_dec(v) atomic_sub(1, v)
5194 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5195 +{
5196 + atomic_sub_unchecked(1, v);
5197 +}
5198 #define atomic64_dec(v) atomic64_sub(1, v)
5199 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5200 +{
5201 + atomic64_sub_unchecked(1, v);
5202 +}
5203
5204 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5205 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5206
5207 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5208 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5209 +{
5210 + return cmpxchg(&v->counter, old, new);
5211 +}
5212 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5213 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5214 +{
5215 + return xchg(&v->counter, new);
5216 +}
5217
5218 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5219 {
5220 - int c, old;
5221 + int c, old, new;
5222 c = atomic_read(v);
5223 for (;;) {
5224 - if (unlikely(c == (u)))
5225 + if (unlikely(c == u))
5226 break;
5227 - old = atomic_cmpxchg((v), c, c + (a));
5228 +
5229 + asm volatile("addcc %2, %0, %0\n"
5230 +
5231 +#ifdef CONFIG_PAX_REFCOUNT
5232 + "tvs %%icc, 6\n"
5233 +#endif
5234 +
5235 + : "=r" (new)
5236 + : "0" (c), "ir" (a)
5237 + : "cc");
5238 +
5239 + old = atomic_cmpxchg(v, c, new);
5240 if (likely(old == c))
5241 break;
5242 c = old;
5243 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5244 #define atomic64_cmpxchg(v, o, n) \
5245 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5246 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5247 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5248 +{
5249 + return xchg(&v->counter, new);
5250 +}
5251
5252 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5253 {
5254 - long c, old;
5255 + long c, old, new;
5256 c = atomic64_read(v);
5257 for (;;) {
5258 - if (unlikely(c == (u)))
5259 + if (unlikely(c == u))
5260 break;
5261 - old = atomic64_cmpxchg((v), c, c + (a));
5262 +
5263 + asm volatile("addcc %2, %0, %0\n"
5264 +
5265 +#ifdef CONFIG_PAX_REFCOUNT
5266 + "tvs %%xcc, 6\n"
5267 +#endif
5268 +
5269 + : "=r" (new)
5270 + : "0" (c), "ir" (a)
5271 + : "cc");
5272 +
5273 + old = atomic64_cmpxchg(v, c, new);
5274 if (likely(old == c))
5275 break;
5276 c = old;
5277 }
5278 - return c != (u);
5279 + return c != u;
5280 }
5281
5282 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5283 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5284 index 69358b5..9d0d492 100644
5285 --- a/arch/sparc/include/asm/cache.h
5286 +++ b/arch/sparc/include/asm/cache.h
5287 @@ -7,10 +7,12 @@
5288 #ifndef _SPARC_CACHE_H
5289 #define _SPARC_CACHE_H
5290
5291 +#include <linux/const.h>
5292 +
5293 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5294
5295 #define L1_CACHE_SHIFT 5
5296 -#define L1_CACHE_BYTES 32
5297 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5298
5299 #ifdef CONFIG_SPARC32
5300 #define SMP_CACHE_BYTES_SHIFT 5
5301 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5302 index 4269ca6..e3da77f 100644
5303 --- a/arch/sparc/include/asm/elf_32.h
5304 +++ b/arch/sparc/include/asm/elf_32.h
5305 @@ -114,6 +114,13 @@ typedef struct {
5306
5307 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5308
5309 +#ifdef CONFIG_PAX_ASLR
5310 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5311 +
5312 +#define PAX_DELTA_MMAP_LEN 16
5313 +#define PAX_DELTA_STACK_LEN 16
5314 +#endif
5315 +
5316 /* This yields a mask that user programs can use to figure out what
5317 instruction set this cpu supports. This can NOT be done in userspace
5318 on Sparc. */
5319 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5320 index 7df8b7f..4946269 100644
5321 --- a/arch/sparc/include/asm/elf_64.h
5322 +++ b/arch/sparc/include/asm/elf_64.h
5323 @@ -180,6 +180,13 @@ typedef struct {
5324 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5325 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5326
5327 +#ifdef CONFIG_PAX_ASLR
5328 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5329 +
5330 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5331 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5332 +#endif
5333 +
5334 extern unsigned long sparc64_elf_hwcap;
5335 #define ELF_HWCAP sparc64_elf_hwcap
5336
5337 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5338 index ca2b344..c6084f89 100644
5339 --- a/arch/sparc/include/asm/pgalloc_32.h
5340 +++ b/arch/sparc/include/asm/pgalloc_32.h
5341 @@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5342 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5343 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5344 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5345 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5346
5347 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5348 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5349 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5350 index 40b2d7a..22a665b 100644
5351 --- a/arch/sparc/include/asm/pgalloc_64.h
5352 +++ b/arch/sparc/include/asm/pgalloc_64.h
5353 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5354 }
5355
5356 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5357 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5358
5359 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5360 {
5361 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5362 index 3d71018..48a11c5 100644
5363 --- a/arch/sparc/include/asm/pgtable_32.h
5364 +++ b/arch/sparc/include/asm/pgtable_32.h
5365 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5366 BTFIXUPDEF_INT(page_none)
5367 BTFIXUPDEF_INT(page_copy)
5368 BTFIXUPDEF_INT(page_readonly)
5369 +
5370 +#ifdef CONFIG_PAX_PAGEEXEC
5371 +BTFIXUPDEF_INT(page_shared_noexec)
5372 +BTFIXUPDEF_INT(page_copy_noexec)
5373 +BTFIXUPDEF_INT(page_readonly_noexec)
5374 +#endif
5375 +
5376 BTFIXUPDEF_INT(page_kernel)
5377
5378 #define PMD_SHIFT SUN4C_PMD_SHIFT
5379 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5380 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5381 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5382
5383 +#ifdef CONFIG_PAX_PAGEEXEC
5384 +extern pgprot_t PAGE_SHARED_NOEXEC;
5385 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5386 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5387 +#else
5388 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5389 +# define PAGE_COPY_NOEXEC PAGE_COPY
5390 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5391 +#endif
5392 +
5393 extern unsigned long page_kernel;
5394
5395 #ifdef MODULE
5396 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5397 index f6ae2b2..b03ffc7 100644
5398 --- a/arch/sparc/include/asm/pgtsrmmu.h
5399 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5400 @@ -115,6 +115,13 @@
5401 SRMMU_EXEC | SRMMU_REF)
5402 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5403 SRMMU_EXEC | SRMMU_REF)
5404 +
5405 +#ifdef CONFIG_PAX_PAGEEXEC
5406 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5407 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5408 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5409 +#endif
5410 +
5411 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5412 SRMMU_DIRTY | SRMMU_REF)
5413
5414 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5415 index 9689176..63c18ea 100644
5416 --- a/arch/sparc/include/asm/spinlock_64.h
5417 +++ b/arch/sparc/include/asm/spinlock_64.h
5418 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5419
5420 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5421
5422 -static void inline arch_read_lock(arch_rwlock_t *lock)
5423 +static inline void arch_read_lock(arch_rwlock_t *lock)
5424 {
5425 unsigned long tmp1, tmp2;
5426
5427 __asm__ __volatile__ (
5428 "1: ldsw [%2], %0\n"
5429 " brlz,pn %0, 2f\n"
5430 -"4: add %0, 1, %1\n"
5431 +"4: addcc %0, 1, %1\n"
5432 +
5433 +#ifdef CONFIG_PAX_REFCOUNT
5434 +" tvs %%icc, 6\n"
5435 +#endif
5436 +
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5441 " .previous"
5442 : "=&r" (tmp1), "=&r" (tmp2)
5443 : "r" (lock)
5444 - : "memory");
5445 + : "memory", "cc");
5446 }
5447
5448 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5450 {
5451 int tmp1, tmp2;
5452
5453 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5454 "1: ldsw [%2], %0\n"
5455 " brlz,a,pn %0, 2f\n"
5456 " mov 0, %0\n"
5457 -" add %0, 1, %1\n"
5458 +" addcc %0, 1, %1\n"
5459 +
5460 +#ifdef CONFIG_PAX_REFCOUNT
5461 +" tvs %%icc, 6\n"
5462 +#endif
5463 +
5464 " cas [%2], %0, %1\n"
5465 " cmp %0, %1\n"
5466 " bne,pn %%icc, 1b\n"
5467 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5468 return tmp1;
5469 }
5470
5471 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5472 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5473 {
5474 unsigned long tmp1, tmp2;
5475
5476 __asm__ __volatile__(
5477 "1: lduw [%2], %0\n"
5478 -" sub %0, 1, %1\n"
5479 +" subcc %0, 1, %1\n"
5480 +
5481 +#ifdef CONFIG_PAX_REFCOUNT
5482 +" tvs %%icc, 6\n"
5483 +#endif
5484 +
5485 " cas [%2], %0, %1\n"
5486 " cmp %0, %1\n"
5487 " bne,pn %%xcc, 1b\n"
5488 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5489 : "memory");
5490 }
5491
5492 -static void inline arch_write_lock(arch_rwlock_t *lock)
5493 +static inline void arch_write_lock(arch_rwlock_t *lock)
5494 {
5495 unsigned long mask, tmp1, tmp2;
5496
5497 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5498 : "memory");
5499 }
5500
5501 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5502 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5503 {
5504 __asm__ __volatile__(
5505 " stw %%g0, [%0]"
5506 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5507 : "memory");
5508 }
5509
5510 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5511 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5512 {
5513 unsigned long mask, tmp1, tmp2, result;
5514
5515 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5516 index c2a1080..21ed218 100644
5517 --- a/arch/sparc/include/asm/thread_info_32.h
5518 +++ b/arch/sparc/include/asm/thread_info_32.h
5519 @@ -50,6 +50,8 @@ struct thread_info {
5520 unsigned long w_saved;
5521
5522 struct restart_block restart_block;
5523 +
5524 + unsigned long lowest_stack;
5525 };
5526
5527 /*
5528 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5529 index 01d057f..13a7d2f 100644
5530 --- a/arch/sparc/include/asm/thread_info_64.h
5531 +++ b/arch/sparc/include/asm/thread_info_64.h
5532 @@ -63,6 +63,8 @@ struct thread_info {
5533 struct pt_regs *kern_una_regs;
5534 unsigned int kern_una_insn;
5535
5536 + unsigned long lowest_stack;
5537 +
5538 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5539 };
5540
5541 @@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5542 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5543 /* flag bit 6 is available */
5544 #define TIF_32BIT 7 /* 32-bit binary */
5545 -/* flag bit 8 is available */
5546 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5547 #define TIF_SECCOMP 9 /* secure computing */
5548 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5549 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5550 +
5551 /* NOTE: Thread flags >= 12 should be ones we have no interest
5552 * in using in assembly, else we can't use the mask as
5553 * an immediate value in instructions such as andcc.
5554 @@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5555 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5556 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5557 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5558 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5559
5560 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5561 _TIF_DO_NOTIFY_RESUME_MASK | \
5562 _TIF_NEED_RESCHED)
5563 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5564
5565 +#define _TIF_WORK_SYSCALL \
5566 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5567 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5568 +
5569 +
5570 /*
5571 * Thread-synchronous status.
5572 *
5573 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5574 index e88fbe5..96b0ce5 100644
5575 --- a/arch/sparc/include/asm/uaccess.h
5576 +++ b/arch/sparc/include/asm/uaccess.h
5577 @@ -1,5 +1,13 @@
5578 #ifndef ___ASM_SPARC_UACCESS_H
5579 #define ___ASM_SPARC_UACCESS_H
5580 +
5581 +#ifdef __KERNEL__
5582 +#ifndef __ASSEMBLY__
5583 +#include <linux/types.h>
5584 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5585 +#endif
5586 +#endif
5587 +
5588 #if defined(__sparc__) && defined(__arch64__)
5589 #include <asm/uaccess_64.h>
5590 #else
5591 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5592 index 8303ac4..07f333d 100644
5593 --- a/arch/sparc/include/asm/uaccess_32.h
5594 +++ b/arch/sparc/include/asm/uaccess_32.h
5595 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5596
5597 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5598 {
5599 - if (n && __access_ok((unsigned long) to, n))
5600 + if ((long)n < 0)
5601 + return n;
5602 +
5603 + if (n && __access_ok((unsigned long) to, n)) {
5604 + if (!__builtin_constant_p(n))
5605 + check_object_size(from, n, true);
5606 return __copy_user(to, (__force void __user *) from, n);
5607 - else
5608 + } else
5609 return n;
5610 }
5611
5612 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5613 {
5614 + if ((long)n < 0)
5615 + return n;
5616 +
5617 + if (!__builtin_constant_p(n))
5618 + check_object_size(from, n, true);
5619 +
5620 return __copy_user(to, (__force void __user *) from, n);
5621 }
5622
5623 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5624 {
5625 - if (n && __access_ok((unsigned long) from, n))
5626 + if ((long)n < 0)
5627 + return n;
5628 +
5629 + if (n && __access_ok((unsigned long) from, n)) {
5630 + if (!__builtin_constant_p(n))
5631 + check_object_size(to, n, false);
5632 return __copy_user((__force void __user *) to, from, n);
5633 - else
5634 + } else
5635 return n;
5636 }
5637
5638 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5639 {
5640 + if ((long)n < 0)
5641 + return n;
5642 +
5643 return __copy_user((__force void __user *) to, from, n);
5644 }
5645
5646 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5647 index a1091afb..380228e 100644
5648 --- a/arch/sparc/include/asm/uaccess_64.h
5649 +++ b/arch/sparc/include/asm/uaccess_64.h
5650 @@ -10,6 +10,7 @@
5651 #include <linux/compiler.h>
5652 #include <linux/string.h>
5653 #include <linux/thread_info.h>
5654 +#include <linux/kernel.h>
5655 #include <asm/asi.h>
5656 #include <asm/spitfire.h>
5657 #include <asm-generic/uaccess-unaligned.h>
5658 @@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5659 static inline unsigned long __must_check
5660 copy_from_user(void *to, const void __user *from, unsigned long size)
5661 {
5662 - unsigned long ret = ___copy_from_user(to, from, size);
5663 + unsigned long ret;
5664
5665 + if ((long)size < 0 || size > INT_MAX)
5666 + return size;
5667 +
5668 + if (!__builtin_constant_p(size))
5669 + check_object_size(to, size, false);
5670 +
5671 + ret = ___copy_from_user(to, from, size);
5672 if (unlikely(ret))
5673 ret = copy_from_user_fixup(to, from, size);
5674
5675 @@ -229,8 +237,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5676 static inline unsigned long __must_check
5677 copy_to_user(void __user *to, const void *from, unsigned long size)
5678 {
5679 - unsigned long ret = ___copy_to_user(to, from, size);
5680 + unsigned long ret;
5681
5682 + if ((long)size < 0 || size > INT_MAX)
5683 + return size;
5684 +
5685 + if (!__builtin_constant_p(size))
5686 + check_object_size(from, size, true);
5687 +
5688 + ret = ___copy_to_user(to, from, size);
5689 if (unlikely(ret))
5690 ret = copy_to_user_fixup(to, from, size);
5691 return ret;
5692 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5693 index cb85458..e063f17 100644
5694 --- a/arch/sparc/kernel/Makefile
5695 +++ b/arch/sparc/kernel/Makefile
5696 @@ -3,7 +3,7 @@
5697 #
5698
5699 asflags-y := -ansi
5700 -ccflags-y := -Werror
5701 +#ccflags-y := -Werror
5702
5703 extra-y := head_$(BITS).o
5704 extra-y += init_task.o
5705 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5706 index efa0754..74b03fe 100644
5707 --- a/arch/sparc/kernel/process_32.c
5708 +++ b/arch/sparc/kernel/process_32.c
5709 @@ -200,7 +200,7 @@ void __show_backtrace(unsigned long fp)
5710 rw->ins[4], rw->ins[5],
5711 rw->ins[6],
5712 rw->ins[7]);
5713 - printk("%pS\n", (void *) rw->ins[7]);
5714 + printk("%pA\n", (void *) rw->ins[7]);
5715 rw = (struct reg_window32 *) rw->ins[6];
5716 }
5717 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5718 @@ -267,14 +267,14 @@ void show_regs(struct pt_regs *r)
5719
5720 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5721 r->psr, r->pc, r->npc, r->y, print_tainted());
5722 - printk("PC: <%pS>\n", (void *) r->pc);
5723 + printk("PC: <%pA>\n", (void *) r->pc);
5724 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5725 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5726 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5727 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5728 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5729 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5730 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5731 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5732
5733 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5734 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5735 @@ -309,7 +309,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5736 rw = (struct reg_window32 *) fp;
5737 pc = rw->ins[7];
5738 printk("[%08lx : ", pc);
5739 - printk("%pS ] ", (void *) pc);
5740 + printk("%pA ] ", (void *) pc);
5741 fp = rw->ins[6];
5742 } while (++count < 16);
5743 printk("\n");
5744 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5745 index aff0c72..9067b39 100644
5746 --- a/arch/sparc/kernel/process_64.c
5747 +++ b/arch/sparc/kernel/process_64.c
5748 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5749 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5750 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5751 if (regs->tstate & TSTATE_PRIV)
5752 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5753 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5754 }
5755
5756 void show_regs(struct pt_regs *regs)
5757 {
5758 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5759 regs->tpc, regs->tnpc, regs->y, print_tainted());
5760 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5761 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5762 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5763 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5764 regs->u_regs[3]);
5765 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5766 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5767 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5768 regs->u_regs[15]);
5769 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5770 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5771 show_regwindow(regs);
5772 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5773 }
5774 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5775 ((tp && tp->task) ? tp->task->pid : -1));
5776
5777 if (gp->tstate & TSTATE_PRIV) {
5778 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5779 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5780 (void *) gp->tpc,
5781 (void *) gp->o7,
5782 (void *) gp->i7,
5783 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5784 index 6f97c07..b1300ec 100644
5785 --- a/arch/sparc/kernel/ptrace_64.c
5786 +++ b/arch/sparc/kernel/ptrace_64.c
5787 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5788 return ret;
5789 }
5790
5791 +#ifdef CONFIG_GRKERNSEC_SETXID
5792 +extern void gr_delayed_cred_worker(void);
5793 +#endif
5794 +
5795 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5796 {
5797 int ret = 0;
5798 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5799 /* do the secure computing check first */
5800 secure_computing(regs->u_regs[UREG_G1]);
5801
5802 +#ifdef CONFIG_GRKERNSEC_SETXID
5803 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5804 + gr_delayed_cred_worker();
5805 +#endif
5806 +
5807 if (test_thread_flag(TIF_SYSCALL_TRACE))
5808 ret = tracehook_report_syscall_entry(regs);
5809
5810 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5811
5812 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5813 {
5814 +#ifdef CONFIG_GRKERNSEC_SETXID
5815 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5816 + gr_delayed_cred_worker();
5817 +#endif
5818 +
5819 audit_syscall_exit(regs);
5820
5821 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5822 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5823 index 42b282f..28ce9f2 100644
5824 --- a/arch/sparc/kernel/sys_sparc_32.c
5825 +++ b/arch/sparc/kernel/sys_sparc_32.c
5826 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5827 if (ARCH_SUN4C && len > 0x20000000)
5828 return -ENOMEM;
5829 if (!addr)
5830 - addr = TASK_UNMAPPED_BASE;
5831 + addr = current->mm->mmap_base;
5832
5833 if (flags & MAP_SHARED)
5834 addr = COLOUR_ALIGN(addr);
5835 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 }
5837 if (TASK_SIZE - PAGE_SIZE - len < addr)
5838 return -ENOMEM;
5839 - if (!vmm || addr + len <= vmm->vm_start)
5840 + if (check_heap_stack_gap(vmm, addr, len))
5841 return addr;
5842 addr = vmm->vm_end;
5843 if (flags & MAP_SHARED)
5844 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5845 index 3ee51f1..2ba4913 100644
5846 --- a/arch/sparc/kernel/sys_sparc_64.c
5847 +++ b/arch/sparc/kernel/sys_sparc_64.c
5848 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5849 /* We do not accept a shared mapping if it would violate
5850 * cache aliasing constraints.
5851 */
5852 - if ((flags & MAP_SHARED) &&
5853 + if ((filp || (flags & MAP_SHARED)) &&
5854 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5855 return -EINVAL;
5856 return addr;
5857 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5858 if (filp || (flags & MAP_SHARED))
5859 do_color_align = 1;
5860
5861 +#ifdef CONFIG_PAX_RANDMMAP
5862 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5863 +#endif
5864 +
5865 if (addr) {
5866 if (do_color_align)
5867 addr = COLOUR_ALIGN(addr, pgoff);
5868 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5869 addr = PAGE_ALIGN(addr);
5870
5871 vma = find_vma(mm, addr);
5872 - if (task_size - len >= addr &&
5873 - (!vma || addr + len <= vma->vm_start))
5874 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5875 return addr;
5876 }
5877
5878 if (len > mm->cached_hole_size) {
5879 - start_addr = addr = mm->free_area_cache;
5880 + start_addr = addr = mm->free_area_cache;
5881 } else {
5882 - start_addr = addr = TASK_UNMAPPED_BASE;
5883 + start_addr = addr = mm->mmap_base;
5884 mm->cached_hole_size = 0;
5885 }
5886
5887 @@ -174,14 +177,14 @@ full_search:
5888 vma = find_vma(mm, VA_EXCLUDE_END);
5889 }
5890 if (unlikely(task_size < addr)) {
5891 - if (start_addr != TASK_UNMAPPED_BASE) {
5892 - start_addr = addr = TASK_UNMAPPED_BASE;
5893 + if (start_addr != mm->mmap_base) {
5894 + start_addr = addr = mm->mmap_base;
5895 mm->cached_hole_size = 0;
5896 goto full_search;
5897 }
5898 return -ENOMEM;
5899 }
5900 - if (likely(!vma || addr + len <= vma->vm_start)) {
5901 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5902 /*
5903 * Remember the place where we stopped the search:
5904 */
5905 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 /* We do not accept a shared mapping if it would violate
5907 * cache aliasing constraints.
5908 */
5909 - if ((flags & MAP_SHARED) &&
5910 + if ((filp || (flags & MAP_SHARED)) &&
5911 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5912 return -EINVAL;
5913 return addr;
5914 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5915 addr = PAGE_ALIGN(addr);
5916
5917 vma = find_vma(mm, addr);
5918 - if (task_size - len >= addr &&
5919 - (!vma || addr + len <= vma->vm_start))
5920 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5921 return addr;
5922 }
5923
5924 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5925 /* make sure it can fit in the remaining address space */
5926 if (likely(addr > len)) {
5927 vma = find_vma(mm, addr-len);
5928 - if (!vma || addr <= vma->vm_start) {
5929 + if (check_heap_stack_gap(vma, addr - len, len)) {
5930 /* remember the address as a hint for next time */
5931 return (mm->free_area_cache = addr-len);
5932 }
5933 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5934 if (unlikely(mm->mmap_base < len))
5935 goto bottomup;
5936
5937 - addr = mm->mmap_base-len;
5938 - if (do_color_align)
5939 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5940 + addr = mm->mmap_base - len;
5941
5942 do {
5943 + if (do_color_align)
5944 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5945 /*
5946 * Lookup failure means no vma is above this address,
5947 * else if new region fits below vma->vm_start,
5948 * return with success:
5949 */
5950 vma = find_vma(mm, addr);
5951 - if (likely(!vma || addr+len <= vma->vm_start)) {
5952 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5953 /* remember the address as a hint for next time */
5954 return (mm->free_area_cache = addr);
5955 }
5956 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5957 mm->cached_hole_size = vma->vm_start - addr;
5958
5959 /* try just below the current vma->vm_start */
5960 - addr = vma->vm_start-len;
5961 - if (do_color_align)
5962 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5963 - } while (likely(len < vma->vm_start));
5964 + addr = skip_heap_stack_gap(vma, len);
5965 + } while (!IS_ERR_VALUE(addr));
5966
5967 bottomup:
5968 /*
5969 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5970 gap == RLIM_INFINITY ||
5971 sysctl_legacy_va_layout) {
5972 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5973 +
5974 +#ifdef CONFIG_PAX_RANDMMAP
5975 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5976 + mm->mmap_base += mm->delta_mmap;
5977 +#endif
5978 +
5979 mm->get_unmapped_area = arch_get_unmapped_area;
5980 mm->unmap_area = arch_unmap_area;
5981 } else {
5982 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5983 gap = (task_size / 6 * 5);
5984
5985 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5986 +
5987 +#ifdef CONFIG_PAX_RANDMMAP
5988 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5989 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5990 +#endif
5991 +
5992 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5993 mm->unmap_area = arch_unmap_area_topdown;
5994 }
5995 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5996 index 1d7e274..b39c527 100644
5997 --- a/arch/sparc/kernel/syscalls.S
5998 +++ b/arch/sparc/kernel/syscalls.S
5999 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6000 #endif
6001 .align 32
6002 1: ldx [%g6 + TI_FLAGS], %l5
6003 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6004 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6005 be,pt %icc, rtrap
6006 nop
6007 call syscall_trace_leave
6008 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6009
6010 srl %i5, 0, %o5 ! IEU1
6011 srl %i2, 0, %o2 ! IEU0 Group
6012 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6013 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6014 bne,pn %icc, linux_syscall_trace32 ! CTI
6015 mov %i0, %l5 ! IEU1
6016 call %l7 ! CTI Group brk forced
6017 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6018
6019 mov %i3, %o3 ! IEU1
6020 mov %i4, %o4 ! IEU0 Group
6021 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6022 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6023 bne,pn %icc, linux_syscall_trace ! CTI Group
6024 mov %i0, %l5 ! IEU0
6025 2: call %l7 ! CTI Group brk forced
6026 @@ -226,7 +226,7 @@ ret_sys_call:
6027
6028 cmp %o0, -ERESTART_RESTARTBLOCK
6029 bgeu,pn %xcc, 1f
6030 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6031 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6032 80:
6033 /* System call success, clear Carry condition code. */
6034 andn %g3, %g2, %g3
6035 @@ -241,7 +241,7 @@ ret_sys_call:
6036 /* System call failure, set Carry condition code.
6037 * Also, get abs(errno) to return to the process.
6038 */
6039 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6040 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6041 sub %g0, %o0, %o0
6042 or %g3, %g2, %g3
6043 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6044 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6045 index d2de213..6b22bc3 100644
6046 --- a/arch/sparc/kernel/traps_32.c
6047 +++ b/arch/sparc/kernel/traps_32.c
6048 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6049 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6050 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6051
6052 +extern void gr_handle_kernel_exploit(void);
6053 +
6054 void die_if_kernel(char *str, struct pt_regs *regs)
6055 {
6056 static int die_counter;
6057 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6058 count++ < 30 &&
6059 (((unsigned long) rw) >= PAGE_OFFSET) &&
6060 !(((unsigned long) rw) & 0x7)) {
6061 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6062 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6063 (void *) rw->ins[7]);
6064 rw = (struct reg_window32 *)rw->ins[6];
6065 }
6066 }
6067 printk("Instruction DUMP:");
6068 instruction_dump ((unsigned long *) regs->pc);
6069 - if(regs->psr & PSR_PS)
6070 + if(regs->psr & PSR_PS) {
6071 + gr_handle_kernel_exploit();
6072 do_exit(SIGKILL);
6073 + }
6074 do_exit(SIGSEGV);
6075 }
6076
6077 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6078 index c72fdf5..743a344 100644
6079 --- a/arch/sparc/kernel/traps_64.c
6080 +++ b/arch/sparc/kernel/traps_64.c
6081 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6082 i + 1,
6083 p->trapstack[i].tstate, p->trapstack[i].tpc,
6084 p->trapstack[i].tnpc, p->trapstack[i].tt);
6085 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6086 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6087 }
6088 }
6089
6090 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6091
6092 lvl -= 0x100;
6093 if (regs->tstate & TSTATE_PRIV) {
6094 +
6095 +#ifdef CONFIG_PAX_REFCOUNT
6096 + if (lvl == 6)
6097 + pax_report_refcount_overflow(regs);
6098 +#endif
6099 +
6100 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6101 die_if_kernel(buffer, regs);
6102 }
6103 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6104 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6105 {
6106 char buffer[32];
6107 -
6108 +
6109 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6110 0, lvl, SIGTRAP) == NOTIFY_STOP)
6111 return;
6112
6113 +#ifdef CONFIG_PAX_REFCOUNT
6114 + if (lvl == 6)
6115 + pax_report_refcount_overflow(regs);
6116 +#endif
6117 +
6118 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6119
6120 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6121 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6122 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6123 printk("%s" "ERROR(%d): ",
6124 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6125 - printk("TPC<%pS>\n", (void *) regs->tpc);
6126 + printk("TPC<%pA>\n", (void *) regs->tpc);
6127 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6128 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6129 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6130 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6131 smp_processor_id(),
6132 (type & 0x1) ? 'I' : 'D',
6133 regs->tpc);
6134 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6135 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6136 panic("Irrecoverable Cheetah+ parity error.");
6137 }
6138
6139 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6140 smp_processor_id(),
6141 (type & 0x1) ? 'I' : 'D',
6142 regs->tpc);
6143 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6144 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6145 }
6146
6147 struct sun4v_error_entry {
6148 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6149
6150 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6151 regs->tpc, tl);
6152 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6153 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6154 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6155 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6156 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6157 (void *) regs->u_regs[UREG_I7]);
6158 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6159 "pte[%lx] error[%lx]\n",
6160 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6161
6162 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6163 regs->tpc, tl);
6164 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6165 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6166 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6167 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6168 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6169 (void *) regs->u_regs[UREG_I7]);
6170 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6171 "pte[%lx] error[%lx]\n",
6172 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6173 fp = (unsigned long)sf->fp + STACK_BIAS;
6174 }
6175
6176 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6177 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6178 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6179 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6180 int index = tsk->curr_ret_stack;
6181 if (tsk->ret_stack && index >= graph) {
6182 pc = tsk->ret_stack[index - graph].ret;
6183 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6184 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6185 graph++;
6186 }
6187 }
6188 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6189 return (struct reg_window *) (fp + STACK_BIAS);
6190 }
6191
6192 +extern void gr_handle_kernel_exploit(void);
6193 +
6194 void die_if_kernel(char *str, struct pt_regs *regs)
6195 {
6196 static int die_counter;
6197 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6198 while (rw &&
6199 count++ < 30 &&
6200 kstack_valid(tp, (unsigned long) rw)) {
6201 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6202 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6203 (void *) rw->ins[7]);
6204
6205 rw = kernel_stack_up(rw);
6206 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6207 }
6208 user_instruction_dump ((unsigned int __user *) regs->tpc);
6209 }
6210 - if (regs->tstate & TSTATE_PRIV)
6211 + if (regs->tstate & TSTATE_PRIV) {
6212 + gr_handle_kernel_exploit();
6213 do_exit(SIGKILL);
6214 + }
6215 do_exit(SIGSEGV);
6216 }
6217 EXPORT_SYMBOL(die_if_kernel);
6218 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6219 index dae85bc..af1e19d 100644
6220 --- a/arch/sparc/kernel/unaligned_64.c
6221 +++ b/arch/sparc/kernel/unaligned_64.c
6222 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6223 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6224
6225 if (__ratelimit(&ratelimit)) {
6226 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6227 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6228 regs->tpc, (void *) regs->tpc);
6229 }
6230 }
6231 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6232 index a3fc437..fea9957 100644
6233 --- a/arch/sparc/lib/Makefile
6234 +++ b/arch/sparc/lib/Makefile
6235 @@ -2,7 +2,7 @@
6236 #
6237
6238 asflags-y := -ansi -DST_DIV0=0x02
6239 -ccflags-y := -Werror
6240 +#ccflags-y := -Werror
6241
6242 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6243 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6244 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6245 index 59186e0..f747d7a 100644
6246 --- a/arch/sparc/lib/atomic_64.S
6247 +++ b/arch/sparc/lib/atomic_64.S
6248 @@ -18,7 +18,12 @@
6249 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6250 BACKOFF_SETUP(%o2)
6251 1: lduw [%o1], %g1
6252 - add %g1, %o0, %g7
6253 + addcc %g1, %o0, %g7
6254 +
6255 +#ifdef CONFIG_PAX_REFCOUNT
6256 + tvs %icc, 6
6257 +#endif
6258 +
6259 cas [%o1], %g1, %g7
6260 cmp %g1, %g7
6261 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6262 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6263 2: BACKOFF_SPIN(%o2, %o3, 1b)
6264 .size atomic_add, .-atomic_add
6265
6266 + .globl atomic_add_unchecked
6267 + .type atomic_add_unchecked,#function
6268 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6269 + BACKOFF_SETUP(%o2)
6270 +1: lduw [%o1], %g1
6271 + add %g1, %o0, %g7
6272 + cas [%o1], %g1, %g7
6273 + cmp %g1, %g7
6274 + bne,pn %icc, 2f
6275 + nop
6276 + retl
6277 + nop
6278 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 + .size atomic_add_unchecked, .-atomic_add_unchecked
6280 +
6281 .globl atomic_sub
6282 .type atomic_sub,#function
6283 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6284 BACKOFF_SETUP(%o2)
6285 1: lduw [%o1], %g1
6286 - sub %g1, %o0, %g7
6287 + subcc %g1, %o0, %g7
6288 +
6289 +#ifdef CONFIG_PAX_REFCOUNT
6290 + tvs %icc, 6
6291 +#endif
6292 +
6293 cas [%o1], %g1, %g7
6294 cmp %g1, %g7
6295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6296 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6297 2: BACKOFF_SPIN(%o2, %o3, 1b)
6298 .size atomic_sub, .-atomic_sub
6299
6300 + .globl atomic_sub_unchecked
6301 + .type atomic_sub_unchecked,#function
6302 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6303 + BACKOFF_SETUP(%o2)
6304 +1: lduw [%o1], %g1
6305 + sub %g1, %o0, %g7
6306 + cas [%o1], %g1, %g7
6307 + cmp %g1, %g7
6308 + bne,pn %icc, 2f
6309 + nop
6310 + retl
6311 + nop
6312 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6314 +
6315 .globl atomic_add_ret
6316 .type atomic_add_ret,#function
6317 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6318 BACKOFF_SETUP(%o2)
6319 1: lduw [%o1], %g1
6320 - add %g1, %o0, %g7
6321 + addcc %g1, %o0, %g7
6322 +
6323 +#ifdef CONFIG_PAX_REFCOUNT
6324 + tvs %icc, 6
6325 +#endif
6326 +
6327 cas [%o1], %g1, %g7
6328 cmp %g1, %g7
6329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6330 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6331 2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 .size atomic_add_ret, .-atomic_add_ret
6333
6334 + .globl atomic_add_ret_unchecked
6335 + .type atomic_add_ret_unchecked,#function
6336 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6337 + BACKOFF_SETUP(%o2)
6338 +1: lduw [%o1], %g1
6339 + addcc %g1, %o0, %g7
6340 + cas [%o1], %g1, %g7
6341 + cmp %g1, %g7
6342 + bne,pn %icc, 2f
6343 + add %g7, %o0, %g7
6344 + sra %g7, 0, %o0
6345 + retl
6346 + nop
6347 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6348 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6349 +
6350 .globl atomic_sub_ret
6351 .type atomic_sub_ret,#function
6352 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6353 BACKOFF_SETUP(%o2)
6354 1: lduw [%o1], %g1
6355 - sub %g1, %o0, %g7
6356 + subcc %g1, %o0, %g7
6357 +
6358 +#ifdef CONFIG_PAX_REFCOUNT
6359 + tvs %icc, 6
6360 +#endif
6361 +
6362 cas [%o1], %g1, %g7
6363 cmp %g1, %g7
6364 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6365 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6366 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6367 BACKOFF_SETUP(%o2)
6368 1: ldx [%o1], %g1
6369 - add %g1, %o0, %g7
6370 + addcc %g1, %o0, %g7
6371 +
6372 +#ifdef CONFIG_PAX_REFCOUNT
6373 + tvs %xcc, 6
6374 +#endif
6375 +
6376 casx [%o1], %g1, %g7
6377 cmp %g1, %g7
6378 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6379 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6380 2: BACKOFF_SPIN(%o2, %o3, 1b)
6381 .size atomic64_add, .-atomic64_add
6382
6383 + .globl atomic64_add_unchecked
6384 + .type atomic64_add_unchecked,#function
6385 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6386 + BACKOFF_SETUP(%o2)
6387 +1: ldx [%o1], %g1
6388 + addcc %g1, %o0, %g7
6389 + casx [%o1], %g1, %g7
6390 + cmp %g1, %g7
6391 + bne,pn %xcc, 2f
6392 + nop
6393 + retl
6394 + nop
6395 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6396 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6397 +
6398 .globl atomic64_sub
6399 .type atomic64_sub,#function
6400 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 .size atomic64_sub, .-atomic64_sub
6416
6417 + .globl atomic64_sub_unchecked
6418 + .type atomic64_sub_unchecked,#function
6419 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6420 + BACKOFF_SETUP(%o2)
6421 +1: ldx [%o1], %g1
6422 + subcc %g1, %o0, %g7
6423 + casx [%o1], %g1, %g7
6424 + cmp %g1, %g7
6425 + bne,pn %xcc, 2f
6426 + nop
6427 + retl
6428 + nop
6429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6430 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6431 +
6432 .globl atomic64_add_ret
6433 .type atomic64_add_ret,#function
6434 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6435 BACKOFF_SETUP(%o2)
6436 1: ldx [%o1], %g1
6437 - add %g1, %o0, %g7
6438 + addcc %g1, %o0, %g7
6439 +
6440 +#ifdef CONFIG_PAX_REFCOUNT
6441 + tvs %xcc, 6
6442 +#endif
6443 +
6444 casx [%o1], %g1, %g7
6445 cmp %g1, %g7
6446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6447 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6448 2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 .size atomic64_add_ret, .-atomic64_add_ret
6450
6451 + .globl atomic64_add_ret_unchecked
6452 + .type atomic64_add_ret_unchecked,#function
6453 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6454 + BACKOFF_SETUP(%o2)
6455 +1: ldx [%o1], %g1
6456 + addcc %g1, %o0, %g7
6457 + casx [%o1], %g1, %g7
6458 + cmp %g1, %g7
6459 + bne,pn %xcc, 2f
6460 + add %g7, %o0, %g7
6461 + mov %g7, %o0
6462 + retl
6463 + nop
6464 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6465 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6466 +
6467 .globl atomic64_sub_ret
6468 .type atomic64_sub_ret,#function
6469 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6470 BACKOFF_SETUP(%o2)
6471 1: ldx [%o1], %g1
6472 - sub %g1, %o0, %g7
6473 + subcc %g1, %o0, %g7
6474 +
6475 +#ifdef CONFIG_PAX_REFCOUNT
6476 + tvs %xcc, 6
6477 +#endif
6478 +
6479 casx [%o1], %g1, %g7
6480 cmp %g1, %g7
6481 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6482 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6483 index f73c224..662af10 100644
6484 --- a/arch/sparc/lib/ksyms.c
6485 +++ b/arch/sparc/lib/ksyms.c
6486 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6487
6488 /* Atomic counter implementation. */
6489 EXPORT_SYMBOL(atomic_add);
6490 +EXPORT_SYMBOL(atomic_add_unchecked);
6491 EXPORT_SYMBOL(atomic_add_ret);
6492 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6493 EXPORT_SYMBOL(atomic_sub);
6494 +EXPORT_SYMBOL(atomic_sub_unchecked);
6495 EXPORT_SYMBOL(atomic_sub_ret);
6496 EXPORT_SYMBOL(atomic64_add);
6497 +EXPORT_SYMBOL(atomic64_add_unchecked);
6498 EXPORT_SYMBOL(atomic64_add_ret);
6499 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6500 EXPORT_SYMBOL(atomic64_sub);
6501 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6502 EXPORT_SYMBOL(atomic64_sub_ret);
6503
6504 /* Atomic bit operations. */
6505 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6506 index 301421c..e2535d1 100644
6507 --- a/arch/sparc/mm/Makefile
6508 +++ b/arch/sparc/mm/Makefile
6509 @@ -2,7 +2,7 @@
6510 #
6511
6512 asflags-y := -ansi
6513 -ccflags-y := -Werror
6514 +#ccflags-y := -Werror
6515
6516 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6517 obj-y += fault_$(BITS).o
6518 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6519 index df3155a..eb708b8 100644
6520 --- a/arch/sparc/mm/fault_32.c
6521 +++ b/arch/sparc/mm/fault_32.c
6522 @@ -21,6 +21,9 @@
6523 #include <linux/perf_event.h>
6524 #include <linux/interrupt.h>
6525 #include <linux/kdebug.h>
6526 +#include <linux/slab.h>
6527 +#include <linux/pagemap.h>
6528 +#include <linux/compiler.h>
6529
6530 #include <asm/page.h>
6531 #include <asm/pgtable.h>
6532 @@ -207,6 +210,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6533 return safe_compute_effective_address(regs, insn);
6534 }
6535
6536 +#ifdef CONFIG_PAX_PAGEEXEC
6537 +#ifdef CONFIG_PAX_DLRESOLVE
6538 +static void pax_emuplt_close(struct vm_area_struct *vma)
6539 +{
6540 + vma->vm_mm->call_dl_resolve = 0UL;
6541 +}
6542 +
6543 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6544 +{
6545 + unsigned int *kaddr;
6546 +
6547 + vmf->page = alloc_page(GFP_HIGHUSER);
6548 + if (!vmf->page)
6549 + return VM_FAULT_OOM;
6550 +
6551 + kaddr = kmap(vmf->page);
6552 + memset(kaddr, 0, PAGE_SIZE);
6553 + kaddr[0] = 0x9DE3BFA8U; /* save */
6554 + flush_dcache_page(vmf->page);
6555 + kunmap(vmf->page);
6556 + return VM_FAULT_MAJOR;
6557 +}
6558 +
6559 +static const struct vm_operations_struct pax_vm_ops = {
6560 + .close = pax_emuplt_close,
6561 + .fault = pax_emuplt_fault
6562 +};
6563 +
6564 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6565 +{
6566 + int ret;
6567 +
6568 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6569 + vma->vm_mm = current->mm;
6570 + vma->vm_start = addr;
6571 + vma->vm_end = addr + PAGE_SIZE;
6572 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6573 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6574 + vma->vm_ops = &pax_vm_ops;
6575 +
6576 + ret = insert_vm_struct(current->mm, vma);
6577 + if (ret)
6578 + return ret;
6579 +
6580 + ++current->mm->total_vm;
6581 + return 0;
6582 +}
6583 +#endif
6584 +
6585 +/*
6586 + * PaX: decide what to do with offenders (regs->pc = fault address)
6587 + *
6588 + * returns 1 when task should be killed
6589 + * 2 when patched PLT trampoline was detected
6590 + * 3 when unpatched PLT trampoline was detected
6591 + */
6592 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6593 +{
6594 +
6595 +#ifdef CONFIG_PAX_EMUPLT
6596 + int err;
6597 +
6598 + do { /* PaX: patched PLT emulation #1 */
6599 + unsigned int sethi1, sethi2, jmpl;
6600 +
6601 + err = get_user(sethi1, (unsigned int *)regs->pc);
6602 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6603 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6604 +
6605 + if (err)
6606 + break;
6607 +
6608 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6609 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6610 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6611 + {
6612 + unsigned int addr;
6613 +
6614 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6615 + addr = regs->u_regs[UREG_G1];
6616 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6617 + regs->pc = addr;
6618 + regs->npc = addr+4;
6619 + return 2;
6620 + }
6621 + } while (0);
6622 +
6623 + { /* PaX: patched PLT emulation #2 */
6624 + unsigned int ba;
6625 +
6626 + err = get_user(ba, (unsigned int *)regs->pc);
6627 +
6628 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6629 + unsigned int addr;
6630 +
6631 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6632 + regs->pc = addr;
6633 + regs->npc = addr+4;
6634 + return 2;
6635 + }
6636 + }
6637 +
6638 + do { /* PaX: patched PLT emulation #3 */
6639 + unsigned int sethi, jmpl, nop;
6640 +
6641 + err = get_user(sethi, (unsigned int *)regs->pc);
6642 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6643 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6644 +
6645 + if (err)
6646 + break;
6647 +
6648 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6649 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6650 + nop == 0x01000000U)
6651 + {
6652 + unsigned int addr;
6653 +
6654 + addr = (sethi & 0x003FFFFFU) << 10;
6655 + regs->u_regs[UREG_G1] = addr;
6656 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6657 + regs->pc = addr;
6658 + regs->npc = addr+4;
6659 + return 2;
6660 + }
6661 + } while (0);
6662 +
6663 + do { /* PaX: unpatched PLT emulation step 1 */
6664 + unsigned int sethi, ba, nop;
6665 +
6666 + err = get_user(sethi, (unsigned int *)regs->pc);
6667 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6668 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6669 +
6670 + if (err)
6671 + break;
6672 +
6673 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6674 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6675 + nop == 0x01000000U)
6676 + {
6677 + unsigned int addr, save, call;
6678 +
6679 + if ((ba & 0xFFC00000U) == 0x30800000U)
6680 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6681 + else
6682 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6683 +
6684 + err = get_user(save, (unsigned int *)addr);
6685 + err |= get_user(call, (unsigned int *)(addr+4));
6686 + err |= get_user(nop, (unsigned int *)(addr+8));
6687 + if (err)
6688 + break;
6689 +
6690 +#ifdef CONFIG_PAX_DLRESOLVE
6691 + if (save == 0x9DE3BFA8U &&
6692 + (call & 0xC0000000U) == 0x40000000U &&
6693 + nop == 0x01000000U)
6694 + {
6695 + struct vm_area_struct *vma;
6696 + unsigned long call_dl_resolve;
6697 +
6698 + down_read(&current->mm->mmap_sem);
6699 + call_dl_resolve = current->mm->call_dl_resolve;
6700 + up_read(&current->mm->mmap_sem);
6701 + if (likely(call_dl_resolve))
6702 + goto emulate;
6703 +
6704 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6705 +
6706 + down_write(&current->mm->mmap_sem);
6707 + if (current->mm->call_dl_resolve) {
6708 + call_dl_resolve = current->mm->call_dl_resolve;
6709 + up_write(&current->mm->mmap_sem);
6710 + if (vma)
6711 + kmem_cache_free(vm_area_cachep, vma);
6712 + goto emulate;
6713 + }
6714 +
6715 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6716 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6717 + up_write(&current->mm->mmap_sem);
6718 + if (vma)
6719 + kmem_cache_free(vm_area_cachep, vma);
6720 + return 1;
6721 + }
6722 +
6723 + if (pax_insert_vma(vma, call_dl_resolve)) {
6724 + up_write(&current->mm->mmap_sem);
6725 + kmem_cache_free(vm_area_cachep, vma);
6726 + return 1;
6727 + }
6728 +
6729 + current->mm->call_dl_resolve = call_dl_resolve;
6730 + up_write(&current->mm->mmap_sem);
6731 +
6732 +emulate:
6733 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6734 + regs->pc = call_dl_resolve;
6735 + regs->npc = addr+4;
6736 + return 3;
6737 + }
6738 +#endif
6739 +
6740 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6741 + if ((save & 0xFFC00000U) == 0x05000000U &&
6742 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6743 + nop == 0x01000000U)
6744 + {
6745 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6746 + regs->u_regs[UREG_G2] = addr + 4;
6747 + addr = (save & 0x003FFFFFU) << 10;
6748 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6749 + regs->pc = addr;
6750 + regs->npc = addr+4;
6751 + return 3;
6752 + }
6753 + }
6754 + } while (0);
6755 +
6756 + do { /* PaX: unpatched PLT emulation step 2 */
6757 + unsigned int save, call, nop;
6758 +
6759 + err = get_user(save, (unsigned int *)(regs->pc-4));
6760 + err |= get_user(call, (unsigned int *)regs->pc);
6761 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6762 + if (err)
6763 + break;
6764 +
6765 + if (save == 0x9DE3BFA8U &&
6766 + (call & 0xC0000000U) == 0x40000000U &&
6767 + nop == 0x01000000U)
6768 + {
6769 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6770 +
6771 + regs->u_regs[UREG_RETPC] = regs->pc;
6772 + regs->pc = dl_resolve;
6773 + regs->npc = dl_resolve+4;
6774 + return 3;
6775 + }
6776 + } while (0);
6777 +#endif
6778 +
6779 + return 1;
6780 +}
6781 +
6782 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6783 +{
6784 + unsigned long i;
6785 +
6786 + printk(KERN_ERR "PAX: bytes at PC: ");
6787 + for (i = 0; i < 8; i++) {
6788 + unsigned int c;
6789 + if (get_user(c, (unsigned int *)pc+i))
6790 + printk(KERN_CONT "???????? ");
6791 + else
6792 + printk(KERN_CONT "%08x ", c);
6793 + }
6794 + printk("\n");
6795 +}
6796 +#endif
6797 +
6798 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6799 int text_fault)
6800 {
6801 @@ -282,6 +547,24 @@ good_area:
6802 if(!(vma->vm_flags & VM_WRITE))
6803 goto bad_area;
6804 } else {
6805 +
6806 +#ifdef CONFIG_PAX_PAGEEXEC
6807 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6808 + up_read(&mm->mmap_sem);
6809 + switch (pax_handle_fetch_fault(regs)) {
6810 +
6811 +#ifdef CONFIG_PAX_EMUPLT
6812 + case 2:
6813 + case 3:
6814 + return;
6815 +#endif
6816 +
6817 + }
6818 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6819 + do_group_exit(SIGKILL);
6820 + }
6821 +#endif
6822 +
6823 /* Allow reads even for write-only mappings */
6824 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6825 goto bad_area;
6826 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6827 index 1fe0429..aee2e87 100644
6828 --- a/arch/sparc/mm/fault_64.c
6829 +++ b/arch/sparc/mm/fault_64.c
6830 @@ -21,6 +21,9 @@
6831 #include <linux/kprobes.h>
6832 #include <linux/kdebug.h>
6833 #include <linux/percpu.h>
6834 +#include <linux/slab.h>
6835 +#include <linux/pagemap.h>
6836 +#include <linux/compiler.h>
6837
6838 #include <asm/page.h>
6839 #include <asm/pgtable.h>
6840 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6841 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6842 regs->tpc);
6843 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6844 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6845 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6846 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6847 dump_stack();
6848 unhandled_fault(regs->tpc, current, regs);
6849 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6850 show_regs(regs);
6851 }
6852
6853 +#ifdef CONFIG_PAX_PAGEEXEC
6854 +#ifdef CONFIG_PAX_DLRESOLVE
6855 +static void pax_emuplt_close(struct vm_area_struct *vma)
6856 +{
6857 + vma->vm_mm->call_dl_resolve = 0UL;
6858 +}
6859 +
6860 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6861 +{
6862 + unsigned int *kaddr;
6863 +
6864 + vmf->page = alloc_page(GFP_HIGHUSER);
6865 + if (!vmf->page)
6866 + return VM_FAULT_OOM;
6867 +
6868 + kaddr = kmap(vmf->page);
6869 + memset(kaddr, 0, PAGE_SIZE);
6870 + kaddr[0] = 0x9DE3BFA8U; /* save */
6871 + flush_dcache_page(vmf->page);
6872 + kunmap(vmf->page);
6873 + return VM_FAULT_MAJOR;
6874 +}
6875 +
6876 +static const struct vm_operations_struct pax_vm_ops = {
6877 + .close = pax_emuplt_close,
6878 + .fault = pax_emuplt_fault
6879 +};
6880 +
6881 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6882 +{
6883 + int ret;
6884 +
6885 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6886 + vma->vm_mm = current->mm;
6887 + vma->vm_start = addr;
6888 + vma->vm_end = addr + PAGE_SIZE;
6889 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6890 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6891 + vma->vm_ops = &pax_vm_ops;
6892 +
6893 + ret = insert_vm_struct(current->mm, vma);
6894 + if (ret)
6895 + return ret;
6896 +
6897 + ++current->mm->total_vm;
6898 + return 0;
6899 +}
6900 +#endif
6901 +
6902 +/*
6903 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6904 + *
6905 + * returns 1 when task should be killed
6906 + * 2 when patched PLT trampoline was detected
6907 + * 3 when unpatched PLT trampoline was detected
6908 + */
6909 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6910 +{
6911 +
6912 +#ifdef CONFIG_PAX_EMUPLT
6913 + int err;
6914 +
6915 + do { /* PaX: patched PLT emulation #1 */
6916 + unsigned int sethi1, sethi2, jmpl;
6917 +
6918 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6919 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6920 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6921 +
6922 + if (err)
6923 + break;
6924 +
6925 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6926 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6927 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6928 + {
6929 + unsigned long addr;
6930 +
6931 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6932 + addr = regs->u_regs[UREG_G1];
6933 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6934 +
6935 + if (test_thread_flag(TIF_32BIT))
6936 + addr &= 0xFFFFFFFFUL;
6937 +
6938 + regs->tpc = addr;
6939 + regs->tnpc = addr+4;
6940 + return 2;
6941 + }
6942 + } while (0);
6943 +
6944 + { /* PaX: patched PLT emulation #2 */
6945 + unsigned int ba;
6946 +
6947 + err = get_user(ba, (unsigned int *)regs->tpc);
6948 +
6949 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6950 + unsigned long addr;
6951 +
6952 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6953 +
6954 + if (test_thread_flag(TIF_32BIT))
6955 + addr &= 0xFFFFFFFFUL;
6956 +
6957 + regs->tpc = addr;
6958 + regs->tnpc = addr+4;
6959 + return 2;
6960 + }
6961 + }
6962 +
6963 + do { /* PaX: patched PLT emulation #3 */
6964 + unsigned int sethi, jmpl, nop;
6965 +
6966 + err = get_user(sethi, (unsigned int *)regs->tpc);
6967 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6968 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6969 +
6970 + if (err)
6971 + break;
6972 +
6973 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6974 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6975 + nop == 0x01000000U)
6976 + {
6977 + unsigned long addr;
6978 +
6979 + addr = (sethi & 0x003FFFFFU) << 10;
6980 + regs->u_regs[UREG_G1] = addr;
6981 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6982 +
6983 + if (test_thread_flag(TIF_32BIT))
6984 + addr &= 0xFFFFFFFFUL;
6985 +
6986 + regs->tpc = addr;
6987 + regs->tnpc = addr+4;
6988 + return 2;
6989 + }
6990 + } while (0);
6991 +
6992 + do { /* PaX: patched PLT emulation #4 */
6993 + unsigned int sethi, mov1, call, mov2;
6994 +
6995 + err = get_user(sethi, (unsigned int *)regs->tpc);
6996 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6997 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6998 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6999 +
7000 + if (err)
7001 + break;
7002 +
7003 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004 + mov1 == 0x8210000FU &&
7005 + (call & 0xC0000000U) == 0x40000000U &&
7006 + mov2 == 0x9E100001U)
7007 + {
7008 + unsigned long addr;
7009 +
7010 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7011 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7012 +
7013 + if (test_thread_flag(TIF_32BIT))
7014 + addr &= 0xFFFFFFFFUL;
7015 +
7016 + regs->tpc = addr;
7017 + regs->tnpc = addr+4;
7018 + return 2;
7019 + }
7020 + } while (0);
7021 +
7022 + do { /* PaX: patched PLT emulation #5 */
7023 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7024 +
7025 + err = get_user(sethi, (unsigned int *)regs->tpc);
7026 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7027 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7028 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7029 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7030 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7031 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7032 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7033 +
7034 + if (err)
7035 + break;
7036 +
7037 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7038 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7039 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7040 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7041 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7042 + sllx == 0x83287020U &&
7043 + jmpl == 0x81C04005U &&
7044 + nop == 0x01000000U)
7045 + {
7046 + unsigned long addr;
7047 +
7048 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7049 + regs->u_regs[UREG_G1] <<= 32;
7050 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7051 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052 + regs->tpc = addr;
7053 + regs->tnpc = addr+4;
7054 + return 2;
7055 + }
7056 + } while (0);
7057 +
7058 + do { /* PaX: patched PLT emulation #6 */
7059 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7060 +
7061 + err = get_user(sethi, (unsigned int *)regs->tpc);
7062 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7063 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7064 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7065 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7066 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7067 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7068 +
7069 + if (err)
7070 + break;
7071 +
7072 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7073 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7074 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7075 + sllx == 0x83287020U &&
7076 + (or & 0xFFFFE000U) == 0x8A116000U &&
7077 + jmpl == 0x81C04005U &&
7078 + nop == 0x01000000U)
7079 + {
7080 + unsigned long addr;
7081 +
7082 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7083 + regs->u_regs[UREG_G1] <<= 32;
7084 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7085 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7086 + regs->tpc = addr;
7087 + regs->tnpc = addr+4;
7088 + return 2;
7089 + }
7090 + } while (0);
7091 +
7092 + do { /* PaX: unpatched PLT emulation step 1 */
7093 + unsigned int sethi, ba, nop;
7094 +
7095 + err = get_user(sethi, (unsigned int *)regs->tpc);
7096 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7097 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7098 +
7099 + if (err)
7100 + break;
7101 +
7102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7103 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7104 + nop == 0x01000000U)
7105 + {
7106 + unsigned long addr;
7107 + unsigned int save, call;
7108 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7109 +
7110 + if ((ba & 0xFFC00000U) == 0x30800000U)
7111 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7112 + else
7113 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7114 +
7115 + if (test_thread_flag(TIF_32BIT))
7116 + addr &= 0xFFFFFFFFUL;
7117 +
7118 + err = get_user(save, (unsigned int *)addr);
7119 + err |= get_user(call, (unsigned int *)(addr+4));
7120 + err |= get_user(nop, (unsigned int *)(addr+8));
7121 + if (err)
7122 + break;
7123 +
7124 +#ifdef CONFIG_PAX_DLRESOLVE
7125 + if (save == 0x9DE3BFA8U &&
7126 + (call & 0xC0000000U) == 0x40000000U &&
7127 + nop == 0x01000000U)
7128 + {
7129 + struct vm_area_struct *vma;
7130 + unsigned long call_dl_resolve;
7131 +
7132 + down_read(&current->mm->mmap_sem);
7133 + call_dl_resolve = current->mm->call_dl_resolve;
7134 + up_read(&current->mm->mmap_sem);
7135 + if (likely(call_dl_resolve))
7136 + goto emulate;
7137 +
7138 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7139 +
7140 + down_write(&current->mm->mmap_sem);
7141 + if (current->mm->call_dl_resolve) {
7142 + call_dl_resolve = current->mm->call_dl_resolve;
7143 + up_write(&current->mm->mmap_sem);
7144 + if (vma)
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + goto emulate;
7147 + }
7148 +
7149 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7150 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7151 + up_write(&current->mm->mmap_sem);
7152 + if (vma)
7153 + kmem_cache_free(vm_area_cachep, vma);
7154 + return 1;
7155 + }
7156 +
7157 + if (pax_insert_vma(vma, call_dl_resolve)) {
7158 + up_write(&current->mm->mmap_sem);
7159 + kmem_cache_free(vm_area_cachep, vma);
7160 + return 1;
7161 + }
7162 +
7163 + current->mm->call_dl_resolve = call_dl_resolve;
7164 + up_write(&current->mm->mmap_sem);
7165 +
7166 +emulate:
7167 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7168 + regs->tpc = call_dl_resolve;
7169 + regs->tnpc = addr+4;
7170 + return 3;
7171 + }
7172 +#endif
7173 +
7174 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7175 + if ((save & 0xFFC00000U) == 0x05000000U &&
7176 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7177 + nop == 0x01000000U)
7178 + {
7179 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180 + regs->u_regs[UREG_G2] = addr + 4;
7181 + addr = (save & 0x003FFFFFU) << 10;
7182 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7183 +
7184 + if (test_thread_flag(TIF_32BIT))
7185 + addr &= 0xFFFFFFFFUL;
7186 +
7187 + regs->tpc = addr;
7188 + regs->tnpc = addr+4;
7189 + return 3;
7190 + }
7191 +
7192 + /* PaX: 64-bit PLT stub */
7193 + err = get_user(sethi1, (unsigned int *)addr);
7194 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7195 + err |= get_user(or1, (unsigned int *)(addr+8));
7196 + err |= get_user(or2, (unsigned int *)(addr+12));
7197 + err |= get_user(sllx, (unsigned int *)(addr+16));
7198 + err |= get_user(add, (unsigned int *)(addr+20));
7199 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7200 + err |= get_user(nop, (unsigned int *)(addr+28));
7201 + if (err)
7202 + break;
7203 +
7204 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7205 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7206 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7207 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7208 + sllx == 0x89293020U &&
7209 + add == 0x8A010005U &&
7210 + jmpl == 0x89C14000U &&
7211 + nop == 0x01000000U)
7212 + {
7213 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7215 + regs->u_regs[UREG_G4] <<= 32;
7216 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7217 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7218 + regs->u_regs[UREG_G4] = addr + 24;
7219 + addr = regs->u_regs[UREG_G5];
7220 + regs->tpc = addr;
7221 + regs->tnpc = addr+4;
7222 + return 3;
7223 + }
7224 + }
7225 + } while (0);
7226 +
7227 +#ifdef CONFIG_PAX_DLRESOLVE
7228 + do { /* PaX: unpatched PLT emulation step 2 */
7229 + unsigned int save, call, nop;
7230 +
7231 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7232 + err |= get_user(call, (unsigned int *)regs->tpc);
7233 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7234 + if (err)
7235 + break;
7236 +
7237 + if (save == 0x9DE3BFA8U &&
7238 + (call & 0xC0000000U) == 0x40000000U &&
7239 + nop == 0x01000000U)
7240 + {
7241 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7242 +
7243 + if (test_thread_flag(TIF_32BIT))
7244 + dl_resolve &= 0xFFFFFFFFUL;
7245 +
7246 + regs->u_regs[UREG_RETPC] = regs->tpc;
7247 + regs->tpc = dl_resolve;
7248 + regs->tnpc = dl_resolve+4;
7249 + return 3;
7250 + }
7251 + } while (0);
7252 +#endif
7253 +
7254 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7255 + unsigned int sethi, ba, nop;
7256 +
7257 + err = get_user(sethi, (unsigned int *)regs->tpc);
7258 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7259 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7260 +
7261 + if (err)
7262 + break;
7263 +
7264 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7265 + (ba & 0xFFF00000U) == 0x30600000U &&
7266 + nop == 0x01000000U)
7267 + {
7268 + unsigned long addr;
7269 +
7270 + addr = (sethi & 0x003FFFFFU) << 10;
7271 + regs->u_regs[UREG_G1] = addr;
7272 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7273 +
7274 + if (test_thread_flag(TIF_32BIT))
7275 + addr &= 0xFFFFFFFFUL;
7276 +
7277 + regs->tpc = addr;
7278 + regs->tnpc = addr+4;
7279 + return 2;
7280 + }
7281 + } while (0);
7282 +
7283 +#endif
7284 +
7285 + return 1;
7286 +}
7287 +
7288 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7289 +{
7290 + unsigned long i;
7291 +
7292 + printk(KERN_ERR "PAX: bytes at PC: ");
7293 + for (i = 0; i < 8; i++) {
7294 + unsigned int c;
7295 + if (get_user(c, (unsigned int *)pc+i))
7296 + printk(KERN_CONT "???????? ");
7297 + else
7298 + printk(KERN_CONT "%08x ", c);
7299 + }
7300 + printk("\n");
7301 +}
7302 +#endif
7303 +
7304 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7305 {
7306 struct mm_struct *mm = current->mm;
7307 @@ -343,6 +797,29 @@ retry:
7308 if (!vma)
7309 goto bad_area;
7310
7311 +#ifdef CONFIG_PAX_PAGEEXEC
7312 + /* PaX: detect ITLB misses on non-exec pages */
7313 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7314 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7315 + {
7316 + if (address != regs->tpc)
7317 + goto good_area;
7318 +
7319 + up_read(&mm->mmap_sem);
7320 + switch (pax_handle_fetch_fault(regs)) {
7321 +
7322 +#ifdef CONFIG_PAX_EMUPLT
7323 + case 2:
7324 + case 3:
7325 + return;
7326 +#endif
7327 +
7328 + }
7329 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7330 + do_group_exit(SIGKILL);
7331 + }
7332 +#endif
7333 +
7334 /* Pure DTLB misses do not tell us whether the fault causing
7335 * load/store/atomic was a write or not, it only says that there
7336 * was no match. So in such a case we (carefully) read the
7337 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7338 index 07e1453..0a7d9e9 100644
7339 --- a/arch/sparc/mm/hugetlbpage.c
7340 +++ b/arch/sparc/mm/hugetlbpage.c
7341 @@ -67,7 +67,7 @@ full_search:
7342 }
7343 return -ENOMEM;
7344 }
7345 - if (likely(!vma || addr + len <= vma->vm_start)) {
7346 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7347 /*
7348 * Remember the place where we stopped the search:
7349 */
7350 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 /* make sure it can fit in the remaining address space */
7352 if (likely(addr > len)) {
7353 vma = find_vma(mm, addr-len);
7354 - if (!vma || addr <= vma->vm_start) {
7355 + if (check_heap_stack_gap(vma, addr - len, len)) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr-len);
7358 }
7359 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 if (unlikely(mm->mmap_base < len))
7361 goto bottomup;
7362
7363 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7364 + addr = mm->mmap_base - len;
7365
7366 do {
7367 + addr &= HPAGE_MASK;
7368 /*
7369 * Lookup failure means no vma is above this address,
7370 * else if new region fits below vma->vm_start,
7371 * return with success:
7372 */
7373 vma = find_vma(mm, addr);
7374 - if (likely(!vma || addr+len <= vma->vm_start)) {
7375 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr);
7378 }
7379 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 mm->cached_hole_size = vma->vm_start - addr;
7381
7382 /* try just below the current vma->vm_start */
7383 - addr = (vma->vm_start-len) & HPAGE_MASK;
7384 - } while (likely(len < vma->vm_start));
7385 + addr = skip_heap_stack_gap(vma, len);
7386 + } while (!IS_ERR_VALUE(addr));
7387
7388 bottomup:
7389 /*
7390 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7391 if (addr) {
7392 addr = ALIGN(addr, HPAGE_SIZE);
7393 vma = find_vma(mm, addr);
7394 - if (task_size - len >= addr &&
7395 - (!vma || addr + len <= vma->vm_start))
7396 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7397 return addr;
7398 }
7399 if (mm->get_unmapped_area == arch_get_unmapped_area)
7400 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7401 index c5f9021..7591bae 100644
7402 --- a/arch/sparc/mm/init_32.c
7403 +++ b/arch/sparc/mm/init_32.c
7404 @@ -315,6 +315,9 @@ extern void device_scan(void);
7405 pgprot_t PAGE_SHARED __read_mostly;
7406 EXPORT_SYMBOL(PAGE_SHARED);
7407
7408 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7409 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7410 +
7411 void __init paging_init(void)
7412 {
7413 switch(sparc_cpu_model) {
7414 @@ -343,17 +346,17 @@ void __init paging_init(void)
7415
7416 /* Initialize the protection map with non-constant, MMU dependent values. */
7417 protection_map[0] = PAGE_NONE;
7418 - protection_map[1] = PAGE_READONLY;
7419 - protection_map[2] = PAGE_COPY;
7420 - protection_map[3] = PAGE_COPY;
7421 + protection_map[1] = PAGE_READONLY_NOEXEC;
7422 + protection_map[2] = PAGE_COPY_NOEXEC;
7423 + protection_map[3] = PAGE_COPY_NOEXEC;
7424 protection_map[4] = PAGE_READONLY;
7425 protection_map[5] = PAGE_READONLY;
7426 protection_map[6] = PAGE_COPY;
7427 protection_map[7] = PAGE_COPY;
7428 protection_map[8] = PAGE_NONE;
7429 - protection_map[9] = PAGE_READONLY;
7430 - protection_map[10] = PAGE_SHARED;
7431 - protection_map[11] = PAGE_SHARED;
7432 + protection_map[9] = PAGE_READONLY_NOEXEC;
7433 + protection_map[10] = PAGE_SHARED_NOEXEC;
7434 + protection_map[11] = PAGE_SHARED_NOEXEC;
7435 protection_map[12] = PAGE_READONLY;
7436 protection_map[13] = PAGE_READONLY;
7437 protection_map[14] = PAGE_SHARED;
7438 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7439 index cbef74e..c38fead 100644
7440 --- a/arch/sparc/mm/srmmu.c
7441 +++ b/arch/sparc/mm/srmmu.c
7442 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7443 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7444 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7445 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7446 +
7447 +#ifdef CONFIG_PAX_PAGEEXEC
7448 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7449 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7450 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7451 +#endif
7452 +
7453 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7454 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7455
7456 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7457 index f4500c6..889656c 100644
7458 --- a/arch/tile/include/asm/atomic_64.h
7459 +++ b/arch/tile/include/asm/atomic_64.h
7460 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7461
7462 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7463
7464 +#define atomic64_read_unchecked(v) atomic64_read(v)
7465 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7466 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7467 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7468 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7469 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7470 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7471 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7472 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7473 +
7474 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7475 #define smp_mb__before_atomic_dec() smp_mb()
7476 #define smp_mb__after_atomic_dec() smp_mb()
7477 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7478 index 392e533..536b092 100644
7479 --- a/arch/tile/include/asm/cache.h
7480 +++ b/arch/tile/include/asm/cache.h
7481 @@ -15,11 +15,12 @@
7482 #ifndef _ASM_TILE_CACHE_H
7483 #define _ASM_TILE_CACHE_H
7484
7485 +#include <linux/const.h>
7486 #include <arch/chip.h>
7487
7488 /* bytes per L1 data cache line */
7489 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7490 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7491 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7492
7493 /* bytes per L2 cache line */
7494 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7495 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7496 index ef34d2c..d6ce60c 100644
7497 --- a/arch/tile/include/asm/uaccess.h
7498 +++ b/arch/tile/include/asm/uaccess.h
7499 @@ -361,9 +361,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7500 const void __user *from,
7501 unsigned long n)
7502 {
7503 - int sz = __compiletime_object_size(to);
7504 + size_t sz = __compiletime_object_size(to);
7505
7506 - if (likely(sz == -1 || sz >= n))
7507 + if (likely(sz == (size_t)-1 || sz >= n))
7508 n = _copy_from_user(to, from, n);
7509 else
7510 copy_from_user_overflow();
7511 diff --git a/arch/um/Makefile b/arch/um/Makefile
7512 index 55c0661..86ad413 100644
7513 --- a/arch/um/Makefile
7514 +++ b/arch/um/Makefile
7515 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7516 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7517 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7518
7519 +ifdef CONSTIFY_PLUGIN
7520 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7521 +endif
7522 +
7523 #This will adjust *FLAGS accordingly to the platform.
7524 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7525
7526 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7527 index 19e1bdd..3665b77 100644
7528 --- a/arch/um/include/asm/cache.h
7529 +++ b/arch/um/include/asm/cache.h
7530 @@ -1,6 +1,7 @@
7531 #ifndef __UM_CACHE_H
7532 #define __UM_CACHE_H
7533
7534 +#include <linux/const.h>
7535
7536 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7537 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7538 @@ -12,6 +13,6 @@
7539 # define L1_CACHE_SHIFT 5
7540 #endif
7541
7542 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7543 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544
7545 #endif
7546 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7547 index 6c03acd..a5e0215 100644
7548 --- a/arch/um/include/asm/kmap_types.h
7549 +++ b/arch/um/include/asm/kmap_types.h
7550 @@ -23,6 +23,7 @@ enum km_type {
7551 KM_IRQ1,
7552 KM_SOFTIRQ0,
7553 KM_SOFTIRQ1,
7554 + KM_CLEARPAGE,
7555 KM_TYPE_NR
7556 };
7557
7558 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7559 index 7cfc3ce..cbd1a58 100644
7560 --- a/arch/um/include/asm/page.h
7561 +++ b/arch/um/include/asm/page.h
7562 @@ -14,6 +14,9 @@
7563 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7564 #define PAGE_MASK (~(PAGE_SIZE-1))
7565
7566 +#define ktla_ktva(addr) (addr)
7567 +#define ktva_ktla(addr) (addr)
7568 +
7569 #ifndef __ASSEMBLY__
7570
7571 struct page;
7572 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7573 index 0032f92..cd151e0 100644
7574 --- a/arch/um/include/asm/pgtable-3level.h
7575 +++ b/arch/um/include/asm/pgtable-3level.h
7576 @@ -58,6 +58,7 @@
7577 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7578 #define pud_populate(mm, pud, pmd) \
7579 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7580 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7581
7582 #ifdef CONFIG_64BIT
7583 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7584 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7585 index 2b73ded..804f540 100644
7586 --- a/arch/um/kernel/process.c
7587 +++ b/arch/um/kernel/process.c
7588 @@ -404,22 +404,6 @@ int singlestepping(void * t)
7589 return 2;
7590 }
7591
7592 -/*
7593 - * Only x86 and x86_64 have an arch_align_stack().
7594 - * All other arches have "#define arch_align_stack(x) (x)"
7595 - * in their asm/system.h
7596 - * As this is included in UML from asm-um/system-generic.h,
7597 - * we can use it to behave as the subarch does.
7598 - */
7599 -#ifndef arch_align_stack
7600 -unsigned long arch_align_stack(unsigned long sp)
7601 -{
7602 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7603 - sp -= get_random_int() % 8192;
7604 - return sp & ~0xf;
7605 -}
7606 -#endif
7607 -
7608 unsigned long get_wchan(struct task_struct *p)
7609 {
7610 unsigned long stack_page, sp, ip;
7611 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7612 index ad8f795..2c7eec6 100644
7613 --- a/arch/unicore32/include/asm/cache.h
7614 +++ b/arch/unicore32/include/asm/cache.h
7615 @@ -12,8 +12,10 @@
7616 #ifndef __UNICORE_CACHE_H__
7617 #define __UNICORE_CACHE_H__
7618
7619 -#define L1_CACHE_SHIFT (5)
7620 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7621 +#include <linux/const.h>
7622 +
7623 +#define L1_CACHE_SHIFT 5
7624 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7625
7626 /*
7627 * Memory returned by kmalloc() may be used for DMA, so we must make
7628 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7629 index c9866b0..fe53aef 100644
7630 --- a/arch/x86/Kconfig
7631 +++ b/arch/x86/Kconfig
7632 @@ -229,7 +229,7 @@ config X86_HT
7633
7634 config X86_32_LAZY_GS
7635 def_bool y
7636 - depends on X86_32 && !CC_STACKPROTECTOR
7637 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7638
7639 config ARCH_HWEIGHT_CFLAGS
7640 string
7641 @@ -1042,7 +1042,7 @@ choice
7642
7643 config NOHIGHMEM
7644 bool "off"
7645 - depends on !X86_NUMAQ
7646 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7647 ---help---
7648 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7649 However, the address space of 32-bit x86 processors is only 4
7650 @@ -1079,7 +1079,7 @@ config NOHIGHMEM
7651
7652 config HIGHMEM4G
7653 bool "4GB"
7654 - depends on !X86_NUMAQ
7655 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7656 ---help---
7657 Select this if you have a 32-bit processor and between 1 and 4
7658 gigabytes of physical RAM.
7659 @@ -1133,7 +1133,7 @@ config PAGE_OFFSET
7660 hex
7661 default 0xB0000000 if VMSPLIT_3G_OPT
7662 default 0x80000000 if VMSPLIT_2G
7663 - default 0x78000000 if VMSPLIT_2G_OPT
7664 + default 0x70000000 if VMSPLIT_2G_OPT
7665 default 0x40000000 if VMSPLIT_1G
7666 default 0xC0000000
7667 depends on X86_32
7668 @@ -1523,6 +1523,7 @@ config SECCOMP
7669
7670 config CC_STACKPROTECTOR
7671 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7672 + depends on X86_64 || !PAX_MEMORY_UDEREF
7673 ---help---
7674 This option turns on the -fstack-protector GCC feature. This
7675 feature puts, at the beginning of functions, a canary value on
7676 @@ -1580,6 +1581,7 @@ config KEXEC_JUMP
7677 config PHYSICAL_START
7678 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7679 default "0x1000000"
7680 + range 0x400000 0x40000000
7681 ---help---
7682 This gives the physical address where the kernel is loaded.
7683
7684 @@ -1643,6 +1645,7 @@ config X86_NEED_RELOCS
7685 config PHYSICAL_ALIGN
7686 hex "Alignment value to which kernel should be aligned" if X86_32
7687 default "0x1000000"
7688 + range 0x400000 0x1000000 if PAX_KERNEXEC
7689 range 0x2000 0x1000000
7690 ---help---
7691 This value puts the alignment restrictions on physical address
7692 @@ -1674,9 +1677,10 @@ config HOTPLUG_CPU
7693 Say N if you want to disable CPU hotplug.
7694
7695 config COMPAT_VDSO
7696 - def_bool y
7697 + def_bool n
7698 prompt "Compat VDSO support"
7699 depends on X86_32 || IA32_EMULATION
7700 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7701 ---help---
7702 Map the 32-bit VDSO to the predictable old-style address too.
7703
7704 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7705 index 706e12e..62e4feb 100644
7706 --- a/arch/x86/Kconfig.cpu
7707 +++ b/arch/x86/Kconfig.cpu
7708 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7709
7710 config X86_F00F_BUG
7711 def_bool y
7712 - depends on M586MMX || M586TSC || M586 || M486 || M386
7713 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7714
7715 config X86_INVD_BUG
7716 def_bool y
7717 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7718
7719 config X86_ALIGNMENT_16
7720 def_bool y
7721 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7722 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7723
7724 config X86_INTEL_USERCOPY
7725 def_bool y
7726 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7727 # generates cmov.
7728 config X86_CMOV
7729 def_bool y
7730 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7731 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7732
7733 config X86_MINIMUM_CPU_FAMILY
7734 int
7735 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7736 index e46c214..ab62fd1 100644
7737 --- a/arch/x86/Kconfig.debug
7738 +++ b/arch/x86/Kconfig.debug
7739 @@ -84,7 +84,7 @@ config X86_PTDUMP
7740 config DEBUG_RODATA
7741 bool "Write protect kernel read-only data structures"
7742 default y
7743 - depends on DEBUG_KERNEL
7744 + depends on DEBUG_KERNEL && BROKEN
7745 ---help---
7746 Mark the kernel read-only data as write-protected in the pagetables,
7747 in order to catch accidental (and incorrect) writes to such const
7748 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7749
7750 config DEBUG_SET_MODULE_RONX
7751 bool "Set loadable kernel module data as NX and text as RO"
7752 - depends on MODULES
7753 + depends on MODULES && BROKEN
7754 ---help---
7755 This option helps catch unintended modifications to loadable
7756 kernel module's text and read-only data. It also prevents execution
7757 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7758
7759 config DEBUG_STRICT_USER_COPY_CHECKS
7760 bool "Strict copy size checks"
7761 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7762 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7763 ---help---
7764 Enabling this option turns a certain set of sanity checks for user
7765 copy operations into compile time failures.
7766 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7767 index b1c611e..2c1a823 100644
7768 --- a/arch/x86/Makefile
7769 +++ b/arch/x86/Makefile
7770 @@ -46,6 +46,7 @@ else
7771 UTS_MACHINE := x86_64
7772 CHECKFLAGS += -D__x86_64__ -m64
7773
7774 + biarch := $(call cc-option,-m64)
7775 KBUILD_AFLAGS += -m64
7776 KBUILD_CFLAGS += -m64
7777
7778 @@ -222,3 +223,12 @@ define archhelp
7779 echo ' FDARGS="..." arguments for the booted kernel'
7780 echo ' FDINITRD=file initrd for the booted kernel'
7781 endef
7782 +
7783 +define OLD_LD
7784 +
7785 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7786 +*** Please upgrade your binutils to 2.18 or newer
7787 +endef
7788 +
7789 +archprepare:
7790 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7791 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7792 index 5a747dd..ff7b12c 100644
7793 --- a/arch/x86/boot/Makefile
7794 +++ b/arch/x86/boot/Makefile
7795 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7796 $(call cc-option, -fno-stack-protector) \
7797 $(call cc-option, -mpreferred-stack-boundary=2)
7798 KBUILD_CFLAGS += $(call cc-option, -m32)
7799 +ifdef CONSTIFY_PLUGIN
7800 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7801 +endif
7802 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7803 GCOV_PROFILE := n
7804
7805 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7806 index 878e4b9..20537ab 100644
7807 --- a/arch/x86/boot/bitops.h
7808 +++ b/arch/x86/boot/bitops.h
7809 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7810 u8 v;
7811 const u32 *p = (const u32 *)addr;
7812
7813 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7814 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7815 return v;
7816 }
7817
7818 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7819
7820 static inline void set_bit(int nr, void *addr)
7821 {
7822 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7823 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7824 }
7825
7826 #endif /* BOOT_BITOPS_H */
7827 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7828 index 18997e5..83d9c67 100644
7829 --- a/arch/x86/boot/boot.h
7830 +++ b/arch/x86/boot/boot.h
7831 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7832 static inline u16 ds(void)
7833 {
7834 u16 seg;
7835 - asm("movw %%ds,%0" : "=rm" (seg));
7836 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7837 return seg;
7838 }
7839
7840 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7841 static inline int memcmp(const void *s1, const void *s2, size_t len)
7842 {
7843 u8 diff;
7844 - asm("repe; cmpsb; setnz %0"
7845 + asm volatile("repe; cmpsb; setnz %0"
7846 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7847 return diff;
7848 }
7849 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7850 index e398bb5..3a382ca 100644
7851 --- a/arch/x86/boot/compressed/Makefile
7852 +++ b/arch/x86/boot/compressed/Makefile
7853 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7854 KBUILD_CFLAGS += $(cflags-y)
7855 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7856 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7857 +ifdef CONSTIFY_PLUGIN
7858 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7859 +endif
7860
7861 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7862 GCOV_PROFILE := n
7863 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7864 index 0cdfc0d..6e79437 100644
7865 --- a/arch/x86/boot/compressed/eboot.c
7866 +++ b/arch/x86/boot/compressed/eboot.c
7867 @@ -122,7 +122,6 @@ again:
7868 *addr = max_addr;
7869 }
7870
7871 -free_pool:
7872 efi_call_phys1(sys_table->boottime->free_pool, map);
7873
7874 fail:
7875 @@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7876 if (i == map_size / desc_size)
7877 status = EFI_NOT_FOUND;
7878
7879 -free_pool:
7880 efi_call_phys1(sys_table->boottime->free_pool, map);
7881 fail:
7882 return status;
7883 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7884 index c85e3ac..6f5aa80 100644
7885 --- a/arch/x86/boot/compressed/head_32.S
7886 +++ b/arch/x86/boot/compressed/head_32.S
7887 @@ -106,7 +106,7 @@ preferred_addr:
7888 notl %eax
7889 andl %eax, %ebx
7890 #else
7891 - movl $LOAD_PHYSICAL_ADDR, %ebx
7892 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7893 #endif
7894
7895 /* Target address to relocate to for decompression */
7896 @@ -192,7 +192,7 @@ relocated:
7897 * and where it was actually loaded.
7898 */
7899 movl %ebp, %ebx
7900 - subl $LOAD_PHYSICAL_ADDR, %ebx
7901 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7902 jz 2f /* Nothing to be done if loaded at compiled addr. */
7903 /*
7904 * Process relocations.
7905 @@ -200,8 +200,7 @@ relocated:
7906
7907 1: subl $4, %edi
7908 movl (%edi), %ecx
7909 - testl %ecx, %ecx
7910 - jz 2f
7911 + jecxz 2f
7912 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7913 jmp 1b
7914 2:
7915 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7916 index 87e03a1..0d94c76 100644
7917 --- a/arch/x86/boot/compressed/head_64.S
7918 +++ b/arch/x86/boot/compressed/head_64.S
7919 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7920 notl %eax
7921 andl %eax, %ebx
7922 #else
7923 - movl $LOAD_PHYSICAL_ADDR, %ebx
7924 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7925 #endif
7926
7927 /* Target address to relocate to for decompression */
7928 @@ -263,7 +263,7 @@ preferred_addr:
7929 notq %rax
7930 andq %rax, %rbp
7931 #else
7932 - movq $LOAD_PHYSICAL_ADDR, %rbp
7933 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7934 #endif
7935
7936 /* Target address to relocate to for decompression */
7937 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7938 index 7116dcb..d9ae1d7 100644
7939 --- a/arch/x86/boot/compressed/misc.c
7940 +++ b/arch/x86/boot/compressed/misc.c
7941 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7942 case PT_LOAD:
7943 #ifdef CONFIG_RELOCATABLE
7944 dest = output;
7945 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7946 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7947 #else
7948 dest = (void *)(phdr->p_paddr);
7949 #endif
7950 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7951 error("Destination address too large");
7952 #endif
7953 #ifndef CONFIG_RELOCATABLE
7954 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7955 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7956 error("Wrong destination address");
7957 #endif
7958
7959 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7960 index 4d3ff03..e4972ff 100644
7961 --- a/arch/x86/boot/cpucheck.c
7962 +++ b/arch/x86/boot/cpucheck.c
7963 @@ -74,7 +74,7 @@ static int has_fpu(void)
7964 u16 fcw = -1, fsw = -1;
7965 u32 cr0;
7966
7967 - asm("movl %%cr0,%0" : "=r" (cr0));
7968 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7969 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7970 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7971 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7972 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7973 {
7974 u32 f0, f1;
7975
7976 - asm("pushfl ; "
7977 + asm volatile("pushfl ; "
7978 "pushfl ; "
7979 "popl %0 ; "
7980 "movl %0,%1 ; "
7981 @@ -115,7 +115,7 @@ static void get_flags(void)
7982 set_bit(X86_FEATURE_FPU, cpu.flags);
7983
7984 if (has_eflag(X86_EFLAGS_ID)) {
7985 - asm("cpuid"
7986 + asm volatile("cpuid"
7987 : "=a" (max_intel_level),
7988 "=b" (cpu_vendor[0]),
7989 "=d" (cpu_vendor[1]),
7990 @@ -124,7 +124,7 @@ static void get_flags(void)
7991
7992 if (max_intel_level >= 0x00000001 &&
7993 max_intel_level <= 0x0000ffff) {
7994 - asm("cpuid"
7995 + asm volatile("cpuid"
7996 : "=a" (tfms),
7997 "=c" (cpu.flags[4]),
7998 "=d" (cpu.flags[0])
7999 @@ -136,7 +136,7 @@ static void get_flags(void)
8000 cpu.model += ((tfms >> 16) & 0xf) << 4;
8001 }
8002
8003 - asm("cpuid"
8004 + asm volatile("cpuid"
8005 : "=a" (max_amd_level)
8006 : "a" (0x80000000)
8007 : "ebx", "ecx", "edx");
8008 @@ -144,7 +144,7 @@ static void get_flags(void)
8009 if (max_amd_level >= 0x80000001 &&
8010 max_amd_level <= 0x8000ffff) {
8011 u32 eax = 0x80000001;
8012 - asm("cpuid"
8013 + asm volatile("cpuid"
8014 : "+a" (eax),
8015 "=c" (cpu.flags[6]),
8016 "=d" (cpu.flags[1])
8017 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8018 u32 ecx = MSR_K7_HWCR;
8019 u32 eax, edx;
8020
8021 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8022 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8023 eax &= ~(1 << 15);
8024 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8025 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8026
8027 get_flags(); /* Make sure it really did something */
8028 err = check_flags();
8029 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8030 u32 ecx = MSR_VIA_FCR;
8031 u32 eax, edx;
8032
8033 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8034 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8035 eax |= (1<<1)|(1<<7);
8036 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8037 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8038
8039 set_bit(X86_FEATURE_CX8, cpu.flags);
8040 err = check_flags();
8041 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8042 u32 eax, edx;
8043 u32 level = 1;
8044
8045 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8046 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8047 - asm("cpuid"
8048 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8049 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8050 + asm volatile("cpuid"
8051 : "+a" (level), "=d" (cpu.flags[0])
8052 : : "ecx", "ebx");
8053 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8054 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8055
8056 err = check_flags();
8057 }
8058 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8059 index f1bbeeb..aff09cb 100644
8060 --- a/arch/x86/boot/header.S
8061 +++ b/arch/x86/boot/header.S
8062 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8063 # single linked list of
8064 # struct setup_data
8065
8066 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8067 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8068
8069 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8070 #define VO_INIT_SIZE (VO__end - VO__text)
8071 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8072 index db75d07..8e6d0af 100644
8073 --- a/arch/x86/boot/memory.c
8074 +++ b/arch/x86/boot/memory.c
8075 @@ -19,7 +19,7 @@
8076
8077 static int detect_memory_e820(void)
8078 {
8079 - int count = 0;
8080 + unsigned int count = 0;
8081 struct biosregs ireg, oreg;
8082 struct e820entry *desc = boot_params.e820_map;
8083 static struct e820entry buf; /* static so it is zeroed */
8084 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8085 index 11e8c6e..fdbb1ed 100644
8086 --- a/arch/x86/boot/video-vesa.c
8087 +++ b/arch/x86/boot/video-vesa.c
8088 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8089
8090 boot_params.screen_info.vesapm_seg = oreg.es;
8091 boot_params.screen_info.vesapm_off = oreg.di;
8092 + boot_params.screen_info.vesapm_size = oreg.cx;
8093 }
8094
8095 /*
8096 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8097 index 43eda28..5ab5fdb 100644
8098 --- a/arch/x86/boot/video.c
8099 +++ b/arch/x86/boot/video.c
8100 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8101 static unsigned int get_entry(void)
8102 {
8103 char entry_buf[4];
8104 - int i, len = 0;
8105 + unsigned int i, len = 0;
8106 int key;
8107 unsigned int v;
8108
8109 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8110 index 5b577d5..3c1fed4 100644
8111 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8112 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8113 @@ -8,6 +8,8 @@
8114 * including this sentence is retained in full.
8115 */
8116
8117 +#include <asm/alternative-asm.h>
8118 +
8119 .extern crypto_ft_tab
8120 .extern crypto_it_tab
8121 .extern crypto_fl_tab
8122 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8123 je B192; \
8124 leaq 32(r9),r9;
8125
8126 +#define ret pax_force_retaddr 0, 1; ret
8127 +
8128 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8129 movq r1,r2; \
8130 movq r3,r4; \
8131 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8132 index 3470624..201259d 100644
8133 --- a/arch/x86/crypto/aesni-intel_asm.S
8134 +++ b/arch/x86/crypto/aesni-intel_asm.S
8135 @@ -31,6 +31,7 @@
8136
8137 #include <linux/linkage.h>
8138 #include <asm/inst.h>
8139 +#include <asm/alternative-asm.h>
8140
8141 #ifdef __x86_64__
8142 .data
8143 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8144 pop %r14
8145 pop %r13
8146 pop %r12
8147 + pax_force_retaddr 0, 1
8148 ret
8149 +ENDPROC(aesni_gcm_dec)
8150
8151
8152 /*****************************************************************************
8153 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8154 pop %r14
8155 pop %r13
8156 pop %r12
8157 + pax_force_retaddr 0, 1
8158 ret
8159 +ENDPROC(aesni_gcm_enc)
8160
8161 #endif
8162
8163 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8164 pxor %xmm1, %xmm0
8165 movaps %xmm0, (TKEYP)
8166 add $0x10, TKEYP
8167 + pax_force_retaddr_bts
8168 ret
8169
8170 .align 4
8171 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8172 shufps $0b01001110, %xmm2, %xmm1
8173 movaps %xmm1, 0x10(TKEYP)
8174 add $0x20, TKEYP
8175 + pax_force_retaddr_bts
8176 ret
8177
8178 .align 4
8179 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8180
8181 movaps %xmm0, (TKEYP)
8182 add $0x10, TKEYP
8183 + pax_force_retaddr_bts
8184 ret
8185
8186 .align 4
8187 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8188 pxor %xmm1, %xmm2
8189 movaps %xmm2, (TKEYP)
8190 add $0x10, TKEYP
8191 + pax_force_retaddr_bts
8192 ret
8193
8194 /*
8195 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8196 #ifndef __x86_64__
8197 popl KEYP
8198 #endif
8199 + pax_force_retaddr 0, 1
8200 ret
8201 +ENDPROC(aesni_set_key)
8202
8203 /*
8204 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8205 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8206 popl KLEN
8207 popl KEYP
8208 #endif
8209 + pax_force_retaddr 0, 1
8210 ret
8211 +ENDPROC(aesni_enc)
8212
8213 /*
8214 * _aesni_enc1: internal ABI
8215 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8216 AESENC KEY STATE
8217 movaps 0x70(TKEYP), KEY
8218 AESENCLAST KEY STATE
8219 + pax_force_retaddr_bts
8220 ret
8221
8222 /*
8223 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8224 AESENCLAST KEY STATE2
8225 AESENCLAST KEY STATE3
8226 AESENCLAST KEY STATE4
8227 + pax_force_retaddr_bts
8228 ret
8229
8230 /*
8231 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8232 popl KLEN
8233 popl KEYP
8234 #endif
8235 + pax_force_retaddr 0, 1
8236 ret
8237 +ENDPROC(aesni_dec)
8238
8239 /*
8240 * _aesni_dec1: internal ABI
8241 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8242 AESDEC KEY STATE
8243 movaps 0x70(TKEYP), KEY
8244 AESDECLAST KEY STATE
8245 + pax_force_retaddr_bts
8246 ret
8247
8248 /*
8249 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8250 AESDECLAST KEY STATE2
8251 AESDECLAST KEY STATE3
8252 AESDECLAST KEY STATE4
8253 + pax_force_retaddr_bts
8254 ret
8255
8256 /*
8257 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8258 popl KEYP
8259 popl LEN
8260 #endif
8261 + pax_force_retaddr 0, 1
8262 ret
8263 +ENDPROC(aesni_ecb_enc)
8264
8265 /*
8266 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8267 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8268 popl KEYP
8269 popl LEN
8270 #endif
8271 + pax_force_retaddr 0, 1
8272 ret
8273 +ENDPROC(aesni_ecb_dec)
8274
8275 /*
8276 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8277 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8278 popl LEN
8279 popl IVP
8280 #endif
8281 + pax_force_retaddr 0, 1
8282 ret
8283 +ENDPROC(aesni_cbc_enc)
8284
8285 /*
8286 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8287 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8288 popl LEN
8289 popl IVP
8290 #endif
8291 + pax_force_retaddr 0, 1
8292 ret
8293 +ENDPROC(aesni_cbc_dec)
8294
8295 #ifdef __x86_64__
8296 .align 16
8297 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8298 mov $1, TCTR_LOW
8299 MOVQ_R64_XMM TCTR_LOW INC
8300 MOVQ_R64_XMM CTR TCTR_LOW
8301 + pax_force_retaddr_bts
8302 ret
8303
8304 /*
8305 @@ -2554,6 +2582,7 @@ _aesni_inc:
8306 .Linc_low:
8307 movaps CTR, IV
8308 PSHUFB_XMM BSWAP_MASK IV
8309 + pax_force_retaddr_bts
8310 ret
8311
8312 /*
8313 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8314 .Lctr_enc_ret:
8315 movups IV, (IVP)
8316 .Lctr_enc_just_ret:
8317 + pax_force_retaddr 0, 1
8318 ret
8319 +ENDPROC(aesni_ctr_enc)
8320 #endif
8321 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8322 index 391d245..67f35c2 100644
8323 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8324 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8325 @@ -20,6 +20,8 @@
8326 *
8327 */
8328
8329 +#include <asm/alternative-asm.h>
8330 +
8331 .file "blowfish-x86_64-asm.S"
8332 .text
8333
8334 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8335 jnz __enc_xor;
8336
8337 write_block();
8338 + pax_force_retaddr 0, 1
8339 ret;
8340 __enc_xor:
8341 xor_block();
8342 + pax_force_retaddr 0, 1
8343 ret;
8344
8345 .align 8
8346 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8347
8348 movq %r11, %rbp;
8349
8350 + pax_force_retaddr 0, 1
8351 ret;
8352
8353 /**********************************************************************
8354 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8355
8356 popq %rbx;
8357 popq %rbp;
8358 + pax_force_retaddr 0, 1
8359 ret;
8360
8361 __enc_xor4:
8362 @@ -349,6 +355,7 @@ __enc_xor4:
8363
8364 popq %rbx;
8365 popq %rbp;
8366 + pax_force_retaddr 0, 1
8367 ret;
8368
8369 .align 8
8370 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8371 popq %rbx;
8372 popq %rbp;
8373
8374 + pax_force_retaddr 0, 1
8375 ret;
8376
8377 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8378 index 0b33743..7a56206 100644
8379 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8380 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8381 @@ -20,6 +20,8 @@
8382 *
8383 */
8384
8385 +#include <asm/alternative-asm.h>
8386 +
8387 .file "camellia-x86_64-asm_64.S"
8388 .text
8389
8390 @@ -229,12 +231,14 @@ __enc_done:
8391 enc_outunpack(mov, RT1);
8392
8393 movq RRBP, %rbp;
8394 + pax_force_retaddr 0, 1
8395 ret;
8396
8397 __enc_xor:
8398 enc_outunpack(xor, RT1);
8399
8400 movq RRBP, %rbp;
8401 + pax_force_retaddr 0, 1
8402 ret;
8403
8404 .global camellia_dec_blk;
8405 @@ -275,6 +279,7 @@ __dec_rounds16:
8406 dec_outunpack();
8407
8408 movq RRBP, %rbp;
8409 + pax_force_retaddr 0, 1
8410 ret;
8411
8412 /**********************************************************************
8413 @@ -468,6 +473,7 @@ __enc2_done:
8414
8415 movq RRBP, %rbp;
8416 popq %rbx;
8417 + pax_force_retaddr 0, 1
8418 ret;
8419
8420 __enc2_xor:
8421 @@ -475,6 +481,7 @@ __enc2_xor:
8422
8423 movq RRBP, %rbp;
8424 popq %rbx;
8425 + pax_force_retaddr 0, 1
8426 ret;
8427
8428 .global camellia_dec_blk_2way;
8429 @@ -517,4 +524,5 @@ __dec2_rounds16:
8430
8431 movq RRBP, %rbp;
8432 movq RXOR, %rbx;
8433 + pax_force_retaddr 0, 1
8434 ret;
8435 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8436 index 6214a9b..1f4fc9a 100644
8437 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8438 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8439 @@ -1,3 +1,5 @@
8440 +#include <asm/alternative-asm.h>
8441 +
8442 # enter ECRYPT_encrypt_bytes
8443 .text
8444 .p2align 5
8445 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8446 add %r11,%rsp
8447 mov %rdi,%rax
8448 mov %rsi,%rdx
8449 + pax_force_retaddr 0, 1
8450 ret
8451 # bytesatleast65:
8452 ._bytesatleast65:
8453 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8454 add %r11,%rsp
8455 mov %rdi,%rax
8456 mov %rsi,%rdx
8457 + pax_force_retaddr
8458 ret
8459 # enter ECRYPT_ivsetup
8460 .text
8461 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8462 add %r11,%rsp
8463 mov %rdi,%rax
8464 mov %rsi,%rdx
8465 + pax_force_retaddr
8466 ret
8467 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8468 index 3ee1ff0..cbc568b 100644
8469 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8470 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8471 @@ -24,6 +24,8 @@
8472 *
8473 */
8474
8475 +#include <asm/alternative-asm.h>
8476 +
8477 .file "serpent-sse2-x86_64-asm_64.S"
8478 .text
8479
8480 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8481 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8482 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8483
8484 + pax_force_retaddr
8485 ret;
8486
8487 __enc_xor8:
8488 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8489 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8490
8491 + pax_force_retaddr
8492 ret;
8493
8494 .align 8
8495 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8496 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8497 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8498
8499 + pax_force_retaddr
8500 ret;
8501 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8502 index b2c2f57..8470cab 100644
8503 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8504 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8505 @@ -28,6 +28,8 @@
8506 * (at your option) any later version.
8507 */
8508
8509 +#include <asm/alternative-asm.h>
8510 +
8511 #define CTX %rdi // arg1
8512 #define BUF %rsi // arg2
8513 #define CNT %rdx // arg3
8514 @@ -104,6 +106,7 @@
8515 pop %r12
8516 pop %rbp
8517 pop %rbx
8518 + pax_force_retaddr 0, 1
8519 ret
8520
8521 .size \name, .-\name
8522 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8523 index 5b012a2..36d5364 100644
8524 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8525 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8526 @@ -20,6 +20,8 @@
8527 *
8528 */
8529
8530 +#include <asm/alternative-asm.h>
8531 +
8532 .file "twofish-x86_64-asm-3way.S"
8533 .text
8534
8535 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8536 popq %r13;
8537 popq %r14;
8538 popq %r15;
8539 + pax_force_retaddr 0, 1
8540 ret;
8541
8542 __enc_xor3:
8543 @@ -271,6 +274,7 @@ __enc_xor3:
8544 popq %r13;
8545 popq %r14;
8546 popq %r15;
8547 + pax_force_retaddr 0, 1
8548 ret;
8549
8550 .global twofish_dec_blk_3way
8551 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8552 popq %r13;
8553 popq %r14;
8554 popq %r15;
8555 + pax_force_retaddr 0, 1
8556 ret;
8557
8558 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8559 index 7bcf3fc..f53832f 100644
8560 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8561 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8562 @@ -21,6 +21,7 @@
8563 .text
8564
8565 #include <asm/asm-offsets.h>
8566 +#include <asm/alternative-asm.h>
8567
8568 #define a_offset 0
8569 #define b_offset 4
8570 @@ -268,6 +269,7 @@ twofish_enc_blk:
8571
8572 popq R1
8573 movq $1,%rax
8574 + pax_force_retaddr 0, 1
8575 ret
8576
8577 twofish_dec_blk:
8578 @@ -319,4 +321,5 @@ twofish_dec_blk:
8579
8580 popq R1
8581 movq $1,%rax
8582 + pax_force_retaddr 0, 1
8583 ret
8584 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8585 index 07b3a68..bd2a388 100644
8586 --- a/arch/x86/ia32/ia32_aout.c
8587 +++ b/arch/x86/ia32/ia32_aout.c
8588 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8589 unsigned long dump_start, dump_size;
8590 struct user32 dump;
8591
8592 + memset(&dump, 0, sizeof(dump));
8593 +
8594 fs = get_fs();
8595 set_fs(KERNEL_DS);
8596 has_dumped = 1;
8597 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8598 index 4f5bfac..e1ef0d3 100644
8599 --- a/arch/x86/ia32/ia32_signal.c
8600 +++ b/arch/x86/ia32/ia32_signal.c
8601 @@ -168,7 +168,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8602 }
8603 seg = get_fs();
8604 set_fs(KERNEL_DS);
8605 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8606 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8607 set_fs(seg);
8608 if (ret >= 0 && uoss_ptr) {
8609 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8610 @@ -369,7 +369,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8611 */
8612 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8613 size_t frame_size,
8614 - void **fpstate)
8615 + void __user **fpstate)
8616 {
8617 unsigned long sp;
8618
8619 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8620
8621 if (used_math()) {
8622 sp = sp - sig_xstate_ia32_size;
8623 - *fpstate = (struct _fpstate_ia32 *) sp;
8624 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8625 if (save_i387_xstate_ia32(*fpstate) < 0)
8626 return (void __user *) -1L;
8627 }
8628 @@ -398,7 +398,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8629 sp -= frame_size;
8630 /* Align the stack pointer according to the i386 ABI,
8631 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8632 - sp = ((sp + 4) & -16ul) - 4;
8633 + sp = ((sp - 12) & -16ul) - 4;
8634 return (void __user *) sp;
8635 }
8636
8637 @@ -456,7 +456,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8638 * These are actually not used anymore, but left because some
8639 * gdb versions depend on them as a marker.
8640 */
8641 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8642 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8643 } put_user_catch(err);
8644
8645 if (err)
8646 @@ -498,7 +498,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8647 0xb8,
8648 __NR_ia32_rt_sigreturn,
8649 0x80cd,
8650 - 0,
8651 + 0
8652 };
8653
8654 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8655 @@ -528,16 +528,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8656
8657 if (ka->sa.sa_flags & SA_RESTORER)
8658 restorer = ka->sa.sa_restorer;
8659 + else if (current->mm->context.vdso)
8660 + /* Return stub is in 32bit vsyscall page */
8661 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8662 else
8663 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8664 - rt_sigreturn);
8665 + restorer = &frame->retcode;
8666 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8667
8668 /*
8669 * Not actually used anymore, but left because some gdb
8670 * versions need it.
8671 */
8672 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8673 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8674 } put_user_catch(err);
8675
8676 if (err)
8677 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8678 index e3e7340..05ed805 100644
8679 --- a/arch/x86/ia32/ia32entry.S
8680 +++ b/arch/x86/ia32/ia32entry.S
8681 @@ -13,8 +13,10 @@
8682 #include <asm/thread_info.h>
8683 #include <asm/segment.h>
8684 #include <asm/irqflags.h>
8685 +#include <asm/pgtable.h>
8686 #include <linux/linkage.h>
8687 #include <linux/err.h>
8688 +#include <asm/alternative-asm.h>
8689
8690 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8691 #include <linux/elf-em.h>
8692 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8693 ENDPROC(native_irq_enable_sysexit)
8694 #endif
8695
8696 + .macro pax_enter_kernel_user
8697 + pax_set_fptr_mask
8698 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8699 + call pax_enter_kernel_user
8700 +#endif
8701 + .endm
8702 +
8703 + .macro pax_exit_kernel_user
8704 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8705 + call pax_exit_kernel_user
8706 +#endif
8707 +#ifdef CONFIG_PAX_RANDKSTACK
8708 + pushq %rax
8709 + pushq %r11
8710 + call pax_randomize_kstack
8711 + popq %r11
8712 + popq %rax
8713 +#endif
8714 + .endm
8715 +
8716 +.macro pax_erase_kstack
8717 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8718 + call pax_erase_kstack
8719 +#endif
8720 +.endm
8721 +
8722 /*
8723 * 32bit SYSENTER instruction entry.
8724 *
8725 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8726 CFI_REGISTER rsp,rbp
8727 SWAPGS_UNSAFE_STACK
8728 movq PER_CPU_VAR(kernel_stack), %rsp
8729 - addq $(KERNEL_STACK_OFFSET),%rsp
8730 - /*
8731 - * No need to follow this irqs on/off section: the syscall
8732 - * disabled irqs, here we enable it straight after entry:
8733 - */
8734 - ENABLE_INTERRUPTS(CLBR_NONE)
8735 movl %ebp,%ebp /* zero extension */
8736 pushq_cfi $__USER32_DS
8737 /*CFI_REL_OFFSET ss,0*/
8738 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8739 CFI_REL_OFFSET rsp,0
8740 pushfq_cfi
8741 /*CFI_REL_OFFSET rflags,0*/
8742 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8743 - CFI_REGISTER rip,r10
8744 + orl $X86_EFLAGS_IF,(%rsp)
8745 + GET_THREAD_INFO(%r11)
8746 + movl TI_sysenter_return(%r11), %r11d
8747 + CFI_REGISTER rip,r11
8748 pushq_cfi $__USER32_CS
8749 /*CFI_REL_OFFSET cs,0*/
8750 movl %eax, %eax
8751 - pushq_cfi %r10
8752 + pushq_cfi %r11
8753 CFI_REL_OFFSET rip,0
8754 pushq_cfi %rax
8755 cld
8756 SAVE_ARGS 0,1,0
8757 + pax_enter_kernel_user
8758 + /*
8759 + * No need to follow this irqs on/off section: the syscall
8760 + * disabled irqs, here we enable it straight after entry:
8761 + */
8762 + ENABLE_INTERRUPTS(CLBR_NONE)
8763 /* no need to do an access_ok check here because rbp has been
8764 32bit zero extended */
8765 +
8766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8767 + mov $PAX_USER_SHADOW_BASE,%r11
8768 + add %r11,%rbp
8769 +#endif
8770 +
8771 1: movl (%rbp),%ebp
8772 .section __ex_table,"a"
8773 .quad 1b,ia32_badarg
8774 .previous
8775 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8776 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8777 + GET_THREAD_INFO(%r11)
8778 + orl $TS_COMPAT,TI_status(%r11)
8779 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8780 CFI_REMEMBER_STATE
8781 jnz sysenter_tracesys
8782 cmpq $(IA32_NR_syscalls-1),%rax
8783 @@ -160,12 +197,15 @@ sysenter_do_call:
8784 sysenter_dispatch:
8785 call *ia32_sys_call_table(,%rax,8)
8786 movq %rax,RAX-ARGOFFSET(%rsp)
8787 + GET_THREAD_INFO(%r11)
8788 DISABLE_INTERRUPTS(CLBR_NONE)
8789 TRACE_IRQS_OFF
8790 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8791 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8792 jnz sysexit_audit
8793 sysexit_from_sys_call:
8794 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8795 + pax_exit_kernel_user
8796 + pax_erase_kstack
8797 + andl $~TS_COMPAT,TI_status(%r11)
8798 /* clear IF, that popfq doesn't enable interrupts early */
8799 andl $~0x200,EFLAGS-R11(%rsp)
8800 movl RIP-R11(%rsp),%edx /* User %eip */
8801 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8802 movl %eax,%esi /* 2nd arg: syscall number */
8803 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8804 call __audit_syscall_entry
8805 +
8806 + pax_erase_kstack
8807 +
8808 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8809 cmpq $(IA32_NR_syscalls-1),%rax
8810 ja ia32_badsys
8811 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8812 .endm
8813
8814 .macro auditsys_exit exit
8815 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8816 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8817 jnz ia32_ret_from_sys_call
8818 TRACE_IRQS_ON
8819 sti
8820 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8821 1: setbe %al /* 1 if error, 0 if not */
8822 movzbl %al,%edi /* zero-extend that into %edi */
8823 call __audit_syscall_exit
8824 + GET_THREAD_INFO(%r11)
8825 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8826 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8827 cli
8828 TRACE_IRQS_OFF
8829 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8830 + testl %edi,TI_flags(%r11)
8831 jz \exit
8832 CLEAR_RREGS -ARGOFFSET
8833 jmp int_with_check
8834 @@ -235,7 +279,7 @@ sysexit_audit:
8835
8836 sysenter_tracesys:
8837 #ifdef CONFIG_AUDITSYSCALL
8838 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8839 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8840 jz sysenter_auditsys
8841 #endif
8842 SAVE_REST
8843 @@ -243,6 +287,9 @@ sysenter_tracesys:
8844 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8845 movq %rsp,%rdi /* &pt_regs -> arg1 */
8846 call syscall_trace_enter
8847 +
8848 + pax_erase_kstack
8849 +
8850 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8851 RESTORE_REST
8852 cmpq $(IA32_NR_syscalls-1),%rax
8853 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8854 ENTRY(ia32_cstar_target)
8855 CFI_STARTPROC32 simple
8856 CFI_SIGNAL_FRAME
8857 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8858 + CFI_DEF_CFA rsp,0
8859 CFI_REGISTER rip,rcx
8860 /*CFI_REGISTER rflags,r11*/
8861 SWAPGS_UNSAFE_STACK
8862 movl %esp,%r8d
8863 CFI_REGISTER rsp,r8
8864 movq PER_CPU_VAR(kernel_stack),%rsp
8865 + SAVE_ARGS 8*6,0,0
8866 + pax_enter_kernel_user
8867 /*
8868 * No need to follow this irqs on/off section: the syscall
8869 * disabled irqs and here we enable it straight after entry:
8870 */
8871 ENABLE_INTERRUPTS(CLBR_NONE)
8872 - SAVE_ARGS 8,0,0
8873 movl %eax,%eax /* zero extension */
8874 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8875 movq %rcx,RIP-ARGOFFSET(%rsp)
8876 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8877 /* no need to do an access_ok check here because r8 has been
8878 32bit zero extended */
8879 /* hardware stack frame is complete now */
8880 +
8881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8882 + mov $PAX_USER_SHADOW_BASE,%r11
8883 + add %r11,%r8
8884 +#endif
8885 +
8886 1: movl (%r8),%r9d
8887 .section __ex_table,"a"
8888 .quad 1b,ia32_badarg
8889 .previous
8890 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8891 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8892 + GET_THREAD_INFO(%r11)
8893 + orl $TS_COMPAT,TI_status(%r11)
8894 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8895 CFI_REMEMBER_STATE
8896 jnz cstar_tracesys
8897 cmpq $IA32_NR_syscalls-1,%rax
8898 @@ -317,12 +372,15 @@ cstar_do_call:
8899 cstar_dispatch:
8900 call *ia32_sys_call_table(,%rax,8)
8901 movq %rax,RAX-ARGOFFSET(%rsp)
8902 + GET_THREAD_INFO(%r11)
8903 DISABLE_INTERRUPTS(CLBR_NONE)
8904 TRACE_IRQS_OFF
8905 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8906 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8907 jnz sysretl_audit
8908 sysretl_from_sys_call:
8909 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8910 + pax_exit_kernel_user
8911 + pax_erase_kstack
8912 + andl $~TS_COMPAT,TI_status(%r11)
8913 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8914 movl RIP-ARGOFFSET(%rsp),%ecx
8915 CFI_REGISTER rip,rcx
8916 @@ -350,7 +408,7 @@ sysretl_audit:
8917
8918 cstar_tracesys:
8919 #ifdef CONFIG_AUDITSYSCALL
8920 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8922 jz cstar_auditsys
8923 #endif
8924 xchgl %r9d,%ebp
8925 @@ -359,6 +417,9 @@ cstar_tracesys:
8926 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8927 movq %rsp,%rdi /* &pt_regs -> arg1 */
8928 call syscall_trace_enter
8929 +
8930 + pax_erase_kstack
8931 +
8932 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8933 RESTORE_REST
8934 xchgl %ebp,%r9d
8935 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8936 CFI_REL_OFFSET rip,RIP-RIP
8937 PARAVIRT_ADJUST_EXCEPTION_FRAME
8938 SWAPGS
8939 - /*
8940 - * No need to follow this irqs on/off section: the syscall
8941 - * disabled irqs and here we enable it straight after entry:
8942 - */
8943 - ENABLE_INTERRUPTS(CLBR_NONE)
8944 movl %eax,%eax
8945 pushq_cfi %rax
8946 cld
8947 /* note the registers are not zero extended to the sf.
8948 this could be a problem. */
8949 SAVE_ARGS 0,1,0
8950 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8951 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8952 + pax_enter_kernel_user
8953 + /*
8954 + * No need to follow this irqs on/off section: the syscall
8955 + * disabled irqs and here we enable it straight after entry:
8956 + */
8957 + ENABLE_INTERRUPTS(CLBR_NONE)
8958 + GET_THREAD_INFO(%r11)
8959 + orl $TS_COMPAT,TI_status(%r11)
8960 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8961 jnz ia32_tracesys
8962 cmpq $(IA32_NR_syscalls-1),%rax
8963 ja ia32_badsys
8964 @@ -435,6 +498,9 @@ ia32_tracesys:
8965 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8966 movq %rsp,%rdi /* &pt_regs -> arg1 */
8967 call syscall_trace_enter
8968 +
8969 + pax_erase_kstack
8970 +
8971 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8972 RESTORE_REST
8973 cmpq $(IA32_NR_syscalls-1),%rax
8974 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8975 index aec2202..f76174e 100644
8976 --- a/arch/x86/ia32/sys_ia32.c
8977 +++ b/arch/x86/ia32/sys_ia32.c
8978 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8979 */
8980 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8981 {
8982 - typeof(ubuf->st_uid) uid = 0;
8983 - typeof(ubuf->st_gid) gid = 0;
8984 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8985 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8986 SET_UID(uid, stat->uid);
8987 SET_GID(gid, stat->gid);
8988 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8989 @@ -292,7 +292,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8990 return alarm_setitimer(seconds);
8991 }
8992
8993 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8994 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8995 int options)
8996 {
8997 return compat_sys_wait4(pid, stat_addr, options, NULL);
8998 @@ -313,7 +313,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8999 mm_segment_t old_fs = get_fs();
9000
9001 set_fs(KERNEL_DS);
9002 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9003 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9004 set_fs(old_fs);
9005 if (put_compat_timespec(&t, interval))
9006 return -EFAULT;
9007 @@ -329,7 +329,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9008 mm_segment_t old_fs = get_fs();
9009
9010 set_fs(KERNEL_DS);
9011 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9012 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9013 set_fs(old_fs);
9014 if (!ret) {
9015 switch (_NSIG_WORDS) {
9016 @@ -354,7 +354,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9017 if (copy_siginfo_from_user32(&info, uinfo))
9018 return -EFAULT;
9019 set_fs(KERNEL_DS);
9020 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9021 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9022 set_fs(old_fs);
9023 return ret;
9024 }
9025 @@ -399,7 +399,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9026 return -EFAULT;
9027
9028 set_fs(KERNEL_DS);
9029 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9030 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9031 count);
9032 set_fs(old_fs);
9033
9034 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9035 index 952bd01..7692c6f 100644
9036 --- a/arch/x86/include/asm/alternative-asm.h
9037 +++ b/arch/x86/include/asm/alternative-asm.h
9038 @@ -15,6 +15,45 @@
9039 .endm
9040 #endif
9041
9042 +#ifdef KERNEXEC_PLUGIN
9043 + .macro pax_force_retaddr_bts rip=0
9044 + btsq $63,\rip(%rsp)
9045 + .endm
9046 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9047 + .macro pax_force_retaddr rip=0, reload=0
9048 + btsq $63,\rip(%rsp)
9049 + .endm
9050 + .macro pax_force_fptr ptr
9051 + btsq $63,\ptr
9052 + .endm
9053 + .macro pax_set_fptr_mask
9054 + .endm
9055 +#endif
9056 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9057 + .macro pax_force_retaddr rip=0, reload=0
9058 + .if \reload
9059 + pax_set_fptr_mask
9060 + .endif
9061 + orq %r10,\rip(%rsp)
9062 + .endm
9063 + .macro pax_force_fptr ptr
9064 + orq %r10,\ptr
9065 + .endm
9066 + .macro pax_set_fptr_mask
9067 + movabs $0x8000000000000000,%r10
9068 + .endm
9069 +#endif
9070 +#else
9071 + .macro pax_force_retaddr rip=0, reload=0
9072 + .endm
9073 + .macro pax_force_fptr ptr
9074 + .endm
9075 + .macro pax_force_retaddr_bts rip=0
9076 + .endm
9077 + .macro pax_set_fptr_mask
9078 + .endm
9079 +#endif
9080 +
9081 .macro altinstruction_entry orig alt feature orig_len alt_len
9082 .long \orig - .
9083 .long \alt - .
9084 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9085 index 49331be..9706065 100644
9086 --- a/arch/x86/include/asm/alternative.h
9087 +++ b/arch/x86/include/asm/alternative.h
9088 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9089 ".section .discard,\"aw\",@progbits\n" \
9090 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9091 ".previous\n" \
9092 - ".section .altinstr_replacement, \"ax\"\n" \
9093 + ".section .altinstr_replacement, \"a\"\n" \
9094 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9095 ".previous"
9096
9097 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9098 index d854101..f6ea947 100644
9099 --- a/arch/x86/include/asm/apic.h
9100 +++ b/arch/x86/include/asm/apic.h
9101 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9102
9103 #ifdef CONFIG_X86_LOCAL_APIC
9104
9105 -extern unsigned int apic_verbosity;
9106 +extern int apic_verbosity;
9107 extern int local_apic_timer_c2_ok;
9108
9109 extern int disable_apic;
9110 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9111 index 20370c6..a2eb9b0 100644
9112 --- a/arch/x86/include/asm/apm.h
9113 +++ b/arch/x86/include/asm/apm.h
9114 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9115 __asm__ __volatile__(APM_DO_ZERO_SEGS
9116 "pushl %%edi\n\t"
9117 "pushl %%ebp\n\t"
9118 - "lcall *%%cs:apm_bios_entry\n\t"
9119 + "lcall *%%ss:apm_bios_entry\n\t"
9120 "setc %%al\n\t"
9121 "popl %%ebp\n\t"
9122 "popl %%edi\n\t"
9123 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9124 __asm__ __volatile__(APM_DO_ZERO_SEGS
9125 "pushl %%edi\n\t"
9126 "pushl %%ebp\n\t"
9127 - "lcall *%%cs:apm_bios_entry\n\t"
9128 + "lcall *%%ss:apm_bios_entry\n\t"
9129 "setc %%bl\n\t"
9130 "popl %%ebp\n\t"
9131 "popl %%edi\n\t"
9132 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9133 index 58cb6d4..ca9010d 100644
9134 --- a/arch/x86/include/asm/atomic.h
9135 +++ b/arch/x86/include/asm/atomic.h
9136 @@ -22,7 +22,18 @@
9137 */
9138 static inline int atomic_read(const atomic_t *v)
9139 {
9140 - return (*(volatile int *)&(v)->counter);
9141 + return (*(volatile const int *)&(v)->counter);
9142 +}
9143 +
9144 +/**
9145 + * atomic_read_unchecked - read atomic variable
9146 + * @v: pointer of type atomic_unchecked_t
9147 + *
9148 + * Atomically reads the value of @v.
9149 + */
9150 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9151 +{
9152 + return (*(volatile const int *)&(v)->counter);
9153 }
9154
9155 /**
9156 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9157 }
9158
9159 /**
9160 + * atomic_set_unchecked - set atomic variable
9161 + * @v: pointer of type atomic_unchecked_t
9162 + * @i: required value
9163 + *
9164 + * Atomically sets the value of @v to @i.
9165 + */
9166 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9167 +{
9168 + v->counter = i;
9169 +}
9170 +
9171 +/**
9172 * atomic_add - add integer to atomic variable
9173 * @i: integer value to add
9174 * @v: pointer of type atomic_t
9175 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9176 */
9177 static inline void atomic_add(int i, atomic_t *v)
9178 {
9179 - asm volatile(LOCK_PREFIX "addl %1,%0"
9180 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9181 +
9182 +#ifdef CONFIG_PAX_REFCOUNT
9183 + "jno 0f\n"
9184 + LOCK_PREFIX "subl %1,%0\n"
9185 + "int $4\n0:\n"
9186 + _ASM_EXTABLE(0b, 0b)
9187 +#endif
9188 +
9189 + : "+m" (v->counter)
9190 + : "ir" (i));
9191 +}
9192 +
9193 +/**
9194 + * atomic_add_unchecked - add integer to atomic variable
9195 + * @i: integer value to add
9196 + * @v: pointer of type atomic_unchecked_t
9197 + *
9198 + * Atomically adds @i to @v.
9199 + */
9200 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9201 +{
9202 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9203 : "+m" (v->counter)
9204 : "ir" (i));
9205 }
9206 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9207 */
9208 static inline void atomic_sub(int i, atomic_t *v)
9209 {
9210 - asm volatile(LOCK_PREFIX "subl %1,%0"
9211 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9212 +
9213 +#ifdef CONFIG_PAX_REFCOUNT
9214 + "jno 0f\n"
9215 + LOCK_PREFIX "addl %1,%0\n"
9216 + "int $4\n0:\n"
9217 + _ASM_EXTABLE(0b, 0b)
9218 +#endif
9219 +
9220 + : "+m" (v->counter)
9221 + : "ir" (i));
9222 +}
9223 +
9224 +/**
9225 + * atomic_sub_unchecked - subtract integer from atomic variable
9226 + * @i: integer value to subtract
9227 + * @v: pointer of type atomic_unchecked_t
9228 + *
9229 + * Atomically subtracts @i from @v.
9230 + */
9231 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9232 +{
9233 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9234 : "+m" (v->counter)
9235 : "ir" (i));
9236 }
9237 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9238 {
9239 unsigned char c;
9240
9241 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9242 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9243 +
9244 +#ifdef CONFIG_PAX_REFCOUNT
9245 + "jno 0f\n"
9246 + LOCK_PREFIX "addl %2,%0\n"
9247 + "int $4\n0:\n"
9248 + _ASM_EXTABLE(0b, 0b)
9249 +#endif
9250 +
9251 + "sete %1\n"
9252 : "+m" (v->counter), "=qm" (c)
9253 : "ir" (i) : "memory");
9254 return c;
9255 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9256 */
9257 static inline void atomic_inc(atomic_t *v)
9258 {
9259 - asm volatile(LOCK_PREFIX "incl %0"
9260 + asm volatile(LOCK_PREFIX "incl %0\n"
9261 +
9262 +#ifdef CONFIG_PAX_REFCOUNT
9263 + "jno 0f\n"
9264 + LOCK_PREFIX "decl %0\n"
9265 + "int $4\n0:\n"
9266 + _ASM_EXTABLE(0b, 0b)
9267 +#endif
9268 +
9269 + : "+m" (v->counter));
9270 +}
9271 +
9272 +/**
9273 + * atomic_inc_unchecked - increment atomic variable
9274 + * @v: pointer of type atomic_unchecked_t
9275 + *
9276 + * Atomically increments @v by 1.
9277 + */
9278 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9279 +{
9280 + asm volatile(LOCK_PREFIX "incl %0\n"
9281 : "+m" (v->counter));
9282 }
9283
9284 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9285 */
9286 static inline void atomic_dec(atomic_t *v)
9287 {
9288 - asm volatile(LOCK_PREFIX "decl %0"
9289 + asm volatile(LOCK_PREFIX "decl %0\n"
9290 +
9291 +#ifdef CONFIG_PAX_REFCOUNT
9292 + "jno 0f\n"
9293 + LOCK_PREFIX "incl %0\n"
9294 + "int $4\n0:\n"
9295 + _ASM_EXTABLE(0b, 0b)
9296 +#endif
9297 +
9298 + : "+m" (v->counter));
9299 +}
9300 +
9301 +/**
9302 + * atomic_dec_unchecked - decrement atomic variable
9303 + * @v: pointer of type atomic_unchecked_t
9304 + *
9305 + * Atomically decrements @v by 1.
9306 + */
9307 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9308 +{
9309 + asm volatile(LOCK_PREFIX "decl %0\n"
9310 : "+m" (v->counter));
9311 }
9312
9313 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9314 {
9315 unsigned char c;
9316
9317 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9318 + asm volatile(LOCK_PREFIX "decl %0\n"
9319 +
9320 +#ifdef CONFIG_PAX_REFCOUNT
9321 + "jno 0f\n"
9322 + LOCK_PREFIX "incl %0\n"
9323 + "int $4\n0:\n"
9324 + _ASM_EXTABLE(0b, 0b)
9325 +#endif
9326 +
9327 + "sete %1\n"
9328 : "+m" (v->counter), "=qm" (c)
9329 : : "memory");
9330 return c != 0;
9331 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9332 {
9333 unsigned char c;
9334
9335 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9336 + asm volatile(LOCK_PREFIX "incl %0\n"
9337 +
9338 +#ifdef CONFIG_PAX_REFCOUNT
9339 + "jno 0f\n"
9340 + LOCK_PREFIX "decl %0\n"
9341 + "int $4\n0:\n"
9342 + _ASM_EXTABLE(0b, 0b)
9343 +#endif
9344 +
9345 + "sete %1\n"
9346 + : "+m" (v->counter), "=qm" (c)
9347 + : : "memory");
9348 + return c != 0;
9349 +}
9350 +
9351 +/**
9352 + * atomic_inc_and_test_unchecked - increment and test
9353 + * @v: pointer of type atomic_unchecked_t
9354 + *
9355 + * Atomically increments @v by 1
9356 + * and returns true if the result is zero, or false for all
9357 + * other cases.
9358 + */
9359 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9360 +{
9361 + unsigned char c;
9362 +
9363 + asm volatile(LOCK_PREFIX "incl %0\n"
9364 + "sete %1\n"
9365 : "+m" (v->counter), "=qm" (c)
9366 : : "memory");
9367 return c != 0;
9368 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9369 {
9370 unsigned char c;
9371
9372 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9373 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9374 +
9375 +#ifdef CONFIG_PAX_REFCOUNT
9376 + "jno 0f\n"
9377 + LOCK_PREFIX "subl %2,%0\n"
9378 + "int $4\n0:\n"
9379 + _ASM_EXTABLE(0b, 0b)
9380 +#endif
9381 +
9382 + "sets %1\n"
9383 : "+m" (v->counter), "=qm" (c)
9384 : "ir" (i) : "memory");
9385 return c;
9386 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9387 goto no_xadd;
9388 #endif
9389 /* Modern 486+ processor */
9390 - return i + xadd(&v->counter, i);
9391 + return i + xadd_check_overflow(&v->counter, i);
9392
9393 #ifdef CONFIG_M386
9394 no_xadd: /* Legacy 386 processor */
9395 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9396 }
9397
9398 /**
9399 + * atomic_add_return_unchecked - add integer and return
9400 + * @i: integer value to add
9401 + * @v: pointer of type atomic_unchecked_t
9402 + *
9403 + * Atomically adds @i to @v and returns @i + @v
9404 + */
9405 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9406 +{
9407 +#ifdef CONFIG_M386
9408 + int __i;
9409 + unsigned long flags;
9410 + if (unlikely(boot_cpu_data.x86 <= 3))
9411 + goto no_xadd;
9412 +#endif
9413 + /* Modern 486+ processor */
9414 + return i + xadd(&v->counter, i);
9415 +
9416 +#ifdef CONFIG_M386
9417 +no_xadd: /* Legacy 386 processor */
9418 + raw_local_irq_save(flags);
9419 + __i = atomic_read_unchecked(v);
9420 + atomic_set_unchecked(v, i + __i);
9421 + raw_local_irq_restore(flags);
9422 + return i + __i;
9423 +#endif
9424 +}
9425 +
9426 +/**
9427 * atomic_sub_return - subtract integer and return
9428 * @v: pointer of type atomic_t
9429 * @i: integer value to subtract
9430 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9431 }
9432
9433 #define atomic_inc_return(v) (atomic_add_return(1, v))
9434 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9435 +{
9436 + return atomic_add_return_unchecked(1, v);
9437 +}
9438 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9439
9440 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9441 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9442 return cmpxchg(&v->counter, old, new);
9443 }
9444
9445 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9446 +{
9447 + return cmpxchg(&v->counter, old, new);
9448 +}
9449 +
9450 static inline int atomic_xchg(atomic_t *v, int new)
9451 {
9452 return xchg(&v->counter, new);
9453 }
9454
9455 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9456 +{
9457 + return xchg(&v->counter, new);
9458 +}
9459 +
9460 /**
9461 * __atomic_add_unless - add unless the number is already a given value
9462 * @v: pointer of type atomic_t
9463 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9464 */
9465 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9466 {
9467 - int c, old;
9468 + int c, old, new;
9469 c = atomic_read(v);
9470 for (;;) {
9471 - if (unlikely(c == (u)))
9472 + if (unlikely(c == u))
9473 break;
9474 - old = atomic_cmpxchg((v), c, c + (a));
9475 +
9476 + asm volatile("addl %2,%0\n"
9477 +
9478 +#ifdef CONFIG_PAX_REFCOUNT
9479 + "jno 0f\n"
9480 + "subl %2,%0\n"
9481 + "int $4\n0:\n"
9482 + _ASM_EXTABLE(0b, 0b)
9483 +#endif
9484 +
9485 + : "=r" (new)
9486 + : "0" (c), "ir" (a));
9487 +
9488 + old = atomic_cmpxchg(v, c, new);
9489 if (likely(old == c))
9490 break;
9491 c = old;
9492 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9493 return c;
9494 }
9495
9496 +/**
9497 + * atomic_inc_not_zero_hint - increment if not null
9498 + * @v: pointer of type atomic_t
9499 + * @hint: probable value of the atomic before the increment
9500 + *
9501 + * This version of atomic_inc_not_zero() gives a hint of probable
9502 + * value of the atomic. This helps processor to not read the memory
9503 + * before doing the atomic read/modify/write cycle, lowering
9504 + * number of bus transactions on some arches.
9505 + *
9506 + * Returns: 0 if increment was not done, 1 otherwise.
9507 + */
9508 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9509 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9510 +{
9511 + int val, c = hint, new;
9512 +
9513 + /* sanity test, should be removed by compiler if hint is a constant */
9514 + if (!hint)
9515 + return __atomic_add_unless(v, 1, 0);
9516 +
9517 + do {
9518 + asm volatile("incl %0\n"
9519 +
9520 +#ifdef CONFIG_PAX_REFCOUNT
9521 + "jno 0f\n"
9522 + "decl %0\n"
9523 + "int $4\n0:\n"
9524 + _ASM_EXTABLE(0b, 0b)
9525 +#endif
9526 +
9527 + : "=r" (new)
9528 + : "0" (c));
9529 +
9530 + val = atomic_cmpxchg(v, c, new);
9531 + if (val == c)
9532 + return 1;
9533 + c = val;
9534 + } while (c);
9535 +
9536 + return 0;
9537 +}
9538
9539 /*
9540 * atomic_dec_if_positive - decrement by 1 if old value positive
9541 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9542 index 1981199..36b9dfb 100644
9543 --- a/arch/x86/include/asm/atomic64_32.h
9544 +++ b/arch/x86/include/asm/atomic64_32.h
9545 @@ -12,6 +12,14 @@ typedef struct {
9546 u64 __aligned(8) counter;
9547 } atomic64_t;
9548
9549 +#ifdef CONFIG_PAX_REFCOUNT
9550 +typedef struct {
9551 + u64 __aligned(8) counter;
9552 +} atomic64_unchecked_t;
9553 +#else
9554 +typedef atomic64_t atomic64_unchecked_t;
9555 +#endif
9556 +
9557 #define ATOMIC64_INIT(val) { (val) }
9558
9559 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9560 @@ -37,21 +45,31 @@ typedef struct {
9561 ATOMIC64_DECL_ONE(sym##_386)
9562
9563 ATOMIC64_DECL_ONE(add_386);
9564 +ATOMIC64_DECL_ONE(add_unchecked_386);
9565 ATOMIC64_DECL_ONE(sub_386);
9566 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9567 ATOMIC64_DECL_ONE(inc_386);
9568 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9569 ATOMIC64_DECL_ONE(dec_386);
9570 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9571 #endif
9572
9573 #define alternative_atomic64(f, out, in...) \
9574 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9575
9576 ATOMIC64_DECL(read);
9577 +ATOMIC64_DECL(read_unchecked);
9578 ATOMIC64_DECL(set);
9579 +ATOMIC64_DECL(set_unchecked);
9580 ATOMIC64_DECL(xchg);
9581 ATOMIC64_DECL(add_return);
9582 +ATOMIC64_DECL(add_return_unchecked);
9583 ATOMIC64_DECL(sub_return);
9584 +ATOMIC64_DECL(sub_return_unchecked);
9585 ATOMIC64_DECL(inc_return);
9586 +ATOMIC64_DECL(inc_return_unchecked);
9587 ATOMIC64_DECL(dec_return);
9588 +ATOMIC64_DECL(dec_return_unchecked);
9589 ATOMIC64_DECL(dec_if_positive);
9590 ATOMIC64_DECL(inc_not_zero);
9591 ATOMIC64_DECL(add_unless);
9592 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9593 }
9594
9595 /**
9596 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9597 + * @p: pointer to type atomic64_unchecked_t
9598 + * @o: expected value
9599 + * @n: new value
9600 + *
9601 + * Atomically sets @v to @n if it was equal to @o and returns
9602 + * the old value.
9603 + */
9604 +
9605 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9606 +{
9607 + return cmpxchg64(&v->counter, o, n);
9608 +}
9609 +
9610 +/**
9611 * atomic64_xchg - xchg atomic64 variable
9612 * @v: pointer to type atomic64_t
9613 * @n: value to assign
9614 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9615 }
9616
9617 /**
9618 + * atomic64_set_unchecked - set atomic64 variable
9619 + * @v: pointer to type atomic64_unchecked_t
9620 + * @n: value to assign
9621 + *
9622 + * Atomically sets the value of @v to @n.
9623 + */
9624 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9625 +{
9626 + unsigned high = (unsigned)(i >> 32);
9627 + unsigned low = (unsigned)i;
9628 + alternative_atomic64(set, /* no output */,
9629 + "S" (v), "b" (low), "c" (high)
9630 + : "eax", "edx", "memory");
9631 +}
9632 +
9633 +/**
9634 * atomic64_read - read atomic64 variable
9635 * @v: pointer to type atomic64_t
9636 *
9637 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9638 }
9639
9640 /**
9641 + * atomic64_read_unchecked - read atomic64 variable
9642 + * @v: pointer to type atomic64_unchecked_t
9643 + *
9644 + * Atomically reads the value of @v and returns it.
9645 + */
9646 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9647 +{
9648 + long long r;
9649 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9650 + return r;
9651 + }
9652 +
9653 +/**
9654 * atomic64_add_return - add and return
9655 * @i: integer value to add
9656 * @v: pointer to type atomic64_t
9657 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9658 return i;
9659 }
9660
9661 +/**
9662 + * atomic64_add_return_unchecked - add and return
9663 + * @i: integer value to add
9664 + * @v: pointer to type atomic64_unchecked_t
9665 + *
9666 + * Atomically adds @i to @v and returns @i + *@v
9667 + */
9668 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9669 +{
9670 + alternative_atomic64(add_return_unchecked,
9671 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9672 + ASM_NO_INPUT_CLOBBER("memory"));
9673 + return i;
9674 +}
9675 +
9676 /*
9677 * Other variants with different arithmetic operators:
9678 */
9679 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9680 return a;
9681 }
9682
9683 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9684 +{
9685 + long long a;
9686 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9687 + "S" (v) : "memory", "ecx");
9688 + return a;
9689 +}
9690 +
9691 static inline long long atomic64_dec_return(atomic64_t *v)
9692 {
9693 long long a;
9694 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9695 }
9696
9697 /**
9698 + * atomic64_add_unchecked - add integer to atomic64 variable
9699 + * @i: integer value to add
9700 + * @v: pointer to type atomic64_unchecked_t
9701 + *
9702 + * Atomically adds @i to @v.
9703 + */
9704 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9705 +{
9706 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9707 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9708 + ASM_NO_INPUT_CLOBBER("memory"));
9709 + return i;
9710 +}
9711 +
9712 +/**
9713 * atomic64_sub - subtract the atomic64 variable
9714 * @i: integer value to subtract
9715 * @v: pointer to type atomic64_t
9716 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9717 index 0e1cbfc..5623683 100644
9718 --- a/arch/x86/include/asm/atomic64_64.h
9719 +++ b/arch/x86/include/asm/atomic64_64.h
9720 @@ -18,7 +18,19 @@
9721 */
9722 static inline long atomic64_read(const atomic64_t *v)
9723 {
9724 - return (*(volatile long *)&(v)->counter);
9725 + return (*(volatile const long *)&(v)->counter);
9726 +}
9727 +
9728 +/**
9729 + * atomic64_read_unchecked - read atomic64 variable
9730 + * @v: pointer of type atomic64_unchecked_t
9731 + *
9732 + * Atomically reads the value of @v.
9733 + * Doesn't imply a read memory barrier.
9734 + */
9735 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9736 +{
9737 + return (*(volatile const long *)&(v)->counter);
9738 }
9739
9740 /**
9741 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9742 }
9743
9744 /**
9745 + * atomic64_set_unchecked - set atomic64 variable
9746 + * @v: pointer to type atomic64_unchecked_t
9747 + * @i: required value
9748 + *
9749 + * Atomically sets the value of @v to @i.
9750 + */
9751 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9752 +{
9753 + v->counter = i;
9754 +}
9755 +
9756 +/**
9757 * atomic64_add - add integer to atomic64 variable
9758 * @i: integer value to add
9759 * @v: pointer to type atomic64_t
9760 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9761 */
9762 static inline void atomic64_add(long i, atomic64_t *v)
9763 {
9764 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9765 +
9766 +#ifdef CONFIG_PAX_REFCOUNT
9767 + "jno 0f\n"
9768 + LOCK_PREFIX "subq %1,%0\n"
9769 + "int $4\n0:\n"
9770 + _ASM_EXTABLE(0b, 0b)
9771 +#endif
9772 +
9773 + : "=m" (v->counter)
9774 + : "er" (i), "m" (v->counter));
9775 +}
9776 +
9777 +/**
9778 + * atomic64_add_unchecked - add integer to atomic64 variable
9779 + * @i: integer value to add
9780 + * @v: pointer to type atomic64_unchecked_t
9781 + *
9782 + * Atomically adds @i to @v.
9783 + */
9784 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9785 +{
9786 asm volatile(LOCK_PREFIX "addq %1,%0"
9787 : "=m" (v->counter)
9788 : "er" (i), "m" (v->counter));
9789 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9790 */
9791 static inline void atomic64_sub(long i, atomic64_t *v)
9792 {
9793 - asm volatile(LOCK_PREFIX "subq %1,%0"
9794 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9795 +
9796 +#ifdef CONFIG_PAX_REFCOUNT
9797 + "jno 0f\n"
9798 + LOCK_PREFIX "addq %1,%0\n"
9799 + "int $4\n0:\n"
9800 + _ASM_EXTABLE(0b, 0b)
9801 +#endif
9802 +
9803 + : "=m" (v->counter)
9804 + : "er" (i), "m" (v->counter));
9805 +}
9806 +
9807 +/**
9808 + * atomic64_sub_unchecked - subtract the atomic64 variable
9809 + * @i: integer value to subtract
9810 + * @v: pointer to type atomic64_unchecked_t
9811 + *
9812 + * Atomically subtracts @i from @v.
9813 + */
9814 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9815 +{
9816 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9817 : "=m" (v->counter)
9818 : "er" (i), "m" (v->counter));
9819 }
9820 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9821 {
9822 unsigned char c;
9823
9824 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9825 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9826 +
9827 +#ifdef CONFIG_PAX_REFCOUNT
9828 + "jno 0f\n"
9829 + LOCK_PREFIX "addq %2,%0\n"
9830 + "int $4\n0:\n"
9831 + _ASM_EXTABLE(0b, 0b)
9832 +#endif
9833 +
9834 + "sete %1\n"
9835 : "=m" (v->counter), "=qm" (c)
9836 : "er" (i), "m" (v->counter) : "memory");
9837 return c;
9838 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9839 */
9840 static inline void atomic64_inc(atomic64_t *v)
9841 {
9842 + asm volatile(LOCK_PREFIX "incq %0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + LOCK_PREFIX "decq %0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + : "=m" (v->counter)
9852 + : "m" (v->counter));
9853 +}
9854 +
9855 +/**
9856 + * atomic64_inc_unchecked - increment atomic64 variable
9857 + * @v: pointer to type atomic64_unchecked_t
9858 + *
9859 + * Atomically increments @v by 1.
9860 + */
9861 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9862 +{
9863 asm volatile(LOCK_PREFIX "incq %0"
9864 : "=m" (v->counter)
9865 : "m" (v->counter));
9866 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9867 */
9868 static inline void atomic64_dec(atomic64_t *v)
9869 {
9870 - asm volatile(LOCK_PREFIX "decq %0"
9871 + asm volatile(LOCK_PREFIX "decq %0\n"
9872 +
9873 +#ifdef CONFIG_PAX_REFCOUNT
9874 + "jno 0f\n"
9875 + LOCK_PREFIX "incq %0\n"
9876 + "int $4\n0:\n"
9877 + _ASM_EXTABLE(0b, 0b)
9878 +#endif
9879 +
9880 + : "=m" (v->counter)
9881 + : "m" (v->counter));
9882 +}
9883 +
9884 +/**
9885 + * atomic64_dec_unchecked - decrement atomic64 variable
9886 + * @v: pointer to type atomic64_t
9887 + *
9888 + * Atomically decrements @v by 1.
9889 + */
9890 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9891 +{
9892 + asm volatile(LOCK_PREFIX "decq %0\n"
9893 : "=m" (v->counter)
9894 : "m" (v->counter));
9895 }
9896 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9897 {
9898 unsigned char c;
9899
9900 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9901 + asm volatile(LOCK_PREFIX "decq %0\n"
9902 +
9903 +#ifdef CONFIG_PAX_REFCOUNT
9904 + "jno 0f\n"
9905 + LOCK_PREFIX "incq %0\n"
9906 + "int $4\n0:\n"
9907 + _ASM_EXTABLE(0b, 0b)
9908 +#endif
9909 +
9910 + "sete %1\n"
9911 : "=m" (v->counter), "=qm" (c)
9912 : "m" (v->counter) : "memory");
9913 return c != 0;
9914 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9915 {
9916 unsigned char c;
9917
9918 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9919 + asm volatile(LOCK_PREFIX "incq %0\n"
9920 +
9921 +#ifdef CONFIG_PAX_REFCOUNT
9922 + "jno 0f\n"
9923 + LOCK_PREFIX "decq %0\n"
9924 + "int $4\n0:\n"
9925 + _ASM_EXTABLE(0b, 0b)
9926 +#endif
9927 +
9928 + "sete %1\n"
9929 : "=m" (v->counter), "=qm" (c)
9930 : "m" (v->counter) : "memory");
9931 return c != 0;
9932 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9933 {
9934 unsigned char c;
9935
9936 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9937 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 + "jno 0f\n"
9941 + LOCK_PREFIX "subq %2,%0\n"
9942 + "int $4\n0:\n"
9943 + _ASM_EXTABLE(0b, 0b)
9944 +#endif
9945 +
9946 + "sets %1\n"
9947 : "=m" (v->counter), "=qm" (c)
9948 : "er" (i), "m" (v->counter) : "memory");
9949 return c;
9950 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9951 */
9952 static inline long atomic64_add_return(long i, atomic64_t *v)
9953 {
9954 + return i + xadd_check_overflow(&v->counter, i);
9955 +}
9956 +
9957 +/**
9958 + * atomic64_add_return_unchecked - add and return
9959 + * @i: integer value to add
9960 + * @v: pointer to type atomic64_unchecked_t
9961 + *
9962 + * Atomically adds @i to @v and returns @i + @v
9963 + */
9964 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9965 +{
9966 return i + xadd(&v->counter, i);
9967 }
9968
9969 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9970 }
9971
9972 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9973 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9974 +{
9975 + return atomic64_add_return_unchecked(1, v);
9976 +}
9977 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9978
9979 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9980 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9981 return cmpxchg(&v->counter, old, new);
9982 }
9983
9984 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9985 +{
9986 + return cmpxchg(&v->counter, old, new);
9987 +}
9988 +
9989 static inline long atomic64_xchg(atomic64_t *v, long new)
9990 {
9991 return xchg(&v->counter, new);
9992 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9993 */
9994 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9995 {
9996 - long c, old;
9997 + long c, old, new;
9998 c = atomic64_read(v);
9999 for (;;) {
10000 - if (unlikely(c == (u)))
10001 + if (unlikely(c == u))
10002 break;
10003 - old = atomic64_cmpxchg((v), c, c + (a));
10004 +
10005 + asm volatile("add %2,%0\n"
10006 +
10007 +#ifdef CONFIG_PAX_REFCOUNT
10008 + "jno 0f\n"
10009 + "sub %2,%0\n"
10010 + "int $4\n0:\n"
10011 + _ASM_EXTABLE(0b, 0b)
10012 +#endif
10013 +
10014 + : "=r" (new)
10015 + : "0" (c), "ir" (a));
10016 +
10017 + old = atomic64_cmpxchg(v, c, new);
10018 if (likely(old == c))
10019 break;
10020 c = old;
10021 }
10022 - return c != (u);
10023 + return c != u;
10024 }
10025
10026 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10027 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10028 index b97596e..9bd48b06 100644
10029 --- a/arch/x86/include/asm/bitops.h
10030 +++ b/arch/x86/include/asm/bitops.h
10031 @@ -38,7 +38,7 @@
10032 * a mask operation on a byte.
10033 */
10034 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10035 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10036 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10037 #define CONST_MASK(nr) (1 << ((nr) & 7))
10038
10039 /**
10040 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10041 index 5e1a2ee..c9f9533 100644
10042 --- a/arch/x86/include/asm/boot.h
10043 +++ b/arch/x86/include/asm/boot.h
10044 @@ -11,10 +11,15 @@
10045 #include <asm/pgtable_types.h>
10046
10047 /* Physical address where kernel should be loaded. */
10048 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10049 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10050 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10051 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10052
10053 +#ifndef __ASSEMBLY__
10054 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10055 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10056 +#endif
10057 +
10058 /* Minimum kernel alignment, as a power of two */
10059 #ifdef CONFIG_X86_64
10060 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10061 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10062 index 48f99f1..d78ebf9 100644
10063 --- a/arch/x86/include/asm/cache.h
10064 +++ b/arch/x86/include/asm/cache.h
10065 @@ -5,12 +5,13 @@
10066
10067 /* L1 cache line size */
10068 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10069 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10070 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10071
10072 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10073 +#define __read_only __attribute__((__section__(".data..read_only")))
10074
10075 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10076 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10077 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10078
10079 #ifdef CONFIG_X86_VSMP
10080 #ifdef CONFIG_SMP
10081 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10082 index 9863ee3..4a1f8e1 100644
10083 --- a/arch/x86/include/asm/cacheflush.h
10084 +++ b/arch/x86/include/asm/cacheflush.h
10085 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10086 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10087
10088 if (pg_flags == _PGMT_DEFAULT)
10089 - return -1;
10090 + return ~0UL;
10091 else if (pg_flags == _PGMT_WC)
10092 return _PAGE_CACHE_WC;
10093 else if (pg_flags == _PGMT_UC_MINUS)
10094 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10095 index 46fc474..b02b0f9 100644
10096 --- a/arch/x86/include/asm/checksum_32.h
10097 +++ b/arch/x86/include/asm/checksum_32.h
10098 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10099 int len, __wsum sum,
10100 int *src_err_ptr, int *dst_err_ptr);
10101
10102 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10103 + int len, __wsum sum,
10104 + int *src_err_ptr, int *dst_err_ptr);
10105 +
10106 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10107 + int len, __wsum sum,
10108 + int *src_err_ptr, int *dst_err_ptr);
10109 +
10110 /*
10111 * Note: when you get a NULL pointer exception here this means someone
10112 * passed in an incorrect kernel address to one of these functions.
10113 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10114 int *err_ptr)
10115 {
10116 might_sleep();
10117 - return csum_partial_copy_generic((__force void *)src, dst,
10118 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10119 len, sum, err_ptr, NULL);
10120 }
10121
10122 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10123 {
10124 might_sleep();
10125 if (access_ok(VERIFY_WRITE, dst, len))
10126 - return csum_partial_copy_generic(src, (__force void *)dst,
10127 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10128 len, sum, NULL, err_ptr);
10129
10130 if (len)
10131 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10132 index 99480e5..d81165b 100644
10133 --- a/arch/x86/include/asm/cmpxchg.h
10134 +++ b/arch/x86/include/asm/cmpxchg.h
10135 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10136 __compiletime_error("Bad argument size for cmpxchg");
10137 extern void __xadd_wrong_size(void)
10138 __compiletime_error("Bad argument size for xadd");
10139 +extern void __xadd_check_overflow_wrong_size(void)
10140 + __compiletime_error("Bad argument size for xadd_check_overflow");
10141 extern void __add_wrong_size(void)
10142 __compiletime_error("Bad argument size for add");
10143 +extern void __add_check_overflow_wrong_size(void)
10144 + __compiletime_error("Bad argument size for add_check_overflow");
10145
10146 /*
10147 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10148 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10149 __ret; \
10150 })
10151
10152 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10153 + ({ \
10154 + __typeof__ (*(ptr)) __ret = (arg); \
10155 + switch (sizeof(*(ptr))) { \
10156 + case __X86_CASE_L: \
10157 + asm volatile (lock #op "l %0, %1\n" \
10158 + "jno 0f\n" \
10159 + "mov %0,%1\n" \
10160 + "int $4\n0:\n" \
10161 + _ASM_EXTABLE(0b, 0b) \
10162 + : "+r" (__ret), "+m" (*(ptr)) \
10163 + : : "memory", "cc"); \
10164 + break; \
10165 + case __X86_CASE_Q: \
10166 + asm volatile (lock #op "q %q0, %1\n" \
10167 + "jno 0f\n" \
10168 + "mov %0,%1\n" \
10169 + "int $4\n0:\n" \
10170 + _ASM_EXTABLE(0b, 0b) \
10171 + : "+r" (__ret), "+m" (*(ptr)) \
10172 + : : "memory", "cc"); \
10173 + break; \
10174 + default: \
10175 + __ ## op ## _check_overflow_wrong_size(); \
10176 + } \
10177 + __ret; \
10178 + })
10179 +
10180 /*
10181 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10182 * Since this is generally used to protect other memory information, we
10183 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10184 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10185 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10186
10187 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10188 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10189 +
10190 #define __add(ptr, inc, lock) \
10191 ({ \
10192 __typeof__ (*(ptr)) __ret = (inc); \
10193 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10194 index f91e80f..7f9bd27 100644
10195 --- a/arch/x86/include/asm/cpufeature.h
10196 +++ b/arch/x86/include/asm/cpufeature.h
10197 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10198 ".section .discard,\"aw\",@progbits\n"
10199 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10200 ".previous\n"
10201 - ".section .altinstr_replacement,\"ax\"\n"
10202 + ".section .altinstr_replacement,\"a\"\n"
10203 "3: movb $1,%0\n"
10204 "4:\n"
10205 ".previous\n"
10206 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10207 index e95822d..a90010e 100644
10208 --- a/arch/x86/include/asm/desc.h
10209 +++ b/arch/x86/include/asm/desc.h
10210 @@ -4,6 +4,7 @@
10211 #include <asm/desc_defs.h>
10212 #include <asm/ldt.h>
10213 #include <asm/mmu.h>
10214 +#include <asm/pgtable.h>
10215
10216 #include <linux/smp.h>
10217
10218 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10219
10220 desc->type = (info->read_exec_only ^ 1) << 1;
10221 desc->type |= info->contents << 2;
10222 + desc->type |= info->seg_not_present ^ 1;
10223
10224 desc->s = 1;
10225 desc->dpl = 0x3;
10226 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10227 }
10228
10229 extern struct desc_ptr idt_descr;
10230 -extern gate_desc idt_table[];
10231 extern struct desc_ptr nmi_idt_descr;
10232 -extern gate_desc nmi_idt_table[];
10233 -
10234 -struct gdt_page {
10235 - struct desc_struct gdt[GDT_ENTRIES];
10236 -} __attribute__((aligned(PAGE_SIZE)));
10237 -
10238 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10239 +extern gate_desc idt_table[256];
10240 +extern gate_desc nmi_idt_table[256];
10241
10242 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10243 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10244 {
10245 - return per_cpu(gdt_page, cpu).gdt;
10246 + return cpu_gdt_table[cpu];
10247 }
10248
10249 #ifdef CONFIG_X86_64
10250 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10251 unsigned long base, unsigned dpl, unsigned flags,
10252 unsigned short seg)
10253 {
10254 - gate->a = (seg << 16) | (base & 0xffff);
10255 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10256 + gate->gate.offset_low = base;
10257 + gate->gate.seg = seg;
10258 + gate->gate.reserved = 0;
10259 + gate->gate.type = type;
10260 + gate->gate.s = 0;
10261 + gate->gate.dpl = dpl;
10262 + gate->gate.p = 1;
10263 + gate->gate.offset_high = base >> 16;
10264 }
10265
10266 #endif
10267 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10268
10269 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10270 {
10271 + pax_open_kernel();
10272 memcpy(&idt[entry], gate, sizeof(*gate));
10273 + pax_close_kernel();
10274 }
10275
10276 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10277 {
10278 + pax_open_kernel();
10279 memcpy(&ldt[entry], desc, 8);
10280 + pax_close_kernel();
10281 }
10282
10283 static inline void
10284 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10285 default: size = sizeof(*gdt); break;
10286 }
10287
10288 + pax_open_kernel();
10289 memcpy(&gdt[entry], desc, size);
10290 + pax_close_kernel();
10291 }
10292
10293 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10294 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10295
10296 static inline void native_load_tr_desc(void)
10297 {
10298 + pax_open_kernel();
10299 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10300 + pax_close_kernel();
10301 }
10302
10303 static inline void native_load_gdt(const struct desc_ptr *dtr)
10304 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10305 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10306 unsigned int i;
10307
10308 + pax_open_kernel();
10309 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10310 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10311 + pax_close_kernel();
10312 }
10313
10314 #define _LDT_empty(info) \
10315 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10316 }
10317
10318 #ifdef CONFIG_X86_64
10319 -static inline void set_nmi_gate(int gate, void *addr)
10320 +static inline void set_nmi_gate(int gate, const void *addr)
10321 {
10322 gate_desc s;
10323
10324 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10325 }
10326 #endif
10327
10328 -static inline void _set_gate(int gate, unsigned type, void *addr,
10329 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10330 unsigned dpl, unsigned ist, unsigned seg)
10331 {
10332 gate_desc s;
10333 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10334 * Pentium F0 0F bugfix can have resulted in the mapped
10335 * IDT being write-protected.
10336 */
10337 -static inline void set_intr_gate(unsigned int n, void *addr)
10338 +static inline void set_intr_gate(unsigned int n, const void *addr)
10339 {
10340 BUG_ON((unsigned)n > 0xFF);
10341 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10342 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10343 /*
10344 * This routine sets up an interrupt gate at directory privilege level 3.
10345 */
10346 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10347 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10348 {
10349 BUG_ON((unsigned)n > 0xFF);
10350 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10351 }
10352
10353 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10354 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10355 {
10356 BUG_ON((unsigned)n > 0xFF);
10357 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10358 }
10359
10360 -static inline void set_trap_gate(unsigned int n, void *addr)
10361 +static inline void set_trap_gate(unsigned int n, const void *addr)
10362 {
10363 BUG_ON((unsigned)n > 0xFF);
10364 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10365 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10366 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10367 {
10368 BUG_ON((unsigned)n > 0xFF);
10369 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10370 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10371 }
10372
10373 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10374 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10375 {
10376 BUG_ON((unsigned)n > 0xFF);
10377 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10378 }
10379
10380 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10381 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10382 {
10383 BUG_ON((unsigned)n > 0xFF);
10384 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10385 }
10386
10387 +#ifdef CONFIG_X86_32
10388 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10389 +{
10390 + struct desc_struct d;
10391 +
10392 + if (likely(limit))
10393 + limit = (limit - 1UL) >> PAGE_SHIFT;
10394 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10395 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10396 +}
10397 +#endif
10398 +
10399 #endif /* _ASM_X86_DESC_H */
10400 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10401 index 278441f..b95a174 100644
10402 --- a/arch/x86/include/asm/desc_defs.h
10403 +++ b/arch/x86/include/asm/desc_defs.h
10404 @@ -31,6 +31,12 @@ struct desc_struct {
10405 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10406 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10407 };
10408 + struct {
10409 + u16 offset_low;
10410 + u16 seg;
10411 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10412 + unsigned offset_high: 16;
10413 + } gate;
10414 };
10415 } __attribute__((packed));
10416
10417 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10418 index 3778256..c5d4fce 100644
10419 --- a/arch/x86/include/asm/e820.h
10420 +++ b/arch/x86/include/asm/e820.h
10421 @@ -69,7 +69,7 @@ struct e820map {
10422 #define ISA_START_ADDRESS 0xa0000
10423 #define ISA_END_ADDRESS 0x100000
10424
10425 -#define BIOS_BEGIN 0x000a0000
10426 +#define BIOS_BEGIN 0x000c0000
10427 #define BIOS_END 0x00100000
10428
10429 #define BIOS_ROM_BASE 0xffe00000
10430 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10431 index 5939f44..f8845f6 100644
10432 --- a/arch/x86/include/asm/elf.h
10433 +++ b/arch/x86/include/asm/elf.h
10434 @@ -243,7 +243,25 @@ extern int force_personality32;
10435 the loader. We need to make sure that it is out of the way of the program
10436 that it will "exec", and that there is sufficient room for the brk. */
10437
10438 +#ifdef CONFIG_PAX_SEGMEXEC
10439 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10440 +#else
10441 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10442 +#endif
10443 +
10444 +#ifdef CONFIG_PAX_ASLR
10445 +#ifdef CONFIG_X86_32
10446 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10447 +
10448 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10449 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10450 +#else
10451 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10452 +
10453 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10454 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10455 +#endif
10456 +#endif
10457
10458 /* This yields a mask that user programs can use to figure out what
10459 instruction set this CPU supports. This could be done in user space,
10460 @@ -296,16 +314,12 @@ do { \
10461
10462 #define ARCH_DLINFO \
10463 do { \
10464 - if (vdso_enabled) \
10465 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10466 - (unsigned long)current->mm->context.vdso); \
10467 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10468 } while (0)
10469
10470 #define ARCH_DLINFO_X32 \
10471 do { \
10472 - if (vdso_enabled) \
10473 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10474 - (unsigned long)current->mm->context.vdso); \
10475 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10476 } while (0)
10477
10478 #define AT_SYSINFO 32
10479 @@ -320,7 +334,7 @@ else \
10480
10481 #endif /* !CONFIG_X86_32 */
10482
10483 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10484 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10485
10486 #define VDSO_ENTRY \
10487 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10488 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10489 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10490 #define compat_arch_setup_additional_pages syscall32_setup_pages
10491
10492 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10493 -#define arch_randomize_brk arch_randomize_brk
10494 -
10495 /*
10496 * True on X86_32 or when emulating IA32 on X86_64
10497 */
10498 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10499 index cc70c1c..d96d011 100644
10500 --- a/arch/x86/include/asm/emergency-restart.h
10501 +++ b/arch/x86/include/asm/emergency-restart.h
10502 @@ -15,6 +15,6 @@ enum reboot_type {
10503
10504 extern enum reboot_type reboot_type;
10505
10506 -extern void machine_emergency_restart(void);
10507 +extern void machine_emergency_restart(void) __noreturn;
10508
10509 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10510 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10511 index 4fa8815..71b121a 100644
10512 --- a/arch/x86/include/asm/fpu-internal.h
10513 +++ b/arch/x86/include/asm/fpu-internal.h
10514 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10515 {
10516 int err;
10517
10518 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10519 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10520 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10521 +#endif
10522 +
10523 /* See comment in fxsave() below. */
10524 #ifdef CONFIG_AS_FXSAVEQ
10525 asm volatile("1: fxrstorq %[fx]\n\t"
10526 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10527 {
10528 int err;
10529
10530 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10531 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10532 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10533 +#endif
10534 +
10535 /*
10536 * Clear the bytes not touched by the fxsave and reserved
10537 * for the SW usage.
10538 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10539 "emms\n\t" /* clear stack tags */
10540 "fildl %P[addr]", /* set F?P to defined value */
10541 X86_FEATURE_FXSAVE_LEAK,
10542 - [addr] "m" (tsk->thread.fpu.has_fpu));
10543 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10544
10545 return fpu_restore_checking(&tsk->thread.fpu);
10546 }
10547 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10548 index 71ecbcb..bac10b7 100644
10549 --- a/arch/x86/include/asm/futex.h
10550 +++ b/arch/x86/include/asm/futex.h
10551 @@ -11,16 +11,18 @@
10552 #include <asm/processor.h>
10553
10554 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10555 + typecheck(u32 __user *, uaddr); \
10556 asm volatile("1:\t" insn "\n" \
10557 "2:\t.section .fixup,\"ax\"\n" \
10558 "3:\tmov\t%3, %1\n" \
10559 "\tjmp\t2b\n" \
10560 "\t.previous\n" \
10561 _ASM_EXTABLE(1b, 3b) \
10562 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10563 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10564 : "i" (-EFAULT), "0" (oparg), "1" (0))
10565
10566 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10567 + typecheck(u32 __user *, uaddr); \
10568 asm volatile("1:\tmovl %2, %0\n" \
10569 "\tmovl\t%0, %3\n" \
10570 "\t" insn "\n" \
10571 @@ -33,7 +35,7 @@
10572 _ASM_EXTABLE(1b, 4b) \
10573 _ASM_EXTABLE(2b, 4b) \
10574 : "=&a" (oldval), "=&r" (ret), \
10575 - "+m" (*uaddr), "=&r" (tem) \
10576 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10577 : "r" (oparg), "i" (-EFAULT), "1" (0))
10578
10579 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10580 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10581
10582 switch (op) {
10583 case FUTEX_OP_SET:
10584 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10585 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10586 break;
10587 case FUTEX_OP_ADD:
10588 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10589 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10590 uaddr, oparg);
10591 break;
10592 case FUTEX_OP_OR:
10593 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10594 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10595 return -EFAULT;
10596
10597 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10598 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10599 "2:\t.section .fixup, \"ax\"\n"
10600 "3:\tmov %3, %0\n"
10601 "\tjmp 2b\n"
10602 "\t.previous\n"
10603 _ASM_EXTABLE(1b, 3b)
10604 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10605 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10606 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10607 : "memory"
10608 );
10609 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10610 index eb92a6e..b98b2f4 100644
10611 --- a/arch/x86/include/asm/hw_irq.h
10612 +++ b/arch/x86/include/asm/hw_irq.h
10613 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10614 extern void enable_IO_APIC(void);
10615
10616 /* Statistics */
10617 -extern atomic_t irq_err_count;
10618 -extern atomic_t irq_mis_count;
10619 +extern atomic_unchecked_t irq_err_count;
10620 +extern atomic_unchecked_t irq_mis_count;
10621
10622 /* EISA */
10623 extern void eisa_set_level_irq(unsigned int irq);
10624 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10625 index d8e8eef..99f81ae 100644
10626 --- a/arch/x86/include/asm/io.h
10627 +++ b/arch/x86/include/asm/io.h
10628 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10629
10630 #include <linux/vmalloc.h>
10631
10632 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10633 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10634 +{
10635 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10636 +}
10637 +
10638 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10639 +{
10640 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10641 +}
10642 +
10643 /*
10644 * Convert a virtual cached pointer to an uncached pointer
10645 */
10646 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10647 index bba3cf8..06bc8da 100644
10648 --- a/arch/x86/include/asm/irqflags.h
10649 +++ b/arch/x86/include/asm/irqflags.h
10650 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10651 sti; \
10652 sysexit
10653
10654 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10655 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10656 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10657 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10658 +
10659 #else
10660 #define INTERRUPT_RETURN iret
10661 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10662 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10663 index 5478825..839e88c 100644
10664 --- a/arch/x86/include/asm/kprobes.h
10665 +++ b/arch/x86/include/asm/kprobes.h
10666 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10667 #define RELATIVEJUMP_SIZE 5
10668 #define RELATIVECALL_OPCODE 0xe8
10669 #define RELATIVE_ADDR_SIZE 4
10670 -#define MAX_STACK_SIZE 64
10671 -#define MIN_STACK_SIZE(ADDR) \
10672 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10673 - THREAD_SIZE - (unsigned long)(ADDR))) \
10674 - ? (MAX_STACK_SIZE) \
10675 - : (((unsigned long)current_thread_info()) + \
10676 - THREAD_SIZE - (unsigned long)(ADDR)))
10677 +#define MAX_STACK_SIZE 64UL
10678 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10679
10680 #define flush_insn_slot(p) do { } while (0)
10681
10682 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10683 index e216ba0..453f6ec 100644
10684 --- a/arch/x86/include/asm/kvm_host.h
10685 +++ b/arch/x86/include/asm/kvm_host.h
10686 @@ -679,7 +679,7 @@ struct kvm_x86_ops {
10687 int (*check_intercept)(struct kvm_vcpu *vcpu,
10688 struct x86_instruction_info *info,
10689 enum x86_intercept_stage stage);
10690 -};
10691 +} __do_const;
10692
10693 struct kvm_arch_async_pf {
10694 u32 token;
10695 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10696 index c8bed0d..e5721fa 100644
10697 --- a/arch/x86/include/asm/local.h
10698 +++ b/arch/x86/include/asm/local.h
10699 @@ -17,26 +17,58 @@ typedef struct {
10700
10701 static inline void local_inc(local_t *l)
10702 {
10703 - asm volatile(_ASM_INC "%0"
10704 + asm volatile(_ASM_INC "%0\n"
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + "jno 0f\n"
10708 + _ASM_DEC "%0\n"
10709 + "int $4\n0:\n"
10710 + _ASM_EXTABLE(0b, 0b)
10711 +#endif
10712 +
10713 : "+m" (l->a.counter));
10714 }
10715
10716 static inline void local_dec(local_t *l)
10717 {
10718 - asm volatile(_ASM_DEC "%0"
10719 + asm volatile(_ASM_DEC "%0\n"
10720 +
10721 +#ifdef CONFIG_PAX_REFCOUNT
10722 + "jno 0f\n"
10723 + _ASM_INC "%0\n"
10724 + "int $4\n0:\n"
10725 + _ASM_EXTABLE(0b, 0b)
10726 +#endif
10727 +
10728 : "+m" (l->a.counter));
10729 }
10730
10731 static inline void local_add(long i, local_t *l)
10732 {
10733 - asm volatile(_ASM_ADD "%1,%0"
10734 + asm volatile(_ASM_ADD "%1,%0\n"
10735 +
10736 +#ifdef CONFIG_PAX_REFCOUNT
10737 + "jno 0f\n"
10738 + _ASM_SUB "%1,%0\n"
10739 + "int $4\n0:\n"
10740 + _ASM_EXTABLE(0b, 0b)
10741 +#endif
10742 +
10743 : "+m" (l->a.counter)
10744 : "ir" (i));
10745 }
10746
10747 static inline void local_sub(long i, local_t *l)
10748 {
10749 - asm volatile(_ASM_SUB "%1,%0"
10750 + asm volatile(_ASM_SUB "%1,%0\n"
10751 +
10752 +#ifdef CONFIG_PAX_REFCOUNT
10753 + "jno 0f\n"
10754 + _ASM_ADD "%1,%0\n"
10755 + "int $4\n0:\n"
10756 + _ASM_EXTABLE(0b, 0b)
10757 +#endif
10758 +
10759 : "+m" (l->a.counter)
10760 : "ir" (i));
10761 }
10762 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10763 {
10764 unsigned char c;
10765
10766 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10767 + asm volatile(_ASM_SUB "%2,%0\n"
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + "jno 0f\n"
10771 + _ASM_ADD "%2,%0\n"
10772 + "int $4\n0:\n"
10773 + _ASM_EXTABLE(0b, 0b)
10774 +#endif
10775 +
10776 + "sete %1\n"
10777 : "+m" (l->a.counter), "=qm" (c)
10778 : "ir" (i) : "memory");
10779 return c;
10780 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10781 {
10782 unsigned char c;
10783
10784 - asm volatile(_ASM_DEC "%0; sete %1"
10785 + asm volatile(_ASM_DEC "%0\n"
10786 +
10787 +#ifdef CONFIG_PAX_REFCOUNT
10788 + "jno 0f\n"
10789 + _ASM_INC "%0\n"
10790 + "int $4\n0:\n"
10791 + _ASM_EXTABLE(0b, 0b)
10792 +#endif
10793 +
10794 + "sete %1\n"
10795 : "+m" (l->a.counter), "=qm" (c)
10796 : : "memory");
10797 return c != 0;
10798 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10799 {
10800 unsigned char c;
10801
10802 - asm volatile(_ASM_INC "%0; sete %1"
10803 + asm volatile(_ASM_INC "%0\n"
10804 +
10805 +#ifdef CONFIG_PAX_REFCOUNT
10806 + "jno 0f\n"
10807 + _ASM_DEC "%0\n"
10808 + "int $4\n0:\n"
10809 + _ASM_EXTABLE(0b, 0b)
10810 +#endif
10811 +
10812 + "sete %1\n"
10813 : "+m" (l->a.counter), "=qm" (c)
10814 : : "memory");
10815 return c != 0;
10816 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10817 {
10818 unsigned char c;
10819
10820 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10821 + asm volatile(_ASM_ADD "%2,%0\n"
10822 +
10823 +#ifdef CONFIG_PAX_REFCOUNT
10824 + "jno 0f\n"
10825 + _ASM_SUB "%2,%0\n"
10826 + "int $4\n0:\n"
10827 + _ASM_EXTABLE(0b, 0b)
10828 +#endif
10829 +
10830 + "sets %1\n"
10831 : "+m" (l->a.counter), "=qm" (c)
10832 : "ir" (i) : "memory");
10833 return c;
10834 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10835 #endif
10836 /* Modern 486+ processor */
10837 __i = i;
10838 - asm volatile(_ASM_XADD "%0, %1;"
10839 + asm volatile(_ASM_XADD "%0, %1\n"
10840 +
10841 +#ifdef CONFIG_PAX_REFCOUNT
10842 + "jno 0f\n"
10843 + _ASM_MOV "%0,%1\n"
10844 + "int $4\n0:\n"
10845 + _ASM_EXTABLE(0b, 0b)
10846 +#endif
10847 +
10848 : "+r" (i), "+m" (l->a.counter)
10849 : : "memory");
10850 return i + __i;
10851 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10852 index 593e51d..fa69c9a 100644
10853 --- a/arch/x86/include/asm/mman.h
10854 +++ b/arch/x86/include/asm/mman.h
10855 @@ -5,4 +5,14 @@
10856
10857 #include <asm-generic/mman.h>
10858
10859 +#ifdef __KERNEL__
10860 +#ifndef __ASSEMBLY__
10861 +#ifdef CONFIG_X86_32
10862 +#define arch_mmap_check i386_mmap_check
10863 +int i386_mmap_check(unsigned long addr, unsigned long len,
10864 + unsigned long flags);
10865 +#endif
10866 +#endif
10867 +#endif
10868 +
10869 #endif /* _ASM_X86_MMAN_H */
10870 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10871 index 5f55e69..e20bfb1 100644
10872 --- a/arch/x86/include/asm/mmu.h
10873 +++ b/arch/x86/include/asm/mmu.h
10874 @@ -9,7 +9,7 @@
10875 * we put the segment information here.
10876 */
10877 typedef struct {
10878 - void *ldt;
10879 + struct desc_struct *ldt;
10880 int size;
10881
10882 #ifdef CONFIG_X86_64
10883 @@ -18,7 +18,19 @@ typedef struct {
10884 #endif
10885
10886 struct mutex lock;
10887 - void *vdso;
10888 + unsigned long vdso;
10889 +
10890 +#ifdef CONFIG_X86_32
10891 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10892 + unsigned long user_cs_base;
10893 + unsigned long user_cs_limit;
10894 +
10895 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10896 + cpumask_t cpu_user_cs_mask;
10897 +#endif
10898 +
10899 +#endif
10900 +#endif
10901 } mm_context_t;
10902
10903 #ifdef CONFIG_SMP
10904 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10905 index 6902152..da4283a 100644
10906 --- a/arch/x86/include/asm/mmu_context.h
10907 +++ b/arch/x86/include/asm/mmu_context.h
10908 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10909
10910 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10911 {
10912 +
10913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10914 + unsigned int i;
10915 + pgd_t *pgd;
10916 +
10917 + pax_open_kernel();
10918 + pgd = get_cpu_pgd(smp_processor_id());
10919 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10920 + set_pgd_batched(pgd+i, native_make_pgd(0));
10921 + pax_close_kernel();
10922 +#endif
10923 +
10924 #ifdef CONFIG_SMP
10925 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10926 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10927 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10928 struct task_struct *tsk)
10929 {
10930 unsigned cpu = smp_processor_id();
10931 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10932 + int tlbstate = TLBSTATE_OK;
10933 +#endif
10934
10935 if (likely(prev != next)) {
10936 #ifdef CONFIG_SMP
10937 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10938 + tlbstate = percpu_read(cpu_tlbstate.state);
10939 +#endif
10940 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10941 percpu_write(cpu_tlbstate.active_mm, next);
10942 #endif
10943 cpumask_set_cpu(cpu, mm_cpumask(next));
10944
10945 /* Re-load page tables */
10946 +#ifdef CONFIG_PAX_PER_CPU_PGD
10947 + pax_open_kernel();
10948 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10949 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10950 + pax_close_kernel();
10951 + load_cr3(get_cpu_pgd(cpu));
10952 +#else
10953 load_cr3(next->pgd);
10954 +#endif
10955
10956 /* stop flush ipis for the previous mm */
10957 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10958 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10959 */
10960 if (unlikely(prev->context.ldt != next->context.ldt))
10961 load_LDT_nolock(&next->context);
10962 - }
10963 +
10964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10965 + if (!(__supported_pte_mask & _PAGE_NX)) {
10966 + smp_mb__before_clear_bit();
10967 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10968 + smp_mb__after_clear_bit();
10969 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10970 + }
10971 +#endif
10972 +
10973 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10974 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10975 + prev->context.user_cs_limit != next->context.user_cs_limit))
10976 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10977 #ifdef CONFIG_SMP
10978 + else if (unlikely(tlbstate != TLBSTATE_OK))
10979 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10980 +#endif
10981 +#endif
10982 +
10983 + }
10984 else {
10985 +
10986 +#ifdef CONFIG_PAX_PER_CPU_PGD
10987 + pax_open_kernel();
10988 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10989 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10990 + pax_close_kernel();
10991 + load_cr3(get_cpu_pgd(cpu));
10992 +#endif
10993 +
10994 +#ifdef CONFIG_SMP
10995 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10996 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10997
10998 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10999 * tlb flush IPI delivery. We must reload CR3
11000 * to make sure to use no freed page tables.
11001 */
11002 +
11003 +#ifndef CONFIG_PAX_PER_CPU_PGD
11004 load_cr3(next->pgd);
11005 +#endif
11006 +
11007 load_LDT_nolock(&next->context);
11008 +
11009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11010 + if (!(__supported_pte_mask & _PAGE_NX))
11011 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11012 +#endif
11013 +
11014 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11015 +#ifdef CONFIG_PAX_PAGEEXEC
11016 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11017 +#endif
11018 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11019 +#endif
11020 +
11021 }
11022 +#endif
11023 }
11024 -#endif
11025 }
11026
11027 #define activate_mm(prev, next) \
11028 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11029 index 9eae775..c914fea 100644
11030 --- a/arch/x86/include/asm/module.h
11031 +++ b/arch/x86/include/asm/module.h
11032 @@ -5,6 +5,7 @@
11033
11034 #ifdef CONFIG_X86_64
11035 /* X86_64 does not define MODULE_PROC_FAMILY */
11036 +#define MODULE_PROC_FAMILY ""
11037 #elif defined CONFIG_M386
11038 #define MODULE_PROC_FAMILY "386 "
11039 #elif defined CONFIG_M486
11040 @@ -59,8 +60,20 @@
11041 #error unknown processor family
11042 #endif
11043
11044 -#ifdef CONFIG_X86_32
11045 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11046 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11047 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11048 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11049 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11050 +#else
11051 +#define MODULE_PAX_KERNEXEC ""
11052 #endif
11053
11054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11055 +#define MODULE_PAX_UDEREF "UDEREF "
11056 +#else
11057 +#define MODULE_PAX_UDEREF ""
11058 +#endif
11059 +
11060 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11061 +
11062 #endif /* _ASM_X86_MODULE_H */
11063 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11064 index 7639dbf..e08a58c 100644
11065 --- a/arch/x86/include/asm/page_64_types.h
11066 +++ b/arch/x86/include/asm/page_64_types.h
11067 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11068
11069 /* duplicated to the one in bootmem.h */
11070 extern unsigned long max_pfn;
11071 -extern unsigned long phys_base;
11072 +extern const unsigned long phys_base;
11073
11074 extern unsigned long __phys_addr(unsigned long);
11075 #define __phys_reloc_hide(x) (x)
11076 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11077 index aa0f913..0c5bc6a 100644
11078 --- a/arch/x86/include/asm/paravirt.h
11079 +++ b/arch/x86/include/asm/paravirt.h
11080 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11081 val);
11082 }
11083
11084 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11085 +{
11086 + pgdval_t val = native_pgd_val(pgd);
11087 +
11088 + if (sizeof(pgdval_t) > sizeof(long))
11089 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11090 + val, (u64)val >> 32);
11091 + else
11092 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11093 + val);
11094 +}
11095 +
11096 static inline void pgd_clear(pgd_t *pgdp)
11097 {
11098 set_pgd(pgdp, __pgd(0));
11099 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11100 pv_mmu_ops.set_fixmap(idx, phys, flags);
11101 }
11102
11103 +#ifdef CONFIG_PAX_KERNEXEC
11104 +static inline unsigned long pax_open_kernel(void)
11105 +{
11106 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11107 +}
11108 +
11109 +static inline unsigned long pax_close_kernel(void)
11110 +{
11111 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11112 +}
11113 +#else
11114 +static inline unsigned long pax_open_kernel(void) { return 0; }
11115 +static inline unsigned long pax_close_kernel(void) { return 0; }
11116 +#endif
11117 +
11118 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11119
11120 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11121 @@ -965,7 +992,7 @@ extern void default_banner(void);
11122
11123 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11124 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11125 -#define PARA_INDIRECT(addr) *%cs:addr
11126 +#define PARA_INDIRECT(addr) *%ss:addr
11127 #endif
11128
11129 #define INTERRUPT_RETURN \
11130 @@ -1042,6 +1069,21 @@ extern void default_banner(void);
11131 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11132 CLBR_NONE, \
11133 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11134 +
11135 +#define GET_CR0_INTO_RDI \
11136 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11137 + mov %rax,%rdi
11138 +
11139 +#define SET_RDI_INTO_CR0 \
11140 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11141 +
11142 +#define GET_CR3_INTO_RDI \
11143 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11144 + mov %rax,%rdi
11145 +
11146 +#define SET_RDI_INTO_CR3 \
11147 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11148 +
11149 #endif /* CONFIG_X86_32 */
11150
11151 #endif /* __ASSEMBLY__ */
11152 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11153 index 8e8b9a4..f07d725 100644
11154 --- a/arch/x86/include/asm/paravirt_types.h
11155 +++ b/arch/x86/include/asm/paravirt_types.h
11156 @@ -84,20 +84,20 @@ struct pv_init_ops {
11157 */
11158 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11159 unsigned long addr, unsigned len);
11160 -};
11161 +} __no_const;
11162
11163
11164 struct pv_lazy_ops {
11165 /* Set deferred update mode, used for batching operations. */
11166 void (*enter)(void);
11167 void (*leave)(void);
11168 -};
11169 +} __no_const;
11170
11171 struct pv_time_ops {
11172 unsigned long long (*sched_clock)(void);
11173 unsigned long long (*steal_clock)(int cpu);
11174 unsigned long (*get_tsc_khz)(void);
11175 -};
11176 +} __no_const;
11177
11178 struct pv_cpu_ops {
11179 /* hooks for various privileged instructions */
11180 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11181
11182 void (*start_context_switch)(struct task_struct *prev);
11183 void (*end_context_switch)(struct task_struct *next);
11184 -};
11185 +} __no_const;
11186
11187 struct pv_irq_ops {
11188 /*
11189 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11190 unsigned long start_eip,
11191 unsigned long start_esp);
11192 #endif
11193 -};
11194 +} __no_const;
11195
11196 struct pv_mmu_ops {
11197 unsigned long (*read_cr2)(void);
11198 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11199 struct paravirt_callee_save make_pud;
11200
11201 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11202 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11203 #endif /* PAGETABLE_LEVELS == 4 */
11204 #endif /* PAGETABLE_LEVELS >= 3 */
11205
11206 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11207 an mfn. We can tell which is which from the index. */
11208 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11209 phys_addr_t phys, pgprot_t flags);
11210 +
11211 +#ifdef CONFIG_PAX_KERNEXEC
11212 + unsigned long (*pax_open_kernel)(void);
11213 + unsigned long (*pax_close_kernel)(void);
11214 +#endif
11215 +
11216 };
11217
11218 struct arch_spinlock;
11219 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11220 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11221 int (*spin_trylock)(struct arch_spinlock *lock);
11222 void (*spin_unlock)(struct arch_spinlock *lock);
11223 -};
11224 +} __no_const;
11225
11226 /* This contains all the paravirt structures: we get a convenient
11227 * number for each function using the offset which we use to indicate
11228 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11229 index b4389a4..7024269 100644
11230 --- a/arch/x86/include/asm/pgalloc.h
11231 +++ b/arch/x86/include/asm/pgalloc.h
11232 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11233 pmd_t *pmd, pte_t *pte)
11234 {
11235 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11236 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11237 +}
11238 +
11239 +static inline void pmd_populate_user(struct mm_struct *mm,
11240 + pmd_t *pmd, pte_t *pte)
11241 +{
11242 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11243 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11244 }
11245
11246 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11247
11248 #ifdef CONFIG_X86_PAE
11249 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11250 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11251 +{
11252 + pud_populate(mm, pudp, pmd);
11253 +}
11254 #else /* !CONFIG_X86_PAE */
11255 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11256 {
11257 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11258 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11259 }
11260 +
11261 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11262 +{
11263 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11264 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11265 +}
11266 #endif /* CONFIG_X86_PAE */
11267
11268 #if PAGETABLE_LEVELS > 3
11269 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11270 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11271 }
11272
11273 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11274 +{
11275 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11276 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11277 +}
11278 +
11279 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11280 {
11281 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11282 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11283 index 98391db..8f6984e 100644
11284 --- a/arch/x86/include/asm/pgtable-2level.h
11285 +++ b/arch/x86/include/asm/pgtable-2level.h
11286 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11287
11288 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11289 {
11290 + pax_open_kernel();
11291 *pmdp = pmd;
11292 + pax_close_kernel();
11293 }
11294
11295 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11296 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11297 index cb00ccc..17e9054 100644
11298 --- a/arch/x86/include/asm/pgtable-3level.h
11299 +++ b/arch/x86/include/asm/pgtable-3level.h
11300 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11301
11302 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11303 {
11304 + pax_open_kernel();
11305 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11306 + pax_close_kernel();
11307 }
11308
11309 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11310 {
11311 + pax_open_kernel();
11312 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11313 + pax_close_kernel();
11314 }
11315
11316 /*
11317 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11318 index 49afb3f..91a8c63 100644
11319 --- a/arch/x86/include/asm/pgtable.h
11320 +++ b/arch/x86/include/asm/pgtable.h
11321 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11322
11323 #ifndef __PAGETABLE_PUD_FOLDED
11324 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11325 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11326 #define pgd_clear(pgd) native_pgd_clear(pgd)
11327 #endif
11328
11329 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11330
11331 #define arch_end_context_switch(prev) do {} while(0)
11332
11333 +#define pax_open_kernel() native_pax_open_kernel()
11334 +#define pax_close_kernel() native_pax_close_kernel()
11335 #endif /* CONFIG_PARAVIRT */
11336
11337 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11338 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11339 +
11340 +#ifdef CONFIG_PAX_KERNEXEC
11341 +static inline unsigned long native_pax_open_kernel(void)
11342 +{
11343 + unsigned long cr0;
11344 +
11345 + preempt_disable();
11346 + barrier();
11347 + cr0 = read_cr0() ^ X86_CR0_WP;
11348 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11349 + write_cr0(cr0);
11350 + return cr0 ^ X86_CR0_WP;
11351 +}
11352 +
11353 +static inline unsigned long native_pax_close_kernel(void)
11354 +{
11355 + unsigned long cr0;
11356 +
11357 + cr0 = read_cr0() ^ X86_CR0_WP;
11358 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11359 + write_cr0(cr0);
11360 + barrier();
11361 + preempt_enable_no_resched();
11362 + return cr0 ^ X86_CR0_WP;
11363 +}
11364 +#else
11365 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11366 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11367 +#endif
11368 +
11369 /*
11370 * The following only work if pte_present() is true.
11371 * Undefined behaviour if not..
11372 */
11373 +static inline int pte_user(pte_t pte)
11374 +{
11375 + return pte_val(pte) & _PAGE_USER;
11376 +}
11377 +
11378 static inline int pte_dirty(pte_t pte)
11379 {
11380 return pte_flags(pte) & _PAGE_DIRTY;
11381 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11382 return pte_clear_flags(pte, _PAGE_RW);
11383 }
11384
11385 +static inline pte_t pte_mkread(pte_t pte)
11386 +{
11387 + return __pte(pte_val(pte) | _PAGE_USER);
11388 +}
11389 +
11390 static inline pte_t pte_mkexec(pte_t pte)
11391 {
11392 - return pte_clear_flags(pte, _PAGE_NX);
11393 +#ifdef CONFIG_X86_PAE
11394 + if (__supported_pte_mask & _PAGE_NX)
11395 + return pte_clear_flags(pte, _PAGE_NX);
11396 + else
11397 +#endif
11398 + return pte_set_flags(pte, _PAGE_USER);
11399 +}
11400 +
11401 +static inline pte_t pte_exprotect(pte_t pte)
11402 +{
11403 +#ifdef CONFIG_X86_PAE
11404 + if (__supported_pte_mask & _PAGE_NX)
11405 + return pte_set_flags(pte, _PAGE_NX);
11406 + else
11407 +#endif
11408 + return pte_clear_flags(pte, _PAGE_USER);
11409 }
11410
11411 static inline pte_t pte_mkdirty(pte_t pte)
11412 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11413 #endif
11414
11415 #ifndef __ASSEMBLY__
11416 +
11417 +#ifdef CONFIG_PAX_PER_CPU_PGD
11418 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11419 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11420 +{
11421 + return cpu_pgd[cpu];
11422 +}
11423 +#endif
11424 +
11425 #include <linux/mm_types.h>
11426
11427 static inline int pte_none(pte_t pte)
11428 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11429
11430 static inline int pgd_bad(pgd_t pgd)
11431 {
11432 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11433 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11434 }
11435
11436 static inline int pgd_none(pgd_t pgd)
11437 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11438 * pgd_offset() returns a (pgd_t *)
11439 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11440 */
11441 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11442 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11443 +
11444 +#ifdef CONFIG_PAX_PER_CPU_PGD
11445 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11446 +#endif
11447 +
11448 /*
11449 * a shortcut which implies the use of the kernel's pgd, instead
11450 * of a process's
11451 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11452 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11453 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11454
11455 +#ifdef CONFIG_X86_32
11456 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11457 +#else
11458 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11459 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11460 +
11461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11462 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11463 +#else
11464 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11465 +#endif
11466 +
11467 +#endif
11468 +
11469 #ifndef __ASSEMBLY__
11470
11471 extern int direct_gbpages;
11472 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11473 * dst and src can be on the same page, but the range must not overlap,
11474 * and must not cross a page boundary.
11475 */
11476 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11477 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11478 {
11479 - memcpy(dst, src, count * sizeof(pgd_t));
11480 + pax_open_kernel();
11481 + while (count--)
11482 + *dst++ = *src++;
11483 + pax_close_kernel();
11484 }
11485
11486 +#ifdef CONFIG_PAX_PER_CPU_PGD
11487 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11488 +#endif
11489 +
11490 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11491 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11492 +#else
11493 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11494 +#endif
11495
11496 #include <asm-generic/pgtable.h>
11497 #endif /* __ASSEMBLY__ */
11498 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11499 index 0c92113..34a77c6 100644
11500 --- a/arch/x86/include/asm/pgtable_32.h
11501 +++ b/arch/x86/include/asm/pgtable_32.h
11502 @@ -25,9 +25,6 @@
11503 struct mm_struct;
11504 struct vm_area_struct;
11505
11506 -extern pgd_t swapper_pg_dir[1024];
11507 -extern pgd_t initial_page_table[1024];
11508 -
11509 static inline void pgtable_cache_init(void) { }
11510 static inline void check_pgt_cache(void) { }
11511 void paging_init(void);
11512 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11513 # include <asm/pgtable-2level.h>
11514 #endif
11515
11516 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11517 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11518 +#ifdef CONFIG_X86_PAE
11519 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11520 +#endif
11521 +
11522 #if defined(CONFIG_HIGHPTE)
11523 #define pte_offset_map(dir, address) \
11524 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11525 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11526 /* Clear a kernel PTE and flush it from the TLB */
11527 #define kpte_clear_flush(ptep, vaddr) \
11528 do { \
11529 + pax_open_kernel(); \
11530 pte_clear(&init_mm, (vaddr), (ptep)); \
11531 + pax_close_kernel(); \
11532 __flush_tlb_one((vaddr)); \
11533 } while (0)
11534
11535 @@ -74,6 +79,9 @@ do { \
11536
11537 #endif /* !__ASSEMBLY__ */
11538
11539 +#define HAVE_ARCH_UNMAPPED_AREA
11540 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11541 +
11542 /*
11543 * kern_addr_valid() is (1) for FLATMEM and (0) for
11544 * SPARSEMEM and DISCONTIGMEM
11545 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11546 index ed5903b..c7fe163 100644
11547 --- a/arch/x86/include/asm/pgtable_32_types.h
11548 +++ b/arch/x86/include/asm/pgtable_32_types.h
11549 @@ -8,7 +8,7 @@
11550 */
11551 #ifdef CONFIG_X86_PAE
11552 # include <asm/pgtable-3level_types.h>
11553 -# define PMD_SIZE (1UL << PMD_SHIFT)
11554 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11555 # define PMD_MASK (~(PMD_SIZE - 1))
11556 #else
11557 # include <asm/pgtable-2level_types.h>
11558 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11559 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11560 #endif
11561
11562 +#ifdef CONFIG_PAX_KERNEXEC
11563 +#ifndef __ASSEMBLY__
11564 +extern unsigned char MODULES_EXEC_VADDR[];
11565 +extern unsigned char MODULES_EXEC_END[];
11566 +#endif
11567 +#include <asm/boot.h>
11568 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11569 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11570 +#else
11571 +#define ktla_ktva(addr) (addr)
11572 +#define ktva_ktla(addr) (addr)
11573 +#endif
11574 +
11575 #define MODULES_VADDR VMALLOC_START
11576 #define MODULES_END VMALLOC_END
11577 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11578 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11579 index 975f709..9f779c9 100644
11580 --- a/arch/x86/include/asm/pgtable_64.h
11581 +++ b/arch/x86/include/asm/pgtable_64.h
11582 @@ -16,10 +16,14 @@
11583
11584 extern pud_t level3_kernel_pgt[512];
11585 extern pud_t level3_ident_pgt[512];
11586 +extern pud_t level3_vmalloc_start_pgt[512];
11587 +extern pud_t level3_vmalloc_end_pgt[512];
11588 +extern pud_t level3_vmemmap_pgt[512];
11589 +extern pud_t level2_vmemmap_pgt[512];
11590 extern pmd_t level2_kernel_pgt[512];
11591 extern pmd_t level2_fixmap_pgt[512];
11592 -extern pmd_t level2_ident_pgt[512];
11593 -extern pgd_t init_level4_pgt[];
11594 +extern pmd_t level2_ident_pgt[512*2];
11595 +extern pgd_t init_level4_pgt[512];
11596
11597 #define swapper_pg_dir init_level4_pgt
11598
11599 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11600
11601 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11602 {
11603 + pax_open_kernel();
11604 *pmdp = pmd;
11605 + pax_close_kernel();
11606 }
11607
11608 static inline void native_pmd_clear(pmd_t *pmd)
11609 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11610
11611 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11612 {
11613 + pax_open_kernel();
11614 *pudp = pud;
11615 + pax_close_kernel();
11616 }
11617
11618 static inline void native_pud_clear(pud_t *pud)
11619 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11620
11621 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11622 {
11623 + pax_open_kernel();
11624 + *pgdp = pgd;
11625 + pax_close_kernel();
11626 +}
11627 +
11628 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11629 +{
11630 *pgdp = pgd;
11631 }
11632
11633 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11634 index 766ea16..5b96cb3 100644
11635 --- a/arch/x86/include/asm/pgtable_64_types.h
11636 +++ b/arch/x86/include/asm/pgtable_64_types.h
11637 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11638 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11639 #define MODULES_END _AC(0xffffffffff000000, UL)
11640 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11641 +#define MODULES_EXEC_VADDR MODULES_VADDR
11642 +#define MODULES_EXEC_END MODULES_END
11643 +
11644 +#define ktla_ktva(addr) (addr)
11645 +#define ktva_ktla(addr) (addr)
11646
11647 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11648 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11649 index 013286a..8b42f4f 100644
11650 --- a/arch/x86/include/asm/pgtable_types.h
11651 +++ b/arch/x86/include/asm/pgtable_types.h
11652 @@ -16,13 +16,12 @@
11653 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11654 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11655 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11656 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11657 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11658 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11659 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11660 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11661 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11662 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11663 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11664 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11665 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11666 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11667
11668 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11669 @@ -40,7 +39,6 @@
11670 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11671 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11672 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11673 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11674 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11675 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11676 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11677 @@ -57,8 +55,10 @@
11678
11679 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11680 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11681 -#else
11682 +#elif defined(CONFIG_KMEMCHECK)
11683 #define _PAGE_NX (_AT(pteval_t, 0))
11684 +#else
11685 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11686 #endif
11687
11688 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11689 @@ -96,6 +96,9 @@
11690 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11691 _PAGE_ACCESSED)
11692
11693 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11694 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11695 +
11696 #define __PAGE_KERNEL_EXEC \
11697 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11698 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11699 @@ -106,7 +109,7 @@
11700 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11701 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11702 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11703 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11704 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11705 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11706 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11707 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11708 @@ -168,8 +171,8 @@
11709 * bits are combined, this will alow user to access the high address mapped
11710 * VDSO in the presence of CONFIG_COMPAT_VDSO
11711 */
11712 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11713 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11714 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11715 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11716 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11717 #endif
11718
11719 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11720 {
11721 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11722 }
11723 +#endif
11724
11725 +#if PAGETABLE_LEVELS == 3
11726 +#include <asm-generic/pgtable-nopud.h>
11727 +#endif
11728 +
11729 +#if PAGETABLE_LEVELS == 2
11730 +#include <asm-generic/pgtable-nopmd.h>
11731 +#endif
11732 +
11733 +#ifndef __ASSEMBLY__
11734 #if PAGETABLE_LEVELS > 3
11735 typedef struct { pudval_t pud; } pud_t;
11736
11737 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11738 return pud.pud;
11739 }
11740 #else
11741 -#include <asm-generic/pgtable-nopud.h>
11742 -
11743 static inline pudval_t native_pud_val(pud_t pud)
11744 {
11745 return native_pgd_val(pud.pgd);
11746 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11747 return pmd.pmd;
11748 }
11749 #else
11750 -#include <asm-generic/pgtable-nopmd.h>
11751 -
11752 static inline pmdval_t native_pmd_val(pmd_t pmd)
11753 {
11754 return native_pgd_val(pmd.pud.pgd);
11755 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11756
11757 extern pteval_t __supported_pte_mask;
11758 extern void set_nx(void);
11759 -extern int nx_enabled;
11760
11761 #define pgprot_writecombine pgprot_writecombine
11762 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11763 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11764 index 4fa7dcc..764e33a 100644
11765 --- a/arch/x86/include/asm/processor.h
11766 +++ b/arch/x86/include/asm/processor.h
11767 @@ -276,7 +276,7 @@ struct tss_struct {
11768
11769 } ____cacheline_aligned;
11770
11771 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11772 +extern struct tss_struct init_tss[NR_CPUS];
11773
11774 /*
11775 * Save the original ist values for checking stack pointers during debugging
11776 @@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11777 */
11778 #define TASK_SIZE PAGE_OFFSET
11779 #define TASK_SIZE_MAX TASK_SIZE
11780 +
11781 +#ifdef CONFIG_PAX_SEGMEXEC
11782 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11783 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11784 +#else
11785 #define STACK_TOP TASK_SIZE
11786 -#define STACK_TOP_MAX STACK_TOP
11787 +#endif
11788 +
11789 +#define STACK_TOP_MAX TASK_SIZE
11790
11791 #define INIT_THREAD { \
11792 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11793 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11794 .vm86_info = NULL, \
11795 .sysenter_cs = __KERNEL_CS, \
11796 .io_bitmap_ptr = NULL, \
11797 @@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11798 */
11799 #define INIT_TSS { \
11800 .x86_tss = { \
11801 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11802 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11803 .ss0 = __KERNEL_DS, \
11804 .ss1 = __KERNEL_CS, \
11805 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11806 @@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11807 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11808
11809 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11810 -#define KSTK_TOP(info) \
11811 -({ \
11812 - unsigned long *__ptr = (unsigned long *)(info); \
11813 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11814 -})
11815 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11816
11817 /*
11818 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11819 @@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11820 #define task_pt_regs(task) \
11821 ({ \
11822 struct pt_regs *__regs__; \
11823 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11824 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11825 __regs__ - 1; \
11826 })
11827
11828 @@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11829 /*
11830 * User space process size. 47bits minus one guard page.
11831 */
11832 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11833 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11834
11835 /* This decides where the kernel will search for a free chunk of vm
11836 * space during mmap's.
11837 */
11838 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11839 - 0xc0000000 : 0xFFFFe000)
11840 + 0xc0000000 : 0xFFFFf000)
11841
11842 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11843 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11844 @@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11845 #define STACK_TOP_MAX TASK_SIZE_MAX
11846
11847 #define INIT_THREAD { \
11848 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11849 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11850 }
11851
11852 #define INIT_TSS { \
11853 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11854 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11855 }
11856
11857 /*
11858 @@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11859 */
11860 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11861
11862 +#ifdef CONFIG_PAX_SEGMEXEC
11863 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11864 +#endif
11865 +
11866 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11867
11868 /* Get/set a process' ability to use the timestamp counter instruction */
11869 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11870
11871 void cpu_idle_wait(void);
11872
11873 -extern unsigned long arch_align_stack(unsigned long sp);
11874 +#define arch_align_stack(x) ((x) & ~0xfUL)
11875 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11876
11877 void default_idle(void);
11878 bool set_pm_idle_to_default(void);
11879
11880 -void stop_this_cpu(void *dummy);
11881 +void stop_this_cpu(void *dummy) __noreturn;
11882
11883 #endif /* _ASM_X86_PROCESSOR_H */
11884 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11885 index dcfde52..dbfea06 100644
11886 --- a/arch/x86/include/asm/ptrace.h
11887 +++ b/arch/x86/include/asm/ptrace.h
11888 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11889 }
11890
11891 /*
11892 - * user_mode_vm(regs) determines whether a register set came from user mode.
11893 + * user_mode(regs) determines whether a register set came from user mode.
11894 * This is true if V8086 mode was enabled OR if the register set was from
11895 * protected mode with RPL-3 CS value. This tricky test checks that with
11896 * one comparison. Many places in the kernel can bypass this full check
11897 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11898 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11899 + * be used.
11900 */
11901 -static inline int user_mode(struct pt_regs *regs)
11902 +static inline int user_mode_novm(struct pt_regs *regs)
11903 {
11904 #ifdef CONFIG_X86_32
11905 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11906 #else
11907 - return !!(regs->cs & 3);
11908 + return !!(regs->cs & SEGMENT_RPL_MASK);
11909 #endif
11910 }
11911
11912 -static inline int user_mode_vm(struct pt_regs *regs)
11913 +static inline int user_mode(struct pt_regs *regs)
11914 {
11915 #ifdef CONFIG_X86_32
11916 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11917 USER_RPL;
11918 #else
11919 - return user_mode(regs);
11920 + return user_mode_novm(regs);
11921 #endif
11922 }
11923
11924 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11925 #ifdef CONFIG_X86_64
11926 static inline bool user_64bit_mode(struct pt_regs *regs)
11927 {
11928 + unsigned long cs = regs->cs & 0xffff;
11929 #ifndef CONFIG_PARAVIRT
11930 /*
11931 * On non-paravirt systems, this is the only long mode CPL 3
11932 * selector. We do not allow long mode selectors in the LDT.
11933 */
11934 - return regs->cs == __USER_CS;
11935 + return cs == __USER_CS;
11936 #else
11937 /* Headers are too twisted for this to go in paravirt.h. */
11938 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11939 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11940 #endif
11941 }
11942 #endif
11943 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11944 index 92f29706..a79cbbb 100644
11945 --- a/arch/x86/include/asm/reboot.h
11946 +++ b/arch/x86/include/asm/reboot.h
11947 @@ -6,19 +6,19 @@
11948 struct pt_regs;
11949
11950 struct machine_ops {
11951 - void (*restart)(char *cmd);
11952 - void (*halt)(void);
11953 - void (*power_off)(void);
11954 + void (* __noreturn restart)(char *cmd);
11955 + void (* __noreturn halt)(void);
11956 + void (* __noreturn power_off)(void);
11957 void (*shutdown)(void);
11958 void (*crash_shutdown)(struct pt_regs *);
11959 - void (*emergency_restart)(void);
11960 -};
11961 + void (* __noreturn emergency_restart)(void);
11962 +} __no_const;
11963
11964 extern struct machine_ops machine_ops;
11965
11966 void native_machine_crash_shutdown(struct pt_regs *regs);
11967 void native_machine_shutdown(void);
11968 -void machine_real_restart(unsigned int type);
11969 +void machine_real_restart(unsigned int type) __noreturn;
11970 /* These must match dispatch_table in reboot_32.S */
11971 #define MRR_BIOS 0
11972 #define MRR_APM 1
11973 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11974 index 2dbe4a7..ce1db00 100644
11975 --- a/arch/x86/include/asm/rwsem.h
11976 +++ b/arch/x86/include/asm/rwsem.h
11977 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11978 {
11979 asm volatile("# beginning down_read\n\t"
11980 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11981 +
11982 +#ifdef CONFIG_PAX_REFCOUNT
11983 + "jno 0f\n"
11984 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11985 + "int $4\n0:\n"
11986 + _ASM_EXTABLE(0b, 0b)
11987 +#endif
11988 +
11989 /* adds 0x00000001 */
11990 " jns 1f\n"
11991 " call call_rwsem_down_read_failed\n"
11992 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11993 "1:\n\t"
11994 " mov %1,%2\n\t"
11995 " add %3,%2\n\t"
11996 +
11997 +#ifdef CONFIG_PAX_REFCOUNT
11998 + "jno 0f\n"
11999 + "sub %3,%2\n"
12000 + "int $4\n0:\n"
12001 + _ASM_EXTABLE(0b, 0b)
12002 +#endif
12003 +
12004 " jle 2f\n\t"
12005 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12006 " jnz 1b\n\t"
12007 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12008 long tmp;
12009 asm volatile("# beginning down_write\n\t"
12010 LOCK_PREFIX " xadd %1,(%2)\n\t"
12011 +
12012 +#ifdef CONFIG_PAX_REFCOUNT
12013 + "jno 0f\n"
12014 + "mov %1,(%2)\n"
12015 + "int $4\n0:\n"
12016 + _ASM_EXTABLE(0b, 0b)
12017 +#endif
12018 +
12019 /* adds 0xffff0001, returns the old value */
12020 " test %1,%1\n\t"
12021 /* was the count 0 before? */
12022 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12023 long tmp;
12024 asm volatile("# beginning __up_read\n\t"
12025 LOCK_PREFIX " xadd %1,(%2)\n\t"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + "mov %1,(%2)\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 /* subtracts 1, returns the old value */
12035 " jns 1f\n\t"
12036 " call call_rwsem_wake\n" /* expects old value in %edx */
12037 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12038 long tmp;
12039 asm volatile("# beginning __up_write\n\t"
12040 LOCK_PREFIX " xadd %1,(%2)\n\t"
12041 +
12042 +#ifdef CONFIG_PAX_REFCOUNT
12043 + "jno 0f\n"
12044 + "mov %1,(%2)\n"
12045 + "int $4\n0:\n"
12046 + _ASM_EXTABLE(0b, 0b)
12047 +#endif
12048 +
12049 /* subtracts 0xffff0001, returns the old value */
12050 " jns 1f\n\t"
12051 " call call_rwsem_wake\n" /* expects old value in %edx */
12052 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12053 {
12054 asm volatile("# beginning __downgrade_write\n\t"
12055 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12056 +
12057 +#ifdef CONFIG_PAX_REFCOUNT
12058 + "jno 0f\n"
12059 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12060 + "int $4\n0:\n"
12061 + _ASM_EXTABLE(0b, 0b)
12062 +#endif
12063 +
12064 /*
12065 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12066 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12067 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12068 */
12069 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12070 {
12071 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12072 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12073 +
12074 +#ifdef CONFIG_PAX_REFCOUNT
12075 + "jno 0f\n"
12076 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12077 + "int $4\n0:\n"
12078 + _ASM_EXTABLE(0b, 0b)
12079 +#endif
12080 +
12081 : "+m" (sem->count)
12082 : "er" (delta));
12083 }
12084 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12085 */
12086 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12087 {
12088 - return delta + xadd(&sem->count, delta);
12089 + return delta + xadd_check_overflow(&sem->count, delta);
12090 }
12091
12092 #endif /* __KERNEL__ */
12093 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12094 index 1654662..5af4157 100644
12095 --- a/arch/x86/include/asm/segment.h
12096 +++ b/arch/x86/include/asm/segment.h
12097 @@ -64,10 +64,15 @@
12098 * 26 - ESPFIX small SS
12099 * 27 - per-cpu [ offset to per-cpu data area ]
12100 * 28 - stack_canary-20 [ for stack protector ]
12101 - * 29 - unused
12102 - * 30 - unused
12103 + * 29 - PCI BIOS CS
12104 + * 30 - PCI BIOS DS
12105 * 31 - TSS for double fault handler
12106 */
12107 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12108 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12109 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12110 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12111 +
12112 #define GDT_ENTRY_TLS_MIN 6
12113 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12114
12115 @@ -79,6 +84,8 @@
12116
12117 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12118
12119 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12120 +
12121 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12122
12123 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12124 @@ -104,6 +111,12 @@
12125 #define __KERNEL_STACK_CANARY 0
12126 #endif
12127
12128 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12129 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12130 +
12131 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12132 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12133 +
12134 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12135
12136 /*
12137 @@ -141,7 +154,7 @@
12138 */
12139
12140 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12141 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12142 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12143
12144
12145 #else
12146 @@ -165,6 +178,8 @@
12147 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12148 #define __USER32_DS __USER_DS
12149
12150 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12151 +
12152 #define GDT_ENTRY_TSS 8 /* needs two entries */
12153 #define GDT_ENTRY_LDT 10 /* needs two entries */
12154 #define GDT_ENTRY_TLS_MIN 12
12155 @@ -185,6 +200,7 @@
12156 #endif
12157
12158 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12159 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12160 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12161 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12162 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12163 @@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12164 {
12165 unsigned long __limit;
12166 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12167 - return __limit + 1;
12168 + return __limit;
12169 }
12170
12171 #endif /* !__ASSEMBLY__ */
12172 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12173 index 0434c40..1714bf0 100644
12174 --- a/arch/x86/include/asm/smp.h
12175 +++ b/arch/x86/include/asm/smp.h
12176 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12177 /* cpus sharing the last level cache: */
12178 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12179 DECLARE_PER_CPU(u16, cpu_llc_id);
12180 -DECLARE_PER_CPU(int, cpu_number);
12181 +DECLARE_PER_CPU(unsigned int, cpu_number);
12182
12183 static inline struct cpumask *cpu_sibling_mask(int cpu)
12184 {
12185 @@ -77,7 +77,7 @@ struct smp_ops {
12186
12187 void (*send_call_func_ipi)(const struct cpumask *mask);
12188 void (*send_call_func_single_ipi)(int cpu);
12189 -};
12190 +} __no_const;
12191
12192 /* Globals due to paravirt */
12193 extern void set_cpu_sibling_map(int cpu);
12194 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12195 extern int safe_smp_processor_id(void);
12196
12197 #elif defined(CONFIG_X86_64_SMP)
12198 -#define raw_smp_processor_id() (percpu_read(cpu_number))
12199 -
12200 -#define stack_smp_processor_id() \
12201 -({ \
12202 - struct thread_info *ti; \
12203 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12204 - ti->cpu; \
12205 -})
12206 +#define raw_smp_processor_id() (percpu_read(cpu_number))
12207 +#define stack_smp_processor_id() raw_smp_processor_id()
12208 #define safe_smp_processor_id() smp_processor_id()
12209
12210 #endif
12211 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12212 index 76bfa2c..12d3fe7 100644
12213 --- a/arch/x86/include/asm/spinlock.h
12214 +++ b/arch/x86/include/asm/spinlock.h
12215 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12216 static inline void arch_read_lock(arch_rwlock_t *rw)
12217 {
12218 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12219 +
12220 +#ifdef CONFIG_PAX_REFCOUNT
12221 + "jno 0f\n"
12222 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12223 + "int $4\n0:\n"
12224 + _ASM_EXTABLE(0b, 0b)
12225 +#endif
12226 +
12227 "jns 1f\n"
12228 "call __read_lock_failed\n\t"
12229 "1:\n"
12230 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12231 static inline void arch_write_lock(arch_rwlock_t *rw)
12232 {
12233 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12234 +
12235 +#ifdef CONFIG_PAX_REFCOUNT
12236 + "jno 0f\n"
12237 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12238 + "int $4\n0:\n"
12239 + _ASM_EXTABLE(0b, 0b)
12240 +#endif
12241 +
12242 "jz 1f\n"
12243 "call __write_lock_failed\n\t"
12244 "1:\n"
12245 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12246
12247 static inline void arch_read_unlock(arch_rwlock_t *rw)
12248 {
12249 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12250 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12251 +
12252 +#ifdef CONFIG_PAX_REFCOUNT
12253 + "jno 0f\n"
12254 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12255 + "int $4\n0:\n"
12256 + _ASM_EXTABLE(0b, 0b)
12257 +#endif
12258 +
12259 :"+m" (rw->lock) : : "memory");
12260 }
12261
12262 static inline void arch_write_unlock(arch_rwlock_t *rw)
12263 {
12264 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12265 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12266 +
12267 +#ifdef CONFIG_PAX_REFCOUNT
12268 + "jno 0f\n"
12269 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12270 + "int $4\n0:\n"
12271 + _ASM_EXTABLE(0b, 0b)
12272 +#endif
12273 +
12274 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12275 }
12276
12277 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12278 index b5d9533..41655fa 100644
12279 --- a/arch/x86/include/asm/stackprotector.h
12280 +++ b/arch/x86/include/asm/stackprotector.h
12281 @@ -47,7 +47,7 @@
12282 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12283 */
12284 #define GDT_STACK_CANARY_INIT \
12285 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12286 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12287
12288 /*
12289 * Initialize the stackprotector canary value.
12290 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12291
12292 static inline void load_stack_canary_segment(void)
12293 {
12294 -#ifdef CONFIG_X86_32
12295 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12296 asm volatile ("mov %0, %%gs" : : "r" (0));
12297 #endif
12298 }
12299 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12300 index 70bbe39..4ae2bd4 100644
12301 --- a/arch/x86/include/asm/stacktrace.h
12302 +++ b/arch/x86/include/asm/stacktrace.h
12303 @@ -11,28 +11,20 @@
12304
12305 extern int kstack_depth_to_print;
12306
12307 -struct thread_info;
12308 +struct task_struct;
12309 struct stacktrace_ops;
12310
12311 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12312 - unsigned long *stack,
12313 - unsigned long bp,
12314 - const struct stacktrace_ops *ops,
12315 - void *data,
12316 - unsigned long *end,
12317 - int *graph);
12318 +typedef unsigned long walk_stack_t(struct task_struct *task,
12319 + void *stack_start,
12320 + unsigned long *stack,
12321 + unsigned long bp,
12322 + const struct stacktrace_ops *ops,
12323 + void *data,
12324 + unsigned long *end,
12325 + int *graph);
12326
12327 -extern unsigned long
12328 -print_context_stack(struct thread_info *tinfo,
12329 - unsigned long *stack, unsigned long bp,
12330 - const struct stacktrace_ops *ops, void *data,
12331 - unsigned long *end, int *graph);
12332 -
12333 -extern unsigned long
12334 -print_context_stack_bp(struct thread_info *tinfo,
12335 - unsigned long *stack, unsigned long bp,
12336 - const struct stacktrace_ops *ops, void *data,
12337 - unsigned long *end, int *graph);
12338 +extern walk_stack_t print_context_stack;
12339 +extern walk_stack_t print_context_stack_bp;
12340
12341 /* Generic stack tracer with callbacks */
12342
12343 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12344 void (*address)(void *data, unsigned long address, int reliable);
12345 /* On negative return stop dumping */
12346 int (*stack)(void *data, char *name);
12347 - walk_stack_t walk_stack;
12348 + walk_stack_t *walk_stack;
12349 };
12350
12351 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12352 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12353 index 4ec45b3..a4f0a8a 100644
12354 --- a/arch/x86/include/asm/switch_to.h
12355 +++ b/arch/x86/include/asm/switch_to.h
12356 @@ -108,7 +108,7 @@ do { \
12357 "call __switch_to\n\t" \
12358 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12359 __switch_canary \
12360 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12361 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12362 "movq %%rax,%%rdi\n\t" \
12363 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12364 "jnz ret_from_fork\n\t" \
12365 @@ -119,7 +119,7 @@ do { \
12366 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12367 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12368 [_tif_fork] "i" (_TIF_FORK), \
12369 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12370 + [thread_info] "m" (current_tinfo), \
12371 [current_task] "m" (current_task) \
12372 __switch_canary_iparam \
12373 : "memory", "cc" __EXTRA_CLOBBER)
12374 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12375 index 3fda9db4..4ca1c61 100644
12376 --- a/arch/x86/include/asm/sys_ia32.h
12377 +++ b/arch/x86/include/asm/sys_ia32.h
12378 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12379 struct old_sigaction32 __user *);
12380 asmlinkage long sys32_alarm(unsigned int);
12381
12382 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12383 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12384 asmlinkage long sys32_sysfs(int, u32, u32);
12385
12386 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12387 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12388 index ad6df8c..5e0cf6e 100644
12389 --- a/arch/x86/include/asm/thread_info.h
12390 +++ b/arch/x86/include/asm/thread_info.h
12391 @@ -10,6 +10,7 @@
12392 #include <linux/compiler.h>
12393 #include <asm/page.h>
12394 #include <asm/types.h>
12395 +#include <asm/percpu.h>
12396
12397 /*
12398 * low level task data that entry.S needs immediate access to
12399 @@ -24,7 +25,6 @@ struct exec_domain;
12400 #include <linux/atomic.h>
12401
12402 struct thread_info {
12403 - struct task_struct *task; /* main task structure */
12404 struct exec_domain *exec_domain; /* execution domain */
12405 __u32 flags; /* low level flags */
12406 __u32 status; /* thread synchronous flags */
12407 @@ -34,19 +34,13 @@ struct thread_info {
12408 mm_segment_t addr_limit;
12409 struct restart_block restart_block;
12410 void __user *sysenter_return;
12411 -#ifdef CONFIG_X86_32
12412 - unsigned long previous_esp; /* ESP of the previous stack in
12413 - case of nested (IRQ) stacks
12414 - */
12415 - __u8 supervisor_stack[0];
12416 -#endif
12417 + unsigned long lowest_stack;
12418 unsigned int sig_on_uaccess_error:1;
12419 unsigned int uaccess_err:1; /* uaccess failed */
12420 };
12421
12422 -#define INIT_THREAD_INFO(tsk) \
12423 +#define INIT_THREAD_INFO \
12424 { \
12425 - .task = &tsk, \
12426 .exec_domain = &default_exec_domain, \
12427 .flags = 0, \
12428 .cpu = 0, \
12429 @@ -57,7 +51,7 @@ struct thread_info {
12430 }, \
12431 }
12432
12433 -#define init_thread_info (init_thread_union.thread_info)
12434 +#define init_thread_info (init_thread_union.stack)
12435 #define init_stack (init_thread_union.stack)
12436
12437 #else /* !__ASSEMBLY__ */
12438 @@ -97,6 +91,7 @@ struct thread_info {
12439 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12440 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12441 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12442 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12443
12444 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12445 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12446 @@ -120,16 +115,18 @@ struct thread_info {
12447 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12448 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12449 #define _TIF_X32 (1 << TIF_X32)
12450 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12451
12452 /* work to do in syscall_trace_enter() */
12453 #define _TIF_WORK_SYSCALL_ENTRY \
12454 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12455 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12456 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12457 + _TIF_GRSEC_SETXID)
12458
12459 /* work to do in syscall_trace_leave() */
12460 #define _TIF_WORK_SYSCALL_EXIT \
12461 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12462 - _TIF_SYSCALL_TRACEPOINT)
12463 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12464
12465 /* work to do on interrupt/exception return */
12466 #define _TIF_WORK_MASK \
12467 @@ -139,7 +136,8 @@ struct thread_info {
12468
12469 /* work to do on any return to user space */
12470 #define _TIF_ALLWORK_MASK \
12471 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12472 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12473 + _TIF_GRSEC_SETXID)
12474
12475 /* Only used for 64 bit */
12476 #define _TIF_DO_NOTIFY_MASK \
12477 @@ -173,45 +171,40 @@ struct thread_info {
12478 ret; \
12479 })
12480
12481 -#ifdef CONFIG_X86_32
12482 -
12483 -#define STACK_WARN (THREAD_SIZE/8)
12484 -/*
12485 - * macros/functions for gaining access to the thread information structure
12486 - *
12487 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12488 - */
12489 -#ifndef __ASSEMBLY__
12490 -
12491 -
12492 -/* how to get the current stack pointer from C */
12493 -register unsigned long current_stack_pointer asm("esp") __used;
12494 -
12495 -/* how to get the thread information struct from C */
12496 -static inline struct thread_info *current_thread_info(void)
12497 -{
12498 - return (struct thread_info *)
12499 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12500 -}
12501 -
12502 -#else /* !__ASSEMBLY__ */
12503 -
12504 +#ifdef __ASSEMBLY__
12505 /* how to get the thread information struct from ASM */
12506 #define GET_THREAD_INFO(reg) \
12507 - movl $-THREAD_SIZE, reg; \
12508 - andl %esp, reg
12509 + mov PER_CPU_VAR(current_tinfo), reg
12510
12511 /* use this one if reg already contains %esp */
12512 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12513 - andl $-THREAD_SIZE, reg
12514 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12515 +#else
12516 +/* how to get the thread information struct from C */
12517 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12518 +
12519 +static __always_inline struct thread_info *current_thread_info(void)
12520 +{
12521 + return percpu_read_stable(current_tinfo);
12522 +}
12523 +#endif
12524 +
12525 +#ifdef CONFIG_X86_32
12526 +
12527 +#define STACK_WARN (THREAD_SIZE/8)
12528 +/*
12529 + * macros/functions for gaining access to the thread information structure
12530 + *
12531 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12532 + */
12533 +#ifndef __ASSEMBLY__
12534 +
12535 +/* how to get the current stack pointer from C */
12536 +register unsigned long current_stack_pointer asm("esp") __used;
12537
12538 #endif
12539
12540 #else /* X86_32 */
12541
12542 -#include <asm/percpu.h>
12543 -#define KERNEL_STACK_OFFSET (5*8)
12544 -
12545 /*
12546 * macros/functions for gaining access to the thread information structure
12547 * preempt_count needs to be 1 initially, until the scheduler is functional.
12548 @@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12549 #ifndef __ASSEMBLY__
12550 DECLARE_PER_CPU(unsigned long, kernel_stack);
12551
12552 -static inline struct thread_info *current_thread_info(void)
12553 -{
12554 - struct thread_info *ti;
12555 - ti = (void *)(percpu_read_stable(kernel_stack) +
12556 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12557 - return ti;
12558 -}
12559 -
12560 -#else /* !__ASSEMBLY__ */
12561 -
12562 -/* how to get the thread information struct from ASM */
12563 -#define GET_THREAD_INFO(reg) \
12564 - movq PER_CPU_VAR(kernel_stack),reg ; \
12565 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12566 -
12567 -/*
12568 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12569 - * a certain register (to be used in assembler memory operands).
12570 - */
12571 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12572 -
12573 +/* how to get the current stack pointer from C */
12574 +register unsigned long current_stack_pointer asm("rsp") __used;
12575 #endif
12576
12577 #endif /* !X86_32 */
12578 @@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12579 extern void free_thread_info(struct thread_info *ti);
12580 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12581 #define arch_task_cache_init arch_task_cache_init
12582 +
12583 +#define __HAVE_THREAD_FUNCTIONS
12584 +#define task_thread_info(task) (&(task)->tinfo)
12585 +#define task_stack_page(task) ((task)->stack)
12586 +#define setup_thread_stack(p, org) do {} while (0)
12587 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12588 +
12589 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12590 +extern struct task_struct *alloc_task_struct_node(int node);
12591 +extern void free_task_struct(struct task_struct *);
12592 +
12593 #endif
12594 #endif /* _ASM_X86_THREAD_INFO_H */
12595 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12596 index e054459..14bc8a7 100644
12597 --- a/arch/x86/include/asm/uaccess.h
12598 +++ b/arch/x86/include/asm/uaccess.h
12599 @@ -7,12 +7,15 @@
12600 #include <linux/compiler.h>
12601 #include <linux/thread_info.h>
12602 #include <linux/string.h>
12603 +#include <linux/sched.h>
12604 #include <asm/asm.h>
12605 #include <asm/page.h>
12606
12607 #define VERIFY_READ 0
12608 #define VERIFY_WRITE 1
12609
12610 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12611 +
12612 /*
12613 * The fs value determines whether argument validity checking should be
12614 * performed or not. If get_fs() == USER_DS, checking is performed, with
12615 @@ -28,7 +31,12 @@
12616
12617 #define get_ds() (KERNEL_DS)
12618 #define get_fs() (current_thread_info()->addr_limit)
12619 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12620 +void __set_fs(mm_segment_t x);
12621 +void set_fs(mm_segment_t x);
12622 +#else
12623 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12624 +#endif
12625
12626 #define segment_eq(a, b) ((a).seg == (b).seg)
12627
12628 @@ -76,7 +84,33 @@
12629 * checks that the pointer is in the user space range - after calling
12630 * this function, memory access functions may still return -EFAULT.
12631 */
12632 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12633 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12634 +#define access_ok(type, addr, size) \
12635 +({ \
12636 + long __size = size; \
12637 + unsigned long __addr = (unsigned long)addr; \
12638 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12639 + unsigned long __end_ao = __addr + __size - 1; \
12640 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12641 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12642 + while(__addr_ao <= __end_ao) { \
12643 + char __c_ao; \
12644 + __addr_ao += PAGE_SIZE; \
12645 + if (__size > PAGE_SIZE) \
12646 + cond_resched(); \
12647 + if (__get_user(__c_ao, (char __user *)__addr)) \
12648 + break; \
12649 + if (type != VERIFY_WRITE) { \
12650 + __addr = __addr_ao; \
12651 + continue; \
12652 + } \
12653 + if (__put_user(__c_ao, (char __user *)__addr)) \
12654 + break; \
12655 + __addr = __addr_ao; \
12656 + } \
12657 + } \
12658 + __ret_ao; \
12659 +})
12660
12661 /*
12662 * The exception table consists of pairs of addresses: the first is the
12663 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12664 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12665 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12666
12667 -
12668 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12669 +#define __copyuser_seg "gs;"
12670 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12671 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12672 +#else
12673 +#define __copyuser_seg
12674 +#define __COPYUSER_SET_ES
12675 +#define __COPYUSER_RESTORE_ES
12676 +#endif
12677
12678 #ifdef CONFIG_X86_32
12679 #define __put_user_asm_u64(x, addr, err, errret) \
12680 - asm volatile("1: movl %%eax,0(%2)\n" \
12681 - "2: movl %%edx,4(%2)\n" \
12682 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12683 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12684 "3:\n" \
12685 ".section .fixup,\"ax\"\n" \
12686 "4: movl %3,%0\n" \
12687 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12688 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12689
12690 #define __put_user_asm_ex_u64(x, addr) \
12691 - asm volatile("1: movl %%eax,0(%1)\n" \
12692 - "2: movl %%edx,4(%1)\n" \
12693 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12694 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12695 "3:\n" \
12696 _ASM_EXTABLE(1b, 2b - 1b) \
12697 _ASM_EXTABLE(2b, 3b - 2b) \
12698 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12699 __typeof__(*(ptr)) __pu_val; \
12700 __chk_user_ptr(ptr); \
12701 might_fault(); \
12702 - __pu_val = x; \
12703 + __pu_val = (x); \
12704 switch (sizeof(*(ptr))) { \
12705 case 1: \
12706 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12707 @@ -373,7 +415,7 @@ do { \
12708 } while (0)
12709
12710 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12711 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12712 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12713 "2:\n" \
12714 ".section .fixup,\"ax\"\n" \
12715 "3: mov %3,%0\n" \
12716 @@ -381,7 +423,7 @@ do { \
12717 " jmp 2b\n" \
12718 ".previous\n" \
12719 _ASM_EXTABLE(1b, 3b) \
12720 - : "=r" (err), ltype(x) \
12721 + : "=r" (err), ltype (x) \
12722 : "m" (__m(addr)), "i" (errret), "0" (err))
12723
12724 #define __get_user_size_ex(x, ptr, size) \
12725 @@ -406,7 +448,7 @@ do { \
12726 } while (0)
12727
12728 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12729 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12730 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12731 "2:\n" \
12732 _ASM_EXTABLE(1b, 2b - 1b) \
12733 : ltype(x) : "m" (__m(addr)))
12734 @@ -423,13 +465,24 @@ do { \
12735 int __gu_err; \
12736 unsigned long __gu_val; \
12737 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12738 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12739 + (x) = (__typeof__(*(ptr)))__gu_val; \
12740 __gu_err; \
12741 })
12742
12743 /* FIXME: this hack is definitely wrong -AK */
12744 struct __large_struct { unsigned long buf[100]; };
12745 -#define __m(x) (*(struct __large_struct __user *)(x))
12746 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12747 +#define ____m(x) \
12748 +({ \
12749 + unsigned long ____x = (unsigned long)(x); \
12750 + if (____x < PAX_USER_SHADOW_BASE) \
12751 + ____x += PAX_USER_SHADOW_BASE; \
12752 + (void __user *)____x; \
12753 +})
12754 +#else
12755 +#define ____m(x) (x)
12756 +#endif
12757 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12758
12759 /*
12760 * Tell gcc we read from memory instead of writing: this is because
12761 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12762 * aliasing issues.
12763 */
12764 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12765 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12766 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12767 "2:\n" \
12768 ".section .fixup,\"ax\"\n" \
12769 "3: mov %3,%0\n" \
12770 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12771 ".previous\n" \
12772 _ASM_EXTABLE(1b, 3b) \
12773 : "=r"(err) \
12774 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12775 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12776
12777 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12778 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12779 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12780 "2:\n" \
12781 _ASM_EXTABLE(1b, 2b - 1b) \
12782 : : ltype(x), "m" (__m(addr)))
12783 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12784 * On error, the variable @x is set to zero.
12785 */
12786
12787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12788 +#define __get_user(x, ptr) get_user((x), (ptr))
12789 +#else
12790 #define __get_user(x, ptr) \
12791 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12792 +#endif
12793
12794 /**
12795 * __put_user: - Write a simple value into user space, with less checking.
12796 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12797 * Returns zero on success, or -EFAULT on error.
12798 */
12799
12800 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12801 +#define __put_user(x, ptr) put_user((x), (ptr))
12802 +#else
12803 #define __put_user(x, ptr) \
12804 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12805 +#endif
12806
12807 #define __get_user_unaligned __get_user
12808 #define __put_user_unaligned __put_user
12809 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12810 #define get_user_ex(x, ptr) do { \
12811 unsigned long __gue_val; \
12812 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12813 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12814 + (x) = (__typeof__(*(ptr)))__gue_val; \
12815 } while (0)
12816
12817 #ifdef CONFIG_X86_WP_WORKS_OK
12818 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12819 index 8084bc7..3d6ec37 100644
12820 --- a/arch/x86/include/asm/uaccess_32.h
12821 +++ b/arch/x86/include/asm/uaccess_32.h
12822 @@ -11,15 +11,15 @@
12823 #include <asm/page.h>
12824
12825 unsigned long __must_check __copy_to_user_ll
12826 - (void __user *to, const void *from, unsigned long n);
12827 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12828 unsigned long __must_check __copy_from_user_ll
12829 - (void *to, const void __user *from, unsigned long n);
12830 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12831 unsigned long __must_check __copy_from_user_ll_nozero
12832 - (void *to, const void __user *from, unsigned long n);
12833 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12834 unsigned long __must_check __copy_from_user_ll_nocache
12835 - (void *to, const void __user *from, unsigned long n);
12836 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12837 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12838 - (void *to, const void __user *from, unsigned long n);
12839 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12840
12841 /**
12842 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12843 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12844 static __always_inline unsigned long __must_check
12845 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12846 {
12847 + if ((long)n < 0)
12848 + return n;
12849 +
12850 if (__builtin_constant_p(n)) {
12851 unsigned long ret;
12852
12853 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12854 return ret;
12855 }
12856 }
12857 + if (!__builtin_constant_p(n))
12858 + check_object_size(from, n, true);
12859 return __copy_to_user_ll(to, from, n);
12860 }
12861
12862 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12863 __copy_to_user(void __user *to, const void *from, unsigned long n)
12864 {
12865 might_fault();
12866 +
12867 return __copy_to_user_inatomic(to, from, n);
12868 }
12869
12870 static __always_inline unsigned long
12871 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12872 {
12873 + if ((long)n < 0)
12874 + return n;
12875 +
12876 /* Avoid zeroing the tail if the copy fails..
12877 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12878 * but as the zeroing behaviour is only significant when n is not
12879 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12880 __copy_from_user(void *to, const void __user *from, unsigned long n)
12881 {
12882 might_fault();
12883 +
12884 + if ((long)n < 0)
12885 + return n;
12886 +
12887 if (__builtin_constant_p(n)) {
12888 unsigned long ret;
12889
12890 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12891 return ret;
12892 }
12893 }
12894 + if (!__builtin_constant_p(n))
12895 + check_object_size(to, n, false);
12896 return __copy_from_user_ll(to, from, n);
12897 }
12898
12899 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12900 const void __user *from, unsigned long n)
12901 {
12902 might_fault();
12903 +
12904 + if ((long)n < 0)
12905 + return n;
12906 +
12907 if (__builtin_constant_p(n)) {
12908 unsigned long ret;
12909
12910 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12911 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12912 unsigned long n)
12913 {
12914 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12915 + if ((long)n < 0)
12916 + return n;
12917 +
12918 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12919 }
12920
12921 -unsigned long __must_check copy_to_user(void __user *to,
12922 - const void *from, unsigned long n);
12923 -unsigned long __must_check _copy_from_user(void *to,
12924 - const void __user *from,
12925 - unsigned long n);
12926 -
12927 +extern void copy_to_user_overflow(void)
12928 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12929 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12930 +#else
12931 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12932 +#endif
12933 +;
12934
12935 extern void copy_from_user_overflow(void)
12936 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12937 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12938 #endif
12939 ;
12940
12941 -static inline unsigned long __must_check copy_from_user(void *to,
12942 - const void __user *from,
12943 - unsigned long n)
12944 +/**
12945 + * copy_to_user: - Copy a block of data into user space.
12946 + * @to: Destination address, in user space.
12947 + * @from: Source address, in kernel space.
12948 + * @n: Number of bytes to copy.
12949 + *
12950 + * Context: User context only. This function may sleep.
12951 + *
12952 + * Copy data from kernel space to user space.
12953 + *
12954 + * Returns number of bytes that could not be copied.
12955 + * On success, this will be zero.
12956 + */
12957 +static inline unsigned long __must_check
12958 +copy_to_user(void __user *to, const void *from, unsigned long n)
12959 {
12960 - int sz = __compiletime_object_size(to);
12961 + size_t sz = __compiletime_object_size(from);
12962
12963 - if (likely(sz == -1 || sz >= n))
12964 - n = _copy_from_user(to, from, n);
12965 - else
12966 + if (unlikely(sz != (size_t)-1 && sz < n))
12967 + copy_to_user_overflow();
12968 + else if (access_ok(VERIFY_WRITE, to, n))
12969 + n = __copy_to_user(to, from, n);
12970 + return n;
12971 +}
12972 +
12973 +/**
12974 + * copy_from_user: - Copy a block of data from user space.
12975 + * @to: Destination address, in kernel space.
12976 + * @from: Source address, in user space.
12977 + * @n: Number of bytes to copy.
12978 + *
12979 + * Context: User context only. This function may sleep.
12980 + *
12981 + * Copy data from user space to kernel space.
12982 + *
12983 + * Returns number of bytes that could not be copied.
12984 + * On success, this will be zero.
12985 + *
12986 + * If some data could not be copied, this function will pad the copied
12987 + * data to the requested size using zero bytes.
12988 + */
12989 +static inline unsigned long __must_check
12990 +copy_from_user(void *to, const void __user *from, unsigned long n)
12991 +{
12992 + size_t sz = __compiletime_object_size(to);
12993 +
12994 + if (unlikely(sz != (size_t)-1 && sz < n))
12995 copy_from_user_overflow();
12996 -
12997 + else if (access_ok(VERIFY_READ, from, n))
12998 + n = __copy_from_user(to, from, n);
12999 + else if ((long)n > 0) {
13000 + if (!__builtin_constant_p(n))
13001 + check_object_size(to, n, false);
13002 + memset(to, 0, n);
13003 + }
13004 return n;
13005 }
13006
13007 @@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13008 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13009
13010 long strnlen_user(const char __user *str, long n);
13011 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13012 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13013 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13014 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13015
13016 #endif /* _ASM_X86_UACCESS_32_H */
13017 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13018 index fcd4b6f..ef04f8f 100644
13019 --- a/arch/x86/include/asm/uaccess_64.h
13020 +++ b/arch/x86/include/asm/uaccess_64.h
13021 @@ -10,6 +10,9 @@
13022 #include <asm/alternative.h>
13023 #include <asm/cpufeature.h>
13024 #include <asm/page.h>
13025 +#include <asm/pgtable.h>
13026 +
13027 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13028
13029 /*
13030 * Copy To/From Userspace
13031 @@ -17,12 +20,14 @@
13032
13033 /* Handles exceptions in both to and from, but doesn't do access_ok */
13034 __must_check unsigned long
13035 -copy_user_generic_string(void *to, const void *from, unsigned len);
13036 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13037 __must_check unsigned long
13038 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13039 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13040
13041 static __always_inline __must_check unsigned long
13042 -copy_user_generic(void *to, const void *from, unsigned len)
13043 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13044 +static __always_inline __must_check unsigned long
13045 +copy_user_generic(void *to, const void *from, unsigned long len)
13046 {
13047 unsigned ret;
13048
13049 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13050 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13051 "=d" (len)),
13052 "1" (to), "2" (from), "3" (len)
13053 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13054 + : "memory", "rcx", "r8", "r9", "r11");
13055 return ret;
13056 }
13057
13058 +static __always_inline __must_check unsigned long
13059 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13060 +static __always_inline __must_check unsigned long
13061 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13062 __must_check unsigned long
13063 -_copy_to_user(void __user *to, const void *from, unsigned len);
13064 -__must_check unsigned long
13065 -_copy_from_user(void *to, const void __user *from, unsigned len);
13066 -__must_check unsigned long
13067 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13068 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13069 +
13070 +extern void copy_to_user_overflow(void)
13071 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13072 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13073 +#else
13074 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13075 +#endif
13076 +;
13077 +
13078 +extern void copy_from_user_overflow(void)
13079 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13080 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13081 +#else
13082 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13083 +#endif
13084 +;
13085
13086 static inline unsigned long __must_check copy_from_user(void *to,
13087 const void __user *from,
13088 unsigned long n)
13089 {
13090 - int sz = __compiletime_object_size(to);
13091 -
13092 might_fault();
13093 - if (likely(sz == -1 || sz >= n))
13094 - n = _copy_from_user(to, from, n);
13095 -#ifdef CONFIG_DEBUG_VM
13096 - else
13097 - WARN(1, "Buffer overflow detected!\n");
13098 -#endif
13099 +
13100 + if (access_ok(VERIFY_READ, from, n))
13101 + n = __copy_from_user(to, from, n);
13102 + else if (n < INT_MAX) {
13103 + if (!__builtin_constant_p(n))
13104 + check_object_size(to, n, false);
13105 + memset(to, 0, n);
13106 + }
13107 return n;
13108 }
13109
13110 static __always_inline __must_check
13111 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13112 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13113 {
13114 might_fault();
13115
13116 - return _copy_to_user(dst, src, size);
13117 + if (access_ok(VERIFY_WRITE, dst, size))
13118 + size = __copy_to_user(dst, src, size);
13119 + return size;
13120 }
13121
13122 static __always_inline __must_check
13123 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13124 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13125 {
13126 - int ret = 0;
13127 + size_t sz = __compiletime_object_size(dst);
13128 + unsigned ret = 0;
13129
13130 might_fault();
13131 - if (!__builtin_constant_p(size))
13132 - return copy_user_generic(dst, (__force void *)src, size);
13133 +
13134 + if (size > INT_MAX)
13135 + return size;
13136 +
13137 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13138 + if (!__access_ok(VERIFY_READ, src, size))
13139 + return size;
13140 +#endif
13141 +
13142 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13143 + copy_from_user_overflow();
13144 + return size;
13145 + }
13146 +
13147 + if (!__builtin_constant_p(size)) {
13148 + check_object_size(dst, size, false);
13149 +
13150 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13151 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13152 + src += PAX_USER_SHADOW_BASE;
13153 +#endif
13154 +
13155 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13156 + }
13157 switch (size) {
13158 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13159 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13160 ret, "b", "b", "=q", 1);
13161 return ret;
13162 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13163 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13164 ret, "w", "w", "=r", 2);
13165 return ret;
13166 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13167 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13168 ret, "l", "k", "=r", 4);
13169 return ret;
13170 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13171 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13172 ret, "q", "", "=r", 8);
13173 return ret;
13174 case 10:
13175 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13176 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13177 ret, "q", "", "=r", 10);
13178 if (unlikely(ret))
13179 return ret;
13180 __get_user_asm(*(u16 *)(8 + (char *)dst),
13181 - (u16 __user *)(8 + (char __user *)src),
13182 + (const u16 __user *)(8 + (const char __user *)src),
13183 ret, "w", "w", "=r", 2);
13184 return ret;
13185 case 16:
13186 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13187 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13188 ret, "q", "", "=r", 16);
13189 if (unlikely(ret))
13190 return ret;
13191 __get_user_asm(*(u64 *)(8 + (char *)dst),
13192 - (u64 __user *)(8 + (char __user *)src),
13193 + (const u64 __user *)(8 + (const char __user *)src),
13194 ret, "q", "", "=r", 8);
13195 return ret;
13196 default:
13197 - return copy_user_generic(dst, (__force void *)src, size);
13198 +
13199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13200 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13201 + src += PAX_USER_SHADOW_BASE;
13202 +#endif
13203 +
13204 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13205 }
13206 }
13207
13208 static __always_inline __must_check
13209 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13210 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13211 {
13212 - int ret = 0;
13213 + size_t sz = __compiletime_object_size(src);
13214 + unsigned ret = 0;
13215
13216 might_fault();
13217 - if (!__builtin_constant_p(size))
13218 - return copy_user_generic((__force void *)dst, src, size);
13219 +
13220 + if (size > INT_MAX)
13221 + return size;
13222 +
13223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13224 + if (!__access_ok(VERIFY_WRITE, dst, size))
13225 + return size;
13226 +#endif
13227 +
13228 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13229 + copy_to_user_overflow();
13230 + return size;
13231 + }
13232 +
13233 + if (!__builtin_constant_p(size)) {
13234 + check_object_size(src, size, true);
13235 +
13236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13237 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13238 + dst += PAX_USER_SHADOW_BASE;
13239 +#endif
13240 +
13241 + return copy_user_generic((__force_kernel void *)dst, src, size);
13242 + }
13243 switch (size) {
13244 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13245 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13246 ret, "b", "b", "iq", 1);
13247 return ret;
13248 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13249 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13250 ret, "w", "w", "ir", 2);
13251 return ret;
13252 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13253 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13254 ret, "l", "k", "ir", 4);
13255 return ret;
13256 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13257 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13258 ret, "q", "", "er", 8);
13259 return ret;
13260 case 10:
13261 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13262 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13263 ret, "q", "", "er", 10);
13264 if (unlikely(ret))
13265 return ret;
13266 asm("":::"memory");
13267 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13268 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13269 ret, "w", "w", "ir", 2);
13270 return ret;
13271 case 16:
13272 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13273 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13274 ret, "q", "", "er", 16);
13275 if (unlikely(ret))
13276 return ret;
13277 asm("":::"memory");
13278 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13279 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13280 ret, "q", "", "er", 8);
13281 return ret;
13282 default:
13283 - return copy_user_generic((__force void *)dst, src, size);
13284 +
13285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13286 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13287 + dst += PAX_USER_SHADOW_BASE;
13288 +#endif
13289 +
13290 + return copy_user_generic((__force_kernel void *)dst, src, size);
13291 }
13292 }
13293
13294 static __always_inline __must_check
13295 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13296 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13297 {
13298 - int ret = 0;
13299 + unsigned ret = 0;
13300
13301 might_fault();
13302 - if (!__builtin_constant_p(size))
13303 - return copy_user_generic((__force void *)dst,
13304 - (__force void *)src, size);
13305 +
13306 + if (size > INT_MAX)
13307 + return size;
13308 +
13309 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13310 + if (!__access_ok(VERIFY_READ, src, size))
13311 + return size;
13312 + if (!__access_ok(VERIFY_WRITE, dst, size))
13313 + return size;
13314 +#endif
13315 +
13316 + if (!__builtin_constant_p(size)) {
13317 +
13318 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13319 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13320 + src += PAX_USER_SHADOW_BASE;
13321 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13322 + dst += PAX_USER_SHADOW_BASE;
13323 +#endif
13324 +
13325 + return copy_user_generic((__force_kernel void *)dst,
13326 + (__force_kernel const void *)src, size);
13327 + }
13328 switch (size) {
13329 case 1: {
13330 u8 tmp;
13331 - __get_user_asm(tmp, (u8 __user *)src,
13332 + __get_user_asm(tmp, (const u8 __user *)src,
13333 ret, "b", "b", "=q", 1);
13334 if (likely(!ret))
13335 __put_user_asm(tmp, (u8 __user *)dst,
13336 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13337 }
13338 case 2: {
13339 u16 tmp;
13340 - __get_user_asm(tmp, (u16 __user *)src,
13341 + __get_user_asm(tmp, (const u16 __user *)src,
13342 ret, "w", "w", "=r", 2);
13343 if (likely(!ret))
13344 __put_user_asm(tmp, (u16 __user *)dst,
13345 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13346
13347 case 4: {
13348 u32 tmp;
13349 - __get_user_asm(tmp, (u32 __user *)src,
13350 + __get_user_asm(tmp, (const u32 __user *)src,
13351 ret, "l", "k", "=r", 4);
13352 if (likely(!ret))
13353 __put_user_asm(tmp, (u32 __user *)dst,
13354 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13355 }
13356 case 8: {
13357 u64 tmp;
13358 - __get_user_asm(tmp, (u64 __user *)src,
13359 + __get_user_asm(tmp, (const u64 __user *)src,
13360 ret, "q", "", "=r", 8);
13361 if (likely(!ret))
13362 __put_user_asm(tmp, (u64 __user *)dst,
13363 @@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13364 return ret;
13365 }
13366 default:
13367 - return copy_user_generic((__force void *)dst,
13368 - (__force void *)src, size);
13369 +
13370 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13371 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13372 + src += PAX_USER_SHADOW_BASE;
13373 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374 + dst += PAX_USER_SHADOW_BASE;
13375 +#endif
13376 +
13377 + return copy_user_generic((__force_kernel void *)dst,
13378 + (__force_kernel const void *)src, size);
13379 }
13380 }
13381
13382 __must_check long strnlen_user(const char __user *str, long n);
13383 __must_check long __strnlen_user(const char __user *str, long n);
13384 __must_check long strlen_user(const char __user *str);
13385 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13386 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13387 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13388 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13389
13390 static __must_check __always_inline int
13391 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13392 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13393 {
13394 - return copy_user_generic(dst, (__force const void *)src, size);
13395 + if (size > INT_MAX)
13396 + return size;
13397 +
13398 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13399 + if (!__access_ok(VERIFY_READ, src, size))
13400 + return size;
13401 +
13402 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13403 + src += PAX_USER_SHADOW_BASE;
13404 +#endif
13405 +
13406 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13407 }
13408
13409 -static __must_check __always_inline int
13410 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13411 +static __must_check __always_inline unsigned long
13412 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13413 {
13414 - return copy_user_generic((__force void *)dst, src, size);
13415 + if (size > INT_MAX)
13416 + return size;
13417 +
13418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13419 + if (!__access_ok(VERIFY_WRITE, dst, size))
13420 + return size;
13421 +
13422 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13423 + dst += PAX_USER_SHADOW_BASE;
13424 +#endif
13425 +
13426 + return copy_user_generic((__force_kernel void *)dst, src, size);
13427 }
13428
13429 -extern long __copy_user_nocache(void *dst, const void __user *src,
13430 - unsigned size, int zerorest);
13431 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13432 + unsigned long size, int zerorest) __size_overflow(3);
13433
13434 -static inline int
13435 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13436 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13437 {
13438 might_sleep();
13439 +
13440 + if (size > INT_MAX)
13441 + return size;
13442 +
13443 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13444 + if (!__access_ok(VERIFY_READ, src, size))
13445 + return size;
13446 +#endif
13447 +
13448 return __copy_user_nocache(dst, src, size, 1);
13449 }
13450
13451 -static inline int
13452 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13453 - unsigned size)
13454 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13455 + unsigned long size)
13456 {
13457 + if (size > INT_MAX)
13458 + return size;
13459 +
13460 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13461 + if (!__access_ok(VERIFY_READ, src, size))
13462 + return size;
13463 +#endif
13464 +
13465 return __copy_user_nocache(dst, src, size, 0);
13466 }
13467
13468 -unsigned long
13469 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13470 +extern unsigned long
13471 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13472
13473 #endif /* _ASM_X86_UACCESS_64_H */
13474 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13475 index bb05228..d763d5b 100644
13476 --- a/arch/x86/include/asm/vdso.h
13477 +++ b/arch/x86/include/asm/vdso.h
13478 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13479 #define VDSO32_SYMBOL(base, name) \
13480 ({ \
13481 extern const char VDSO32_##name[]; \
13482 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13483 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13484 })
13485 #endif
13486
13487 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13488 index 764b66a..ad3cfc8 100644
13489 --- a/arch/x86/include/asm/x86_init.h
13490 +++ b/arch/x86/include/asm/x86_init.h
13491 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13492 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13493 void (*find_smp_config)(void);
13494 void (*get_smp_config)(unsigned int early);
13495 -};
13496 +} __no_const;
13497
13498 /**
13499 * struct x86_init_resources - platform specific resource related ops
13500 @@ -43,7 +43,7 @@ struct x86_init_resources {
13501 void (*probe_roms)(void);
13502 void (*reserve_resources)(void);
13503 char *(*memory_setup)(void);
13504 -};
13505 +} __no_const;
13506
13507 /**
13508 * struct x86_init_irqs - platform specific interrupt setup
13509 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13510 void (*pre_vector_init)(void);
13511 void (*intr_init)(void);
13512 void (*trap_init)(void);
13513 -};
13514 +} __no_const;
13515
13516 /**
13517 * struct x86_init_oem - oem platform specific customizing functions
13518 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13519 struct x86_init_oem {
13520 void (*arch_setup)(void);
13521 void (*banner)(void);
13522 -};
13523 +} __no_const;
13524
13525 /**
13526 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13527 @@ -77,7 +77,7 @@ struct x86_init_oem {
13528 */
13529 struct x86_init_mapping {
13530 void (*pagetable_reserve)(u64 start, u64 end);
13531 -};
13532 +} __no_const;
13533
13534 /**
13535 * struct x86_init_paging - platform specific paging functions
13536 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13537 struct x86_init_paging {
13538 void (*pagetable_setup_start)(pgd_t *base);
13539 void (*pagetable_setup_done)(pgd_t *base);
13540 -};
13541 +} __no_const;
13542
13543 /**
13544 * struct x86_init_timers - platform specific timer setup
13545 @@ -102,7 +102,7 @@ struct x86_init_timers {
13546 void (*tsc_pre_init)(void);
13547 void (*timer_init)(void);
13548 void (*wallclock_init)(void);
13549 -};
13550 +} __no_const;
13551
13552 /**
13553 * struct x86_init_iommu - platform specific iommu setup
13554 @@ -110,7 +110,7 @@ struct x86_init_timers {
13555 */
13556 struct x86_init_iommu {
13557 int (*iommu_init)(void);
13558 -};
13559 +} __no_const;
13560
13561 /**
13562 * struct x86_init_pci - platform specific pci init functions
13563 @@ -124,7 +124,7 @@ struct x86_init_pci {
13564 int (*init)(void);
13565 void (*init_irq)(void);
13566 void (*fixup_irqs)(void);
13567 -};
13568 +} __no_const;
13569
13570 /**
13571 * struct x86_init_ops - functions for platform specific setup
13572 @@ -140,7 +140,7 @@ struct x86_init_ops {
13573 struct x86_init_timers timers;
13574 struct x86_init_iommu iommu;
13575 struct x86_init_pci pci;
13576 -};
13577 +} __no_const;
13578
13579 /**
13580 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13581 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13582 void (*setup_percpu_clockev)(void);
13583 void (*early_percpu_clock_init)(void);
13584 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13585 -};
13586 +} __no_const;
13587
13588 /**
13589 * struct x86_platform_ops - platform specific runtime functions
13590 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13591 int (*i8042_detect)(void);
13592 void (*save_sched_clock_state)(void);
13593 void (*restore_sched_clock_state)(void);
13594 -};
13595 +} __no_const;
13596
13597 struct pci_dev;
13598
13599 @@ -186,7 +186,7 @@ struct x86_msi_ops {
13600 void (*teardown_msi_irq)(unsigned int irq);
13601 void (*teardown_msi_irqs)(struct pci_dev *dev);
13602 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13603 -};
13604 +} __no_const;
13605
13606 extern struct x86_init_ops x86_init;
13607 extern struct x86_cpuinit_ops x86_cpuinit;
13608 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13609 index c6ce245..ffbdab7 100644
13610 --- a/arch/x86/include/asm/xsave.h
13611 +++ b/arch/x86/include/asm/xsave.h
13612 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13613 {
13614 int err;
13615
13616 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13617 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13618 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13619 +#endif
13620 +
13621 /*
13622 * Clear the xsave header first, so that reserved fields are
13623 * initialized to zero.
13624 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13625 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13626 {
13627 int err;
13628 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13629 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13630 u32 lmask = mask;
13631 u32 hmask = mask >> 32;
13632
13633 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13634 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13635 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13636 +#endif
13637 +
13638 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13639 "2:\n"
13640 ".section .fixup,\"ax\"\n"
13641 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13642 index 6a564ac..9b1340c 100644
13643 --- a/arch/x86/kernel/acpi/realmode/Makefile
13644 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13645 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13646 $(call cc-option, -fno-stack-protector) \
13647 $(call cc-option, -mpreferred-stack-boundary=2)
13648 KBUILD_CFLAGS += $(call cc-option, -m32)
13649 +ifdef CONSTIFY_PLUGIN
13650 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13651 +endif
13652 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13653 GCOV_PROFILE := n
13654
13655 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13656 index b4fd836..4358fe3 100644
13657 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13658 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13659 @@ -108,6 +108,9 @@ wakeup_code:
13660 /* Do any other stuff... */
13661
13662 #ifndef CONFIG_64BIT
13663 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13664 + call verify_cpu
13665 +
13666 /* This could also be done in C code... */
13667 movl pmode_cr3, %eax
13668 movl %eax, %cr3
13669 @@ -131,6 +134,7 @@ wakeup_code:
13670 movl pmode_cr0, %eax
13671 movl %eax, %cr0
13672 jmp pmode_return
13673 +# include "../../verify_cpu.S"
13674 #else
13675 pushw $0
13676 pushw trampoline_segment
13677 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13678 index 146a49c..1b5338b 100644
13679 --- a/arch/x86/kernel/acpi/sleep.c
13680 +++ b/arch/x86/kernel/acpi/sleep.c
13681 @@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13682 header->trampoline_segment = trampoline_address() >> 4;
13683 #ifdef CONFIG_SMP
13684 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13685 +
13686 + pax_open_kernel();
13687 early_gdt_descr.address =
13688 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13689 + pax_close_kernel();
13690 +
13691 initial_gs = per_cpu_offset(smp_processor_id());
13692 #endif
13693 initial_code = (unsigned long)wakeup_long64;
13694 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13695 index 7261083..5c12053 100644
13696 --- a/arch/x86/kernel/acpi/wakeup_32.S
13697 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13698 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13699 # and restore the stack ... but you need gdt for this to work
13700 movl saved_context_esp, %esp
13701
13702 - movl %cs:saved_magic, %eax
13703 - cmpl $0x12345678, %eax
13704 + cmpl $0x12345678, saved_magic
13705 jne bogus_magic
13706
13707 # jump to place where we left off
13708 - movl saved_eip, %eax
13709 - jmp *%eax
13710 + jmp *(saved_eip)
13711
13712 bogus_magic:
13713 jmp bogus_magic
13714 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13715 index 1f84794..e23f862 100644
13716 --- a/arch/x86/kernel/alternative.c
13717 +++ b/arch/x86/kernel/alternative.c
13718 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13719 */
13720 for (a = start; a < end; a++) {
13721 instr = (u8 *)&a->instr_offset + a->instr_offset;
13722 +
13723 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13724 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13725 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13726 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13727 +#endif
13728 +
13729 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13730 BUG_ON(a->replacementlen > a->instrlen);
13731 BUG_ON(a->instrlen > sizeof(insnbuf));
13732 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13733 for (poff = start; poff < end; poff++) {
13734 u8 *ptr = (u8 *)poff + *poff;
13735
13736 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13737 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13738 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13739 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13740 +#endif
13741 +
13742 if (!*poff || ptr < text || ptr >= text_end)
13743 continue;
13744 /* turn DS segment override prefix into lock prefix */
13745 - if (*ptr == 0x3e)
13746 + if (*ktla_ktva(ptr) == 0x3e)
13747 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13748 };
13749 mutex_unlock(&text_mutex);
13750 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13751 for (poff = start; poff < end; poff++) {
13752 u8 *ptr = (u8 *)poff + *poff;
13753
13754 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13755 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13756 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13757 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13758 +#endif
13759 +
13760 if (!*poff || ptr < text || ptr >= text_end)
13761 continue;
13762 /* turn lock prefix into DS segment override prefix */
13763 - if (*ptr == 0xf0)
13764 + if (*ktla_ktva(ptr) == 0xf0)
13765 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13766 };
13767 mutex_unlock(&text_mutex);
13768 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13769
13770 BUG_ON(p->len > MAX_PATCH_LEN);
13771 /* prep the buffer with the original instructions */
13772 - memcpy(insnbuf, p->instr, p->len);
13773 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13774 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13775 (unsigned long)p->instr, p->len);
13776
13777 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13778 if (smp_alt_once)
13779 free_init_pages("SMP alternatives",
13780 (unsigned long)__smp_locks,
13781 - (unsigned long)__smp_locks_end);
13782 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13783
13784 restart_nmi();
13785 }
13786 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13787 * instructions. And on the local CPU you need to be protected again NMI or MCE
13788 * handlers seeing an inconsistent instruction while you patch.
13789 */
13790 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13791 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13792 size_t len)
13793 {
13794 unsigned long flags;
13795 local_irq_save(flags);
13796 - memcpy(addr, opcode, len);
13797 +
13798 + pax_open_kernel();
13799 + memcpy(ktla_ktva(addr), opcode, len);
13800 sync_core();
13801 + pax_close_kernel();
13802 +
13803 local_irq_restore(flags);
13804 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13805 that causes hangs on some VIA CPUs. */
13806 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13807 */
13808 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13809 {
13810 - unsigned long flags;
13811 - char *vaddr;
13812 + unsigned char *vaddr = ktla_ktva(addr);
13813 struct page *pages[2];
13814 - int i;
13815 + size_t i;
13816
13817 if (!core_kernel_text((unsigned long)addr)) {
13818 - pages[0] = vmalloc_to_page(addr);
13819 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13820 + pages[0] = vmalloc_to_page(vaddr);
13821 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13822 } else {
13823 - pages[0] = virt_to_page(addr);
13824 + pages[0] = virt_to_page(vaddr);
13825 WARN_ON(!PageReserved(pages[0]));
13826 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13827 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13828 }
13829 BUG_ON(!pages[0]);
13830 - local_irq_save(flags);
13831 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13832 - if (pages[1])
13833 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13834 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13835 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13836 - clear_fixmap(FIX_TEXT_POKE0);
13837 - if (pages[1])
13838 - clear_fixmap(FIX_TEXT_POKE1);
13839 - local_flush_tlb();
13840 - sync_core();
13841 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13842 - that causes hangs on some VIA CPUs. */
13843 + text_poke_early(addr, opcode, len);
13844 for (i = 0; i < len; i++)
13845 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13846 - local_irq_restore(flags);
13847 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13848 return addr;
13849 }
13850
13851 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13852 index edc2448..553e7c5 100644
13853 --- a/arch/x86/kernel/apic/apic.c
13854 +++ b/arch/x86/kernel/apic/apic.c
13855 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13856 /*
13857 * Debug level, exported for io_apic.c
13858 */
13859 -unsigned int apic_verbosity;
13860 +int apic_verbosity;
13861
13862 int pic_mode;
13863
13864 @@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13865 apic_write(APIC_ESR, 0);
13866 v1 = apic_read(APIC_ESR);
13867 ack_APIC_irq();
13868 - atomic_inc(&irq_err_count);
13869 + atomic_inc_unchecked(&irq_err_count);
13870
13871 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13872 smp_processor_id(), v0 , v1);
13873 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13874 index e88300d..cd5a87a 100644
13875 --- a/arch/x86/kernel/apic/io_apic.c
13876 +++ b/arch/x86/kernel/apic/io_apic.c
13877 @@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13878
13879 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13880 {
13881 - io_apic_ops = *ops;
13882 + pax_open_kernel();
13883 + memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13884 + pax_close_kernel();
13885 }
13886
13887 /*
13888 @@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13889 }
13890 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13891
13892 -void lock_vector_lock(void)
13893 +void lock_vector_lock(void) __acquires(vector_lock)
13894 {
13895 /* Used to the online set of cpus does not change
13896 * during assign_irq_vector.
13897 @@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
13898 raw_spin_lock(&vector_lock);
13899 }
13900
13901 -void unlock_vector_lock(void)
13902 +void unlock_vector_lock(void) __releases(vector_lock)
13903 {
13904 raw_spin_unlock(&vector_lock);
13905 }
13906 @@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
13907 ack_APIC_irq();
13908 }
13909
13910 -atomic_t irq_mis_count;
13911 +atomic_unchecked_t irq_mis_count;
13912
13913 #ifdef CONFIG_GENERIC_PENDING_IRQ
13914 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
13915 @@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
13916 * at the cpu.
13917 */
13918 if (!(v & (1 << (i & 0x1f)))) {
13919 - atomic_inc(&irq_mis_count);
13920 + atomic_inc_unchecked(&irq_mis_count);
13921
13922 eoi_ioapic_irq(irq, cfg);
13923 }
13924 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13925 index 459e78c..f037006 100644
13926 --- a/arch/x86/kernel/apm_32.c
13927 +++ b/arch/x86/kernel/apm_32.c
13928 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13929 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13930 * even though they are called in protected mode.
13931 */
13932 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13933 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13934 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13935
13936 static const char driver_version[] = "1.16ac"; /* no spaces */
13937 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13938 BUG_ON(cpu != 0);
13939 gdt = get_cpu_gdt_table(cpu);
13940 save_desc_40 = gdt[0x40 / 8];
13941 +
13942 + pax_open_kernel();
13943 gdt[0x40 / 8] = bad_bios_desc;
13944 + pax_close_kernel();
13945
13946 apm_irq_save(flags);
13947 APM_DO_SAVE_SEGS;
13948 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13949 &call->esi);
13950 APM_DO_RESTORE_SEGS;
13951 apm_irq_restore(flags);
13952 +
13953 + pax_open_kernel();
13954 gdt[0x40 / 8] = save_desc_40;
13955 + pax_close_kernel();
13956 +
13957 put_cpu();
13958
13959 return call->eax & 0xff;
13960 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13961 BUG_ON(cpu != 0);
13962 gdt = get_cpu_gdt_table(cpu);
13963 save_desc_40 = gdt[0x40 / 8];
13964 +
13965 + pax_open_kernel();
13966 gdt[0x40 / 8] = bad_bios_desc;
13967 + pax_close_kernel();
13968
13969 apm_irq_save(flags);
13970 APM_DO_SAVE_SEGS;
13971 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13972 &call->eax);
13973 APM_DO_RESTORE_SEGS;
13974 apm_irq_restore(flags);
13975 +
13976 + pax_open_kernel();
13977 gdt[0x40 / 8] = save_desc_40;
13978 + pax_close_kernel();
13979 +
13980 put_cpu();
13981 return error;
13982 }
13983 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13984 * code to that CPU.
13985 */
13986 gdt = get_cpu_gdt_table(0);
13987 +
13988 + pax_open_kernel();
13989 set_desc_base(&gdt[APM_CS >> 3],
13990 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13991 set_desc_base(&gdt[APM_CS_16 >> 3],
13992 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13993 set_desc_base(&gdt[APM_DS >> 3],
13994 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13995 + pax_close_kernel();
13996
13997 proc_create("apm", 0, NULL, &apm_file_ops);
13998
13999 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14000 index 68de2dc..1f3c720 100644
14001 --- a/arch/x86/kernel/asm-offsets.c
14002 +++ b/arch/x86/kernel/asm-offsets.c
14003 @@ -33,6 +33,8 @@ void common(void) {
14004 OFFSET(TI_status, thread_info, status);
14005 OFFSET(TI_addr_limit, thread_info, addr_limit);
14006 OFFSET(TI_preempt_count, thread_info, preempt_count);
14007 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14008 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14009
14010 BLANK();
14011 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14012 @@ -53,8 +55,26 @@ void common(void) {
14013 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14014 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14015 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14016 +
14017 +#ifdef CONFIG_PAX_KERNEXEC
14018 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14019 #endif
14020
14021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14022 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14023 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14024 +#ifdef CONFIG_X86_64
14025 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14026 +#endif
14027 +#endif
14028 +
14029 +#endif
14030 +
14031 + BLANK();
14032 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14033 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14034 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14035 +
14036 #ifdef CONFIG_XEN
14037 BLANK();
14038 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14039 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14040 index 1b4754f..fbb4227 100644
14041 --- a/arch/x86/kernel/asm-offsets_64.c
14042 +++ b/arch/x86/kernel/asm-offsets_64.c
14043 @@ -76,6 +76,7 @@ int main(void)
14044 BLANK();
14045 #undef ENTRY
14046
14047 + DEFINE(TSS_size, sizeof(struct tss_struct));
14048 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14049 BLANK();
14050
14051 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14052 index 6ab6aa2..8f71507 100644
14053 --- a/arch/x86/kernel/cpu/Makefile
14054 +++ b/arch/x86/kernel/cpu/Makefile
14055 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14056 CFLAGS_REMOVE_perf_event.o = -pg
14057 endif
14058
14059 -# Make sure load_percpu_segment has no stackprotector
14060 -nostackp := $(call cc-option, -fno-stack-protector)
14061 -CFLAGS_common.o := $(nostackp)
14062 -
14063 obj-y := intel_cacheinfo.o scattered.o topology.o
14064 obj-y += proc.o capflags.o powerflags.o common.o
14065 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14066 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14067 index 146bb62..ac9c74a 100644
14068 --- a/arch/x86/kernel/cpu/amd.c
14069 +++ b/arch/x86/kernel/cpu/amd.c
14070 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14071 unsigned int size)
14072 {
14073 /* AMD errata T13 (order #21922) */
14074 - if ((c->x86 == 6)) {
14075 + if (c->x86 == 6) {
14076 /* Duron Rev A0 */
14077 if (c->x86_model == 3 && c->x86_mask == 0)
14078 size = 64;
14079 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14080 index cf79302..b1b28ae 100644
14081 --- a/arch/x86/kernel/cpu/common.c
14082 +++ b/arch/x86/kernel/cpu/common.c
14083 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14084
14085 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14086
14087 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14088 -#ifdef CONFIG_X86_64
14089 - /*
14090 - * We need valid kernel segments for data and code in long mode too
14091 - * IRET will check the segment types kkeil 2000/10/28
14092 - * Also sysret mandates a special GDT layout
14093 - *
14094 - * TLS descriptors are currently at a different place compared to i386.
14095 - * Hopefully nobody expects them at a fixed place (Wine?)
14096 - */
14097 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14098 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14099 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14100 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14101 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14102 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14103 -#else
14104 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14105 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14106 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14107 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14108 - /*
14109 - * Segments used for calling PnP BIOS have byte granularity.
14110 - * They code segments and data segments have fixed 64k limits,
14111 - * the transfer segment sizes are set at run time.
14112 - */
14113 - /* 32-bit code */
14114 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14115 - /* 16-bit code */
14116 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14117 - /* 16-bit data */
14118 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14119 - /* 16-bit data */
14120 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14121 - /* 16-bit data */
14122 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14123 - /*
14124 - * The APM segments have byte granularity and their bases
14125 - * are set at run time. All have 64k limits.
14126 - */
14127 - /* 32-bit code */
14128 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14129 - /* 16-bit code */
14130 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14131 - /* data */
14132 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14133 -
14134 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14135 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14136 - GDT_STACK_CANARY_INIT
14137 -#endif
14138 -} };
14139 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14140 -
14141 static int __init x86_xsave_setup(char *s)
14142 {
14143 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14144 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14145 {
14146 struct desc_ptr gdt_descr;
14147
14148 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14149 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14150 gdt_descr.size = GDT_SIZE - 1;
14151 load_gdt(&gdt_descr);
14152 /* Reload the per-cpu base */
14153 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14154 /* Filter out anything that depends on CPUID levels we don't have */
14155 filter_cpuid_features(c, true);
14156
14157 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14158 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14159 +#endif
14160 +
14161 /* If the model name is still unset, do table lookup. */
14162 if (!c->x86_model_id[0]) {
14163 const char *p;
14164 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14165 }
14166 __setup("clearcpuid=", setup_disablecpuid);
14167
14168 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14169 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14170 +
14171 #ifdef CONFIG_X86_64
14172 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14173 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14174 - (unsigned long) nmi_idt_table };
14175 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14176
14177 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14178 irq_stack_union) __aligned(PAGE_SIZE);
14179 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14180 EXPORT_PER_CPU_SYMBOL(current_task);
14181
14182 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14183 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14184 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14185 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14186
14187 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14188 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14189 {
14190 memset(regs, 0, sizeof(struct pt_regs));
14191 regs->fs = __KERNEL_PERCPU;
14192 - regs->gs = __KERNEL_STACK_CANARY;
14193 + savesegment(gs, regs->gs);
14194
14195 return regs;
14196 }
14197 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14198 int i;
14199
14200 cpu = stack_smp_processor_id();
14201 - t = &per_cpu(init_tss, cpu);
14202 + t = init_tss + cpu;
14203 oist = &per_cpu(orig_ist, cpu);
14204
14205 #ifdef CONFIG_NUMA
14206 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14207 switch_to_new_gdt(cpu);
14208 loadsegment(fs, 0);
14209
14210 - load_idt((const struct desc_ptr *)&idt_descr);
14211 + load_idt(&idt_descr);
14212
14213 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14214 syscall_init();
14215 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14216 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14217 barrier();
14218
14219 - x86_configure_nx();
14220 if (cpu != 0)
14221 enable_x2apic();
14222
14223 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14224 {
14225 int cpu = smp_processor_id();
14226 struct task_struct *curr = current;
14227 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14228 + struct tss_struct *t = init_tss + cpu;
14229 struct thread_struct *thread = &curr->thread;
14230
14231 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14232 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14233 index 3e6ff6c..54b4992 100644
14234 --- a/arch/x86/kernel/cpu/intel.c
14235 +++ b/arch/x86/kernel/cpu/intel.c
14236 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14237 * Update the IDT descriptor and reload the IDT so that
14238 * it uses the read-only mapped virtual address.
14239 */
14240 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14241 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14242 load_idt(&idt_descr);
14243 }
14244 #endif
14245 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14246 index 61604ae..98250a5 100644
14247 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14248 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14249 @@ -42,6 +42,7 @@
14250 #include <asm/processor.h>
14251 #include <asm/mce.h>
14252 #include <asm/msr.h>
14253 +#include <asm/local.h>
14254
14255 #include "mce-internal.h"
14256
14257 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14258 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14259 m->cs, m->ip);
14260
14261 - if (m->cs == __KERNEL_CS)
14262 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14263 print_symbol("{%s}", m->ip);
14264 pr_cont("\n");
14265 }
14266 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14267
14268 #define PANIC_TIMEOUT 5 /* 5 seconds */
14269
14270 -static atomic_t mce_paniced;
14271 +static atomic_unchecked_t mce_paniced;
14272
14273 static int fake_panic;
14274 -static atomic_t mce_fake_paniced;
14275 +static atomic_unchecked_t mce_fake_paniced;
14276
14277 /* Panic in progress. Enable interrupts and wait for final IPI */
14278 static void wait_for_panic(void)
14279 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14280 /*
14281 * Make sure only one CPU runs in machine check panic
14282 */
14283 - if (atomic_inc_return(&mce_paniced) > 1)
14284 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14285 wait_for_panic();
14286 barrier();
14287
14288 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14289 console_verbose();
14290 } else {
14291 /* Don't log too much for fake panic */
14292 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14293 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14294 return;
14295 }
14296 /* First print corrected ones that are still unlogged */
14297 @@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14298 * might have been modified by someone else.
14299 */
14300 rmb();
14301 - if (atomic_read(&mce_paniced))
14302 + if (atomic_read_unchecked(&mce_paniced))
14303 wait_for_panic();
14304 if (!monarch_timeout)
14305 goto out;
14306 @@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14307 }
14308
14309 /* Call the installed machine check handler for this CPU setup. */
14310 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14311 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14312 unexpected_machine_check;
14313
14314 /*
14315 @@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14316 return;
14317 }
14318
14319 + pax_open_kernel();
14320 machine_check_vector = do_machine_check;
14321 + pax_close_kernel();
14322
14323 __mcheck_cpu_init_generic();
14324 __mcheck_cpu_init_vendor(c);
14325 @@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14326 */
14327
14328 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14329 -static int mce_chrdev_open_count; /* #times opened */
14330 +static local_t mce_chrdev_open_count; /* #times opened */
14331 static int mce_chrdev_open_exclu; /* already open exclusive? */
14332
14333 static int mce_chrdev_open(struct inode *inode, struct file *file)
14334 @@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14335 spin_lock(&mce_chrdev_state_lock);
14336
14337 if (mce_chrdev_open_exclu ||
14338 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14339 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14340 spin_unlock(&mce_chrdev_state_lock);
14341
14342 return -EBUSY;
14343 @@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14344
14345 if (file->f_flags & O_EXCL)
14346 mce_chrdev_open_exclu = 1;
14347 - mce_chrdev_open_count++;
14348 + local_inc(&mce_chrdev_open_count);
14349
14350 spin_unlock(&mce_chrdev_state_lock);
14351
14352 @@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14353 {
14354 spin_lock(&mce_chrdev_state_lock);
14355
14356 - mce_chrdev_open_count--;
14357 + local_dec(&mce_chrdev_open_count);
14358 mce_chrdev_open_exclu = 0;
14359
14360 spin_unlock(&mce_chrdev_state_lock);
14361 @@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14362 static void mce_reset(void)
14363 {
14364 cpu_missing = 0;
14365 - atomic_set(&mce_fake_paniced, 0);
14366 + atomic_set_unchecked(&mce_fake_paniced, 0);
14367 atomic_set(&mce_executing, 0);
14368 atomic_set(&mce_callin, 0);
14369 atomic_set(&global_nwo, 0);
14370 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14371 index 2d5454c..51987eb 100644
14372 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14373 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14374 @@ -11,6 +11,7 @@
14375 #include <asm/processor.h>
14376 #include <asm/mce.h>
14377 #include <asm/msr.h>
14378 +#include <asm/pgtable.h>
14379
14380 /* By default disabled */
14381 int mce_p5_enabled __read_mostly;
14382 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14383 if (!cpu_has(c, X86_FEATURE_MCE))
14384 return;
14385
14386 + pax_open_kernel();
14387 machine_check_vector = pentium_machine_check;
14388 + pax_close_kernel();
14389 /* Make sure the vector pointer is visible before we enable MCEs: */
14390 wmb();
14391
14392 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14393 index 2d7998f..17c9de1 100644
14394 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14395 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14396 @@ -10,6 +10,7 @@
14397 #include <asm/processor.h>
14398 #include <asm/mce.h>
14399 #include <asm/msr.h>
14400 +#include <asm/pgtable.h>
14401
14402 /* Machine check handler for WinChip C6: */
14403 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14404 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14405 {
14406 u32 lo, hi;
14407
14408 + pax_open_kernel();
14409 machine_check_vector = winchip_machine_check;
14410 + pax_close_kernel();
14411 /* Make sure the vector pointer is visible before we enable MCEs: */
14412 wmb();
14413
14414 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14415 index 6b96110..0da73eb 100644
14416 --- a/arch/x86/kernel/cpu/mtrr/main.c
14417 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14418 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14419 u64 size_or_mask, size_and_mask;
14420 static bool mtrr_aps_delayed_init;
14421
14422 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14423 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14424
14425 const struct mtrr_ops *mtrr_if;
14426
14427 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14428 index df5e41f..816c719 100644
14429 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14430 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14431 @@ -25,7 +25,7 @@ struct mtrr_ops {
14432 int (*validate_add_page)(unsigned long base, unsigned long size,
14433 unsigned int type);
14434 int (*have_wrcomb)(void);
14435 -};
14436 +} __do_const;
14437
14438 extern int generic_get_free_region(unsigned long base, unsigned long size,
14439 int replace_reg);
14440 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14441 index bb8e034..fb9020b 100644
14442 --- a/arch/x86/kernel/cpu/perf_event.c
14443 +++ b/arch/x86/kernel/cpu/perf_event.c
14444 @@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14445 break;
14446
14447 perf_callchain_store(entry, frame.return_address);
14448 - fp = frame.next_frame;
14449 + fp = (const void __force_user *)frame.next_frame;
14450 }
14451 }
14452
14453 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14454 index 13ad899..f642b9a 100644
14455 --- a/arch/x86/kernel/crash.c
14456 +++ b/arch/x86/kernel/crash.c
14457 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14458 {
14459 #ifdef CONFIG_X86_32
14460 struct pt_regs fixed_regs;
14461 -#endif
14462
14463 -#ifdef CONFIG_X86_32
14464 - if (!user_mode_vm(regs)) {
14465 + if (!user_mode(regs)) {
14466 crash_fixup_ss_esp(&fixed_regs, regs);
14467 regs = &fixed_regs;
14468 }
14469 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14470 index 37250fe..bf2ec74 100644
14471 --- a/arch/x86/kernel/doublefault_32.c
14472 +++ b/arch/x86/kernel/doublefault_32.c
14473 @@ -11,7 +11,7 @@
14474
14475 #define DOUBLEFAULT_STACKSIZE (1024)
14476 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14477 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14478 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14479
14480 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14481
14482 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14483 unsigned long gdt, tss;
14484
14485 store_gdt(&gdt_desc);
14486 - gdt = gdt_desc.address;
14487 + gdt = (unsigned long)gdt_desc.address;
14488
14489 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14490
14491 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14492 /* 0x2 bit is always set */
14493 .flags = X86_EFLAGS_SF | 0x2,
14494 .sp = STACK_START,
14495 - .es = __USER_DS,
14496 + .es = __KERNEL_DS,
14497 .cs = __KERNEL_CS,
14498 .ss = __KERNEL_DS,
14499 - .ds = __USER_DS,
14500 + .ds = __KERNEL_DS,
14501 .fs = __KERNEL_PERCPU,
14502
14503 .__cr3 = __pa_nodebug(swapper_pg_dir),
14504 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14505 index 1b81839..0b4e7b0 100644
14506 --- a/arch/x86/kernel/dumpstack.c
14507 +++ b/arch/x86/kernel/dumpstack.c
14508 @@ -2,6 +2,9 @@
14509 * Copyright (C) 1991, 1992 Linus Torvalds
14510 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14511 */
14512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14513 +#define __INCLUDED_BY_HIDESYM 1
14514 +#endif
14515 #include <linux/kallsyms.h>
14516 #include <linux/kprobes.h>
14517 #include <linux/uaccess.h>
14518 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14519 static void
14520 print_ftrace_graph_addr(unsigned long addr, void *data,
14521 const struct stacktrace_ops *ops,
14522 - struct thread_info *tinfo, int *graph)
14523 + struct task_struct *task, int *graph)
14524 {
14525 - struct task_struct *task;
14526 unsigned long ret_addr;
14527 int index;
14528
14529 if (addr != (unsigned long)return_to_handler)
14530 return;
14531
14532 - task = tinfo->task;
14533 index = task->curr_ret_stack;
14534
14535 if (!task->ret_stack || index < *graph)
14536 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14537 static inline void
14538 print_ftrace_graph_addr(unsigned long addr, void *data,
14539 const struct stacktrace_ops *ops,
14540 - struct thread_info *tinfo, int *graph)
14541 + struct task_struct *task, int *graph)
14542 { }
14543 #endif
14544
14545 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14546 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14547 */
14548
14549 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14550 - void *p, unsigned int size, void *end)
14551 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14552 {
14553 - void *t = tinfo;
14554 if (end) {
14555 if (p < end && p >= (end-THREAD_SIZE))
14556 return 1;
14557 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14558 }
14559
14560 unsigned long
14561 -print_context_stack(struct thread_info *tinfo,
14562 +print_context_stack(struct task_struct *task, void *stack_start,
14563 unsigned long *stack, unsigned long bp,
14564 const struct stacktrace_ops *ops, void *data,
14565 unsigned long *end, int *graph)
14566 {
14567 struct stack_frame *frame = (struct stack_frame *)bp;
14568
14569 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14570 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14571 unsigned long addr;
14572
14573 addr = *stack;
14574 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14575 } else {
14576 ops->address(data, addr, 0);
14577 }
14578 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14579 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14580 }
14581 stack++;
14582 }
14583 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14584 EXPORT_SYMBOL_GPL(print_context_stack);
14585
14586 unsigned long
14587 -print_context_stack_bp(struct thread_info *tinfo,
14588 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14589 unsigned long *stack, unsigned long bp,
14590 const struct stacktrace_ops *ops, void *data,
14591 unsigned long *end, int *graph)
14592 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14593 struct stack_frame *frame = (struct stack_frame *)bp;
14594 unsigned long *ret_addr = &frame->return_address;
14595
14596 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14597 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14598 unsigned long addr = *ret_addr;
14599
14600 if (!__kernel_text_address(addr))
14601 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14602 ops->address(data, addr, 1);
14603 frame = frame->next_frame;
14604 ret_addr = &frame->return_address;
14605 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14606 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14607 }
14608
14609 return (unsigned long)frame;
14610 @@ -189,7 +188,7 @@ void dump_stack(void)
14611
14612 bp = stack_frame(current, NULL);
14613 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14614 - current->pid, current->comm, print_tainted(),
14615 + task_pid_nr(current), current->comm, print_tainted(),
14616 init_utsname()->release,
14617 (int)strcspn(init_utsname()->version, " "),
14618 init_utsname()->version);
14619 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14620 }
14621 EXPORT_SYMBOL_GPL(oops_begin);
14622
14623 +extern void gr_handle_kernel_exploit(void);
14624 +
14625 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14626 {
14627 if (regs && kexec_should_crash(current))
14628 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14629 panic("Fatal exception in interrupt");
14630 if (panic_on_oops)
14631 panic("Fatal exception");
14632 - do_exit(signr);
14633 +
14634 + gr_handle_kernel_exploit();
14635 +
14636 + do_group_exit(signr);
14637 }
14638
14639 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14640 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14641
14642 show_registers(regs);
14643 #ifdef CONFIG_X86_32
14644 - if (user_mode_vm(regs)) {
14645 + if (user_mode(regs)) {
14646 sp = regs->sp;
14647 ss = regs->ss & 0xffff;
14648 } else {
14649 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14650 unsigned long flags = oops_begin();
14651 int sig = SIGSEGV;
14652
14653 - if (!user_mode_vm(regs))
14654 + if (!user_mode(regs))
14655 report_bug(regs->ip, regs);
14656
14657 if (__die(str, regs, err))
14658 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14659 index 88ec912..e95e935 100644
14660 --- a/arch/x86/kernel/dumpstack_32.c
14661 +++ b/arch/x86/kernel/dumpstack_32.c
14662 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14663 bp = stack_frame(task, regs);
14664
14665 for (;;) {
14666 - struct thread_info *context;
14667 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14668
14669 - context = (struct thread_info *)
14670 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14671 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14672 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14673
14674 - stack = (unsigned long *)context->previous_esp;
14675 - if (!stack)
14676 + if (stack_start == task_stack_page(task))
14677 break;
14678 + stack = *(unsigned long **)stack_start;
14679 if (ops->stack(data, "IRQ") < 0)
14680 break;
14681 touch_nmi_watchdog();
14682 @@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14683 int i;
14684
14685 print_modules();
14686 - __show_regs(regs, !user_mode_vm(regs));
14687 + __show_regs(regs, !user_mode(regs));
14688
14689 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14690 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14691 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14692 * When in-kernel, we also print out the stack and code at the
14693 * time of the fault..
14694 */
14695 - if (!user_mode_vm(regs)) {
14696 + if (!user_mode(regs)) {
14697 unsigned int code_prologue = code_bytes * 43 / 64;
14698 unsigned int code_len = code_bytes;
14699 unsigned char c;
14700 u8 *ip;
14701 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14702
14703 printk(KERN_EMERG "Stack:\n");
14704 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14705
14706 printk(KERN_EMERG "Code: ");
14707
14708 - ip = (u8 *)regs->ip - code_prologue;
14709 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14710 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14711 /* try starting at IP */
14712 - ip = (u8 *)regs->ip;
14713 + ip = (u8 *)regs->ip + cs_base;
14714 code_len = code_len - code_prologue + 1;
14715 }
14716 for (i = 0; i < code_len; i++, ip++) {
14717 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14718 printk(KERN_CONT " Bad EIP value.");
14719 break;
14720 }
14721 - if (ip == (u8 *)regs->ip)
14722 + if (ip == (u8 *)regs->ip + cs_base)
14723 printk(KERN_CONT "<%02x> ", c);
14724 else
14725 printk(KERN_CONT "%02x ", c);
14726 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14727 {
14728 unsigned short ud2;
14729
14730 + ip = ktla_ktva(ip);
14731 if (ip < PAGE_OFFSET)
14732 return 0;
14733 if (probe_kernel_address((unsigned short *)ip, ud2))
14734 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14735
14736 return ud2 == 0x0b0f;
14737 }
14738 +
14739 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14740 +void pax_check_alloca(unsigned long size)
14741 +{
14742 + unsigned long sp = (unsigned long)&sp, stack_left;
14743 +
14744 + /* all kernel stacks are of the same size */
14745 + stack_left = sp & (THREAD_SIZE - 1);
14746 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14747 +}
14748 +EXPORT_SYMBOL(pax_check_alloca);
14749 +#endif
14750 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14751 index 17107bd..9623722 100644
14752 --- a/arch/x86/kernel/dumpstack_64.c
14753 +++ b/arch/x86/kernel/dumpstack_64.c
14754 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14755 unsigned long *irq_stack_end =
14756 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14757 unsigned used = 0;
14758 - struct thread_info *tinfo;
14759 int graph = 0;
14760 unsigned long dummy;
14761 + void *stack_start;
14762
14763 if (!task)
14764 task = current;
14765 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14766 * current stack address. If the stacks consist of nested
14767 * exceptions
14768 */
14769 - tinfo = task_thread_info(task);
14770 for (;;) {
14771 char *id;
14772 unsigned long *estack_end;
14773 +
14774 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14775 &used, &id);
14776
14777 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14778 if (ops->stack(data, id) < 0)
14779 break;
14780
14781 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14782 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14783 data, estack_end, &graph);
14784 ops->stack(data, "<EOE>");
14785 /*
14786 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14787 * second-to-last pointer (index -2 to end) in the
14788 * exception stack:
14789 */
14790 + if ((u16)estack_end[-1] != __KERNEL_DS)
14791 + goto out;
14792 stack = (unsigned long *) estack_end[-2];
14793 continue;
14794 }
14795 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14796 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14797 if (ops->stack(data, "IRQ") < 0)
14798 break;
14799 - bp = ops->walk_stack(tinfo, stack, bp,
14800 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14801 ops, data, irq_stack_end, &graph);
14802 /*
14803 * We link to the next stack (which would be
14804 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14805 /*
14806 * This handles the process stack:
14807 */
14808 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14809 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14810 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14811 +out:
14812 put_cpu();
14813 }
14814 EXPORT_SYMBOL(dump_trace);
14815 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14816
14817 return ud2 == 0x0b0f;
14818 }
14819 +
14820 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14821 +void pax_check_alloca(unsigned long size)
14822 +{
14823 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14824 + unsigned cpu, used;
14825 + char *id;
14826 +
14827 + /* check the process stack first */
14828 + stack_start = (unsigned long)task_stack_page(current);
14829 + stack_end = stack_start + THREAD_SIZE;
14830 + if (likely(stack_start <= sp && sp < stack_end)) {
14831 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14832 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14833 + return;
14834 + }
14835 +
14836 + cpu = get_cpu();
14837 +
14838 + /* check the irq stacks */
14839 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14840 + stack_start = stack_end - IRQ_STACK_SIZE;
14841 + if (stack_start <= sp && sp < stack_end) {
14842 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14843 + put_cpu();
14844 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14845 + return;
14846 + }
14847 +
14848 + /* check the exception stacks */
14849 + used = 0;
14850 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14851 + stack_start = stack_end - EXCEPTION_STKSZ;
14852 + if (stack_end && stack_start <= sp && sp < stack_end) {
14853 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14854 + put_cpu();
14855 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14856 + return;
14857 + }
14858 +
14859 + put_cpu();
14860 +
14861 + /* unknown stack */
14862 + BUG();
14863 +}
14864 +EXPORT_SYMBOL(pax_check_alloca);
14865 +#endif
14866 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14867 index 9b9f18b..9fcaa04 100644
14868 --- a/arch/x86/kernel/early_printk.c
14869 +++ b/arch/x86/kernel/early_printk.c
14870 @@ -7,6 +7,7 @@
14871 #include <linux/pci_regs.h>
14872 #include <linux/pci_ids.h>
14873 #include <linux/errno.h>
14874 +#include <linux/sched.h>
14875 #include <asm/io.h>
14876 #include <asm/processor.h>
14877 #include <asm/fcntl.h>
14878 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14879 index 7b784f4..db6b628 100644
14880 --- a/arch/x86/kernel/entry_32.S
14881 +++ b/arch/x86/kernel/entry_32.S
14882 @@ -179,13 +179,146 @@
14883 /*CFI_REL_OFFSET gs, PT_GS*/
14884 .endm
14885 .macro SET_KERNEL_GS reg
14886 +
14887 +#ifdef CONFIG_CC_STACKPROTECTOR
14888 movl $(__KERNEL_STACK_CANARY), \reg
14889 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14890 + movl $(__USER_DS), \reg
14891 +#else
14892 + xorl \reg, \reg
14893 +#endif
14894 +
14895 movl \reg, %gs
14896 .endm
14897
14898 #endif /* CONFIG_X86_32_LAZY_GS */
14899
14900 -.macro SAVE_ALL
14901 +.macro pax_enter_kernel
14902 +#ifdef CONFIG_PAX_KERNEXEC
14903 + call pax_enter_kernel
14904 +#endif
14905 +.endm
14906 +
14907 +.macro pax_exit_kernel
14908 +#ifdef CONFIG_PAX_KERNEXEC
14909 + call pax_exit_kernel
14910 +#endif
14911 +.endm
14912 +
14913 +#ifdef CONFIG_PAX_KERNEXEC
14914 +ENTRY(pax_enter_kernel)
14915 +#ifdef CONFIG_PARAVIRT
14916 + pushl %eax
14917 + pushl %ecx
14918 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14919 + mov %eax, %esi
14920 +#else
14921 + mov %cr0, %esi
14922 +#endif
14923 + bts $16, %esi
14924 + jnc 1f
14925 + mov %cs, %esi
14926 + cmp $__KERNEL_CS, %esi
14927 + jz 3f
14928 + ljmp $__KERNEL_CS, $3f
14929 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14930 +2:
14931 +#ifdef CONFIG_PARAVIRT
14932 + mov %esi, %eax
14933 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14934 +#else
14935 + mov %esi, %cr0
14936 +#endif
14937 +3:
14938 +#ifdef CONFIG_PARAVIRT
14939 + popl %ecx
14940 + popl %eax
14941 +#endif
14942 + ret
14943 +ENDPROC(pax_enter_kernel)
14944 +
14945 +ENTRY(pax_exit_kernel)
14946 +#ifdef CONFIG_PARAVIRT
14947 + pushl %eax
14948 + pushl %ecx
14949 +#endif
14950 + mov %cs, %esi
14951 + cmp $__KERNEXEC_KERNEL_CS, %esi
14952 + jnz 2f
14953 +#ifdef CONFIG_PARAVIRT
14954 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14955 + mov %eax, %esi
14956 +#else
14957 + mov %cr0, %esi
14958 +#endif
14959 + btr $16, %esi
14960 + ljmp $__KERNEL_CS, $1f
14961 +1:
14962 +#ifdef CONFIG_PARAVIRT
14963 + mov %esi, %eax
14964 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14965 +#else
14966 + mov %esi, %cr0
14967 +#endif
14968 +2:
14969 +#ifdef CONFIG_PARAVIRT
14970 + popl %ecx
14971 + popl %eax
14972 +#endif
14973 + ret
14974 +ENDPROC(pax_exit_kernel)
14975 +#endif
14976 +
14977 +.macro pax_erase_kstack
14978 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14979 + call pax_erase_kstack
14980 +#endif
14981 +.endm
14982 +
14983 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14984 +/*
14985 + * ebp: thread_info
14986 + * ecx, edx: can be clobbered
14987 + */
14988 +ENTRY(pax_erase_kstack)
14989 + pushl %edi
14990 + pushl %eax
14991 +
14992 + mov TI_lowest_stack(%ebp), %edi
14993 + mov $-0xBEEF, %eax
14994 + std
14995 +
14996 +1: mov %edi, %ecx
14997 + and $THREAD_SIZE_asm - 1, %ecx
14998 + shr $2, %ecx
14999 + repne scasl
15000 + jecxz 2f
15001 +
15002 + cmp $2*16, %ecx
15003 + jc 2f
15004 +
15005 + mov $2*16, %ecx
15006 + repe scasl
15007 + jecxz 2f
15008 + jne 1b
15009 +
15010 +2: cld
15011 + mov %esp, %ecx
15012 + sub %edi, %ecx
15013 + shr $2, %ecx
15014 + rep stosl
15015 +
15016 + mov TI_task_thread_sp0(%ebp), %edi
15017 + sub $128, %edi
15018 + mov %edi, TI_lowest_stack(%ebp)
15019 +
15020 + popl %eax
15021 + popl %edi
15022 + ret
15023 +ENDPROC(pax_erase_kstack)
15024 +#endif
15025 +
15026 +.macro __SAVE_ALL _DS
15027 cld
15028 PUSH_GS
15029 pushl_cfi %fs
15030 @@ -208,7 +341,7 @@
15031 CFI_REL_OFFSET ecx, 0
15032 pushl_cfi %ebx
15033 CFI_REL_OFFSET ebx, 0
15034 - movl $(__USER_DS), %edx
15035 + movl $\_DS, %edx
15036 movl %edx, %ds
15037 movl %edx, %es
15038 movl $(__KERNEL_PERCPU), %edx
15039 @@ -216,6 +349,15 @@
15040 SET_KERNEL_GS %edx
15041 .endm
15042
15043 +.macro SAVE_ALL
15044 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15045 + __SAVE_ALL __KERNEL_DS
15046 + pax_enter_kernel
15047 +#else
15048 + __SAVE_ALL __USER_DS
15049 +#endif
15050 +.endm
15051 +
15052 .macro RESTORE_INT_REGS
15053 popl_cfi %ebx
15054 CFI_RESTORE ebx
15055 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15056 popfl_cfi
15057 jmp syscall_exit
15058 CFI_ENDPROC
15059 -END(ret_from_fork)
15060 +ENDPROC(ret_from_fork)
15061
15062 /*
15063 * Interrupt exit functions should be protected against kprobes
15064 @@ -335,7 +477,15 @@ resume_userspace_sig:
15065 andl $SEGMENT_RPL_MASK, %eax
15066 #endif
15067 cmpl $USER_RPL, %eax
15068 +
15069 +#ifdef CONFIG_PAX_KERNEXEC
15070 + jae resume_userspace
15071 +
15072 + pax_exit_kernel
15073 + jmp resume_kernel
15074 +#else
15075 jb resume_kernel # not returning to v8086 or userspace
15076 +#endif
15077
15078 ENTRY(resume_userspace)
15079 LOCKDEP_SYS_EXIT
15080 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15081 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15082 # int/exception return?
15083 jne work_pending
15084 - jmp restore_all
15085 -END(ret_from_exception)
15086 + jmp restore_all_pax
15087 +ENDPROC(ret_from_exception)
15088
15089 #ifdef CONFIG_PREEMPT
15090 ENTRY(resume_kernel)
15091 @@ -363,7 +513,7 @@ need_resched:
15092 jz restore_all
15093 call preempt_schedule_irq
15094 jmp need_resched
15095 -END(resume_kernel)
15096 +ENDPROC(resume_kernel)
15097 #endif
15098 CFI_ENDPROC
15099 /*
15100 @@ -397,23 +547,34 @@ sysenter_past_esp:
15101 /*CFI_REL_OFFSET cs, 0*/
15102 /*
15103 * Push current_thread_info()->sysenter_return to the stack.
15104 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15105 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15106 */
15107 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15108 + pushl_cfi $0
15109 CFI_REL_OFFSET eip, 0
15110
15111 pushl_cfi %eax
15112 SAVE_ALL
15113 + GET_THREAD_INFO(%ebp)
15114 + movl TI_sysenter_return(%ebp),%ebp
15115 + movl %ebp,PT_EIP(%esp)
15116 ENABLE_INTERRUPTS(CLBR_NONE)
15117
15118 /*
15119 * Load the potential sixth argument from user stack.
15120 * Careful about security.
15121 */
15122 + movl PT_OLDESP(%esp),%ebp
15123 +
15124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15125 + mov PT_OLDSS(%esp),%ds
15126 +1: movl %ds:(%ebp),%ebp
15127 + push %ss
15128 + pop %ds
15129 +#else
15130 cmpl $__PAGE_OFFSET-3,%ebp
15131 jae syscall_fault
15132 1: movl (%ebp),%ebp
15133 +#endif
15134 +
15135 movl %ebp,PT_EBP(%esp)
15136 .section __ex_table,"a"
15137 .align 4
15138 @@ -436,12 +597,24 @@ sysenter_do_call:
15139 testl $_TIF_ALLWORK_MASK, %ecx
15140 jne sysexit_audit
15141 sysenter_exit:
15142 +
15143 +#ifdef CONFIG_PAX_RANDKSTACK
15144 + pushl_cfi %eax
15145 + movl %esp, %eax
15146 + call pax_randomize_kstack
15147 + popl_cfi %eax
15148 +#endif
15149 +
15150 + pax_erase_kstack
15151 +
15152 /* if something modifies registers it must also disable sysexit */
15153 movl PT_EIP(%esp), %edx
15154 movl PT_OLDESP(%esp), %ecx
15155 xorl %ebp,%ebp
15156 TRACE_IRQS_ON
15157 1: mov PT_FS(%esp), %fs
15158 +2: mov PT_DS(%esp), %ds
15159 +3: mov PT_ES(%esp), %es
15160 PTGS_TO_GS
15161 ENABLE_INTERRUPTS_SYSEXIT
15162
15163 @@ -458,6 +631,9 @@ sysenter_audit:
15164 movl %eax,%edx /* 2nd arg: syscall number */
15165 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15166 call __audit_syscall_entry
15167 +
15168 + pax_erase_kstack
15169 +
15170 pushl_cfi %ebx
15171 movl PT_EAX(%esp),%eax /* reload syscall number */
15172 jmp sysenter_do_call
15173 @@ -483,11 +659,17 @@ sysexit_audit:
15174
15175 CFI_ENDPROC
15176 .pushsection .fixup,"ax"
15177 -2: movl $0,PT_FS(%esp)
15178 +4: movl $0,PT_FS(%esp)
15179 + jmp 1b
15180 +5: movl $0,PT_DS(%esp)
15181 + jmp 1b
15182 +6: movl $0,PT_ES(%esp)
15183 jmp 1b
15184 .section __ex_table,"a"
15185 .align 4
15186 - .long 1b,2b
15187 + .long 1b,4b
15188 + .long 2b,5b
15189 + .long 3b,6b
15190 .popsection
15191 PTGS_TO_GS_EX
15192 ENDPROC(ia32_sysenter_target)
15193 @@ -520,6 +702,15 @@ syscall_exit:
15194 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15195 jne syscall_exit_work
15196
15197 +restore_all_pax:
15198 +
15199 +#ifdef CONFIG_PAX_RANDKSTACK
15200 + movl %esp, %eax
15201 + call pax_randomize_kstack
15202 +#endif
15203 +
15204 + pax_erase_kstack
15205 +
15206 restore_all:
15207 TRACE_IRQS_IRET
15208 restore_all_notrace:
15209 @@ -579,14 +770,34 @@ ldt_ss:
15210 * compensating for the offset by changing to the ESPFIX segment with
15211 * a base address that matches for the difference.
15212 */
15213 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15214 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15215 mov %esp, %edx /* load kernel esp */
15216 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15217 mov %dx, %ax /* eax: new kernel esp */
15218 sub %eax, %edx /* offset (low word is 0) */
15219 +#ifdef CONFIG_SMP
15220 + movl PER_CPU_VAR(cpu_number), %ebx
15221 + shll $PAGE_SHIFT_asm, %ebx
15222 + addl $cpu_gdt_table, %ebx
15223 +#else
15224 + movl $cpu_gdt_table, %ebx
15225 +#endif
15226 shr $16, %edx
15227 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15228 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15229 +
15230 +#ifdef CONFIG_PAX_KERNEXEC
15231 + mov %cr0, %esi
15232 + btr $16, %esi
15233 + mov %esi, %cr0
15234 +#endif
15235 +
15236 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15237 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15238 +
15239 +#ifdef CONFIG_PAX_KERNEXEC
15240 + bts $16, %esi
15241 + mov %esi, %cr0
15242 +#endif
15243 +
15244 pushl_cfi $__ESPFIX_SS
15245 pushl_cfi %eax /* new kernel esp */
15246 /* Disable interrupts, but do not irqtrace this section: we
15247 @@ -615,38 +826,30 @@ work_resched:
15248 movl TI_flags(%ebp), %ecx
15249 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15250 # than syscall tracing?
15251 - jz restore_all
15252 + jz restore_all_pax
15253 testb $_TIF_NEED_RESCHED, %cl
15254 jnz work_resched
15255
15256 work_notifysig: # deal with pending signals and
15257 # notify-resume requests
15258 + movl %esp, %eax
15259 #ifdef CONFIG_VM86
15260 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15261 - movl %esp, %eax
15262 - jne work_notifysig_v86 # returning to kernel-space or
15263 + jz 1f # returning to kernel-space or
15264 # vm86-space
15265 - TRACE_IRQS_ON
15266 - ENABLE_INTERRUPTS(CLBR_NONE)
15267 - xorl %edx, %edx
15268 - call do_notify_resume
15269 - jmp resume_userspace_sig
15270
15271 - ALIGN
15272 -work_notifysig_v86:
15273 pushl_cfi %ecx # save ti_flags for do_notify_resume
15274 call save_v86_state # %eax contains pt_regs pointer
15275 popl_cfi %ecx
15276 movl %eax, %esp
15277 -#else
15278 - movl %esp, %eax
15279 +1:
15280 #endif
15281 TRACE_IRQS_ON
15282 ENABLE_INTERRUPTS(CLBR_NONE)
15283 xorl %edx, %edx
15284 call do_notify_resume
15285 jmp resume_userspace_sig
15286 -END(work_pending)
15287 +ENDPROC(work_pending)
15288
15289 # perform syscall exit tracing
15290 ALIGN
15291 @@ -654,11 +857,14 @@ syscall_trace_entry:
15292 movl $-ENOSYS,PT_EAX(%esp)
15293 movl %esp, %eax
15294 call syscall_trace_enter
15295 +
15296 + pax_erase_kstack
15297 +
15298 /* What it returned is what we'll actually use. */
15299 cmpl $(NR_syscalls), %eax
15300 jnae syscall_call
15301 jmp syscall_exit
15302 -END(syscall_trace_entry)
15303 +ENDPROC(syscall_trace_entry)
15304
15305 # perform syscall exit tracing
15306 ALIGN
15307 @@ -671,20 +877,24 @@ syscall_exit_work:
15308 movl %esp, %eax
15309 call syscall_trace_leave
15310 jmp resume_userspace
15311 -END(syscall_exit_work)
15312 +ENDPROC(syscall_exit_work)
15313 CFI_ENDPROC
15314
15315 RING0_INT_FRAME # can't unwind into user space anyway
15316 syscall_fault:
15317 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15318 + push %ss
15319 + pop %ds
15320 +#endif
15321 GET_THREAD_INFO(%ebp)
15322 movl $-EFAULT,PT_EAX(%esp)
15323 jmp resume_userspace
15324 -END(syscall_fault)
15325 +ENDPROC(syscall_fault)
15326
15327 syscall_badsys:
15328 movl $-ENOSYS,PT_EAX(%esp)
15329 jmp resume_userspace
15330 -END(syscall_badsys)
15331 +ENDPROC(syscall_badsys)
15332 CFI_ENDPROC
15333 /*
15334 * End of kprobes section
15335 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15336 CFI_ENDPROC
15337 ENDPROC(ptregs_clone)
15338
15339 + ALIGN;
15340 +ENTRY(kernel_execve)
15341 + CFI_STARTPROC
15342 + pushl_cfi %ebp
15343 + sub $PT_OLDSS+4,%esp
15344 + pushl_cfi %edi
15345 + pushl_cfi %ecx
15346 + pushl_cfi %eax
15347 + lea 3*4(%esp),%edi
15348 + mov $PT_OLDSS/4+1,%ecx
15349 + xorl %eax,%eax
15350 + rep stosl
15351 + popl_cfi %eax
15352 + popl_cfi %ecx
15353 + popl_cfi %edi
15354 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15355 + pushl_cfi %esp
15356 + call sys_execve
15357 + add $4,%esp
15358 + CFI_ADJUST_CFA_OFFSET -4
15359 + GET_THREAD_INFO(%ebp)
15360 + test %eax,%eax
15361 + jz syscall_exit
15362 + add $PT_OLDSS+4,%esp
15363 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15364 + popl_cfi %ebp
15365 + ret
15366 + CFI_ENDPROC
15367 +ENDPROC(kernel_execve)
15368 +
15369 .macro FIXUP_ESPFIX_STACK
15370 /*
15371 * Switch back for ESPFIX stack to the normal zerobased stack
15372 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15373 * normal stack and adjusts ESP with the matching offset.
15374 */
15375 /* fixup the stack */
15376 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15377 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15378 +#ifdef CONFIG_SMP
15379 + movl PER_CPU_VAR(cpu_number), %ebx
15380 + shll $PAGE_SHIFT_asm, %ebx
15381 + addl $cpu_gdt_table, %ebx
15382 +#else
15383 + movl $cpu_gdt_table, %ebx
15384 +#endif
15385 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15386 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15387 shl $16, %eax
15388 addl %esp, %eax /* the adjusted stack pointer */
15389 pushl_cfi $__KERNEL_DS
15390 @@ -819,7 +1066,7 @@ vector=vector+1
15391 .endr
15392 2: jmp common_interrupt
15393 .endr
15394 -END(irq_entries_start)
15395 +ENDPROC(irq_entries_start)
15396
15397 .previous
15398 END(interrupt)
15399 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15400 pushl_cfi $do_coprocessor_error
15401 jmp error_code
15402 CFI_ENDPROC
15403 -END(coprocessor_error)
15404 +ENDPROC(coprocessor_error)
15405
15406 ENTRY(simd_coprocessor_error)
15407 RING0_INT_FRAME
15408 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15409 #endif
15410 jmp error_code
15411 CFI_ENDPROC
15412 -END(simd_coprocessor_error)
15413 +ENDPROC(simd_coprocessor_error)
15414
15415 ENTRY(device_not_available)
15416 RING0_INT_FRAME
15417 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15418 pushl_cfi $do_device_not_available
15419 jmp error_code
15420 CFI_ENDPROC
15421 -END(device_not_available)
15422 +ENDPROC(device_not_available)
15423
15424 #ifdef CONFIG_PARAVIRT
15425 ENTRY(native_iret)
15426 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15427 .align 4
15428 .long native_iret, iret_exc
15429 .previous
15430 -END(native_iret)
15431 +ENDPROC(native_iret)
15432
15433 ENTRY(native_irq_enable_sysexit)
15434 sti
15435 sysexit
15436 -END(native_irq_enable_sysexit)
15437 +ENDPROC(native_irq_enable_sysexit)
15438 #endif
15439
15440 ENTRY(overflow)
15441 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15442 pushl_cfi $do_overflow
15443 jmp error_code
15444 CFI_ENDPROC
15445 -END(overflow)
15446 +ENDPROC(overflow)
15447
15448 ENTRY(bounds)
15449 RING0_INT_FRAME
15450 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15451 pushl_cfi $do_bounds
15452 jmp error_code
15453 CFI_ENDPROC
15454 -END(bounds)
15455 +ENDPROC(bounds)
15456
15457 ENTRY(invalid_op)
15458 RING0_INT_FRAME
15459 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15460 pushl_cfi $do_invalid_op
15461 jmp error_code
15462 CFI_ENDPROC
15463 -END(invalid_op)
15464 +ENDPROC(invalid_op)
15465
15466 ENTRY(coprocessor_segment_overrun)
15467 RING0_INT_FRAME
15468 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15469 pushl_cfi $do_coprocessor_segment_overrun
15470 jmp error_code
15471 CFI_ENDPROC
15472 -END(coprocessor_segment_overrun)
15473 +ENDPROC(coprocessor_segment_overrun)
15474
15475 ENTRY(invalid_TSS)
15476 RING0_EC_FRAME
15477 pushl_cfi $do_invalid_TSS
15478 jmp error_code
15479 CFI_ENDPROC
15480 -END(invalid_TSS)
15481 +ENDPROC(invalid_TSS)
15482
15483 ENTRY(segment_not_present)
15484 RING0_EC_FRAME
15485 pushl_cfi $do_segment_not_present
15486 jmp error_code
15487 CFI_ENDPROC
15488 -END(segment_not_present)
15489 +ENDPROC(segment_not_present)
15490
15491 ENTRY(stack_segment)
15492 RING0_EC_FRAME
15493 pushl_cfi $do_stack_segment
15494 jmp error_code
15495 CFI_ENDPROC
15496 -END(stack_segment)
15497 +ENDPROC(stack_segment)
15498
15499 ENTRY(alignment_check)
15500 RING0_EC_FRAME
15501 pushl_cfi $do_alignment_check
15502 jmp error_code
15503 CFI_ENDPROC
15504 -END(alignment_check)
15505 +ENDPROC(alignment_check)
15506
15507 ENTRY(divide_error)
15508 RING0_INT_FRAME
15509 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15510 pushl_cfi $do_divide_error
15511 jmp error_code
15512 CFI_ENDPROC
15513 -END(divide_error)
15514 +ENDPROC(divide_error)
15515
15516 #ifdef CONFIG_X86_MCE
15517 ENTRY(machine_check)
15518 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15519 pushl_cfi machine_check_vector
15520 jmp error_code
15521 CFI_ENDPROC
15522 -END(machine_check)
15523 +ENDPROC(machine_check)
15524 #endif
15525
15526 ENTRY(spurious_interrupt_bug)
15527 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15528 pushl_cfi $do_spurious_interrupt_bug
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(spurious_interrupt_bug)
15532 +ENDPROC(spurious_interrupt_bug)
15533 /*
15534 * End of kprobes section
15535 */
15536 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15537
15538 ENTRY(mcount)
15539 ret
15540 -END(mcount)
15541 +ENDPROC(mcount)
15542
15543 ENTRY(ftrace_caller)
15544 cmpl $0, function_trace_stop
15545 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15546 .globl ftrace_stub
15547 ftrace_stub:
15548 ret
15549 -END(ftrace_caller)
15550 +ENDPROC(ftrace_caller)
15551
15552 #else /* ! CONFIG_DYNAMIC_FTRACE */
15553
15554 @@ -1177,7 +1424,7 @@ trace:
15555 popl %ecx
15556 popl %eax
15557 jmp ftrace_stub
15558 -END(mcount)
15559 +ENDPROC(mcount)
15560 #endif /* CONFIG_DYNAMIC_FTRACE */
15561 #endif /* CONFIG_FUNCTION_TRACER */
15562
15563 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15564 popl %ecx
15565 popl %eax
15566 ret
15567 -END(ftrace_graph_caller)
15568 +ENDPROC(ftrace_graph_caller)
15569
15570 .globl return_to_handler
15571 return_to_handler:
15572 @@ -1253,15 +1500,18 @@ error_code:
15573 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15574 REG_TO_PTGS %ecx
15575 SET_KERNEL_GS %ecx
15576 - movl $(__USER_DS), %ecx
15577 + movl $(__KERNEL_DS), %ecx
15578 movl %ecx, %ds
15579 movl %ecx, %es
15580 +
15581 + pax_enter_kernel
15582 +
15583 TRACE_IRQS_OFF
15584 movl %esp,%eax # pt_regs pointer
15585 call *%edi
15586 jmp ret_from_exception
15587 CFI_ENDPROC
15588 -END(page_fault)
15589 +ENDPROC(page_fault)
15590
15591 /*
15592 * Debug traps and NMI can happen at the one SYSENTER instruction
15593 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15594 call do_debug
15595 jmp ret_from_exception
15596 CFI_ENDPROC
15597 -END(debug)
15598 +ENDPROC(debug)
15599
15600 /*
15601 * NMI is doubly nasty. It can happen _while_ we're handling
15602 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15603 xorl %edx,%edx # zero error code
15604 movl %esp,%eax # pt_regs pointer
15605 call do_nmi
15606 +
15607 + pax_exit_kernel
15608 +
15609 jmp restore_all_notrace
15610 CFI_ENDPROC
15611
15612 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15613 FIXUP_ESPFIX_STACK # %eax == %esp
15614 xorl %edx,%edx # zero error code
15615 call do_nmi
15616 +
15617 + pax_exit_kernel
15618 +
15619 RESTORE_REGS
15620 lss 12+4(%esp), %esp # back to espfix stack
15621 CFI_ADJUST_CFA_OFFSET -24
15622 jmp irq_return
15623 CFI_ENDPROC
15624 -END(nmi)
15625 +ENDPROC(nmi)
15626
15627 ENTRY(int3)
15628 RING0_INT_FRAME
15629 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15630 call do_int3
15631 jmp ret_from_exception
15632 CFI_ENDPROC
15633 -END(int3)
15634 +ENDPROC(int3)
15635
15636 ENTRY(general_protection)
15637 RING0_EC_FRAME
15638 pushl_cfi $do_general_protection
15639 jmp error_code
15640 CFI_ENDPROC
15641 -END(general_protection)
15642 +ENDPROC(general_protection)
15643
15644 #ifdef CONFIG_KVM_GUEST
15645 ENTRY(async_page_fault)
15646 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15647 pushl_cfi $do_async_page_fault
15648 jmp error_code
15649 CFI_ENDPROC
15650 -END(async_page_fault)
15651 +ENDPROC(async_page_fault)
15652 #endif
15653
15654 /*
15655 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15656 index cdc79b5..4710a75 100644
15657 --- a/arch/x86/kernel/entry_64.S
15658 +++ b/arch/x86/kernel/entry_64.S
15659 @@ -56,6 +56,8 @@
15660 #include <asm/ftrace.h>
15661 #include <asm/percpu.h>
15662 #include <linux/err.h>
15663 +#include <asm/pgtable.h>
15664 +#include <asm/alternative-asm.h>
15665
15666 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15667 #include <linux/elf-em.h>
15668 @@ -69,8 +71,9 @@
15669 #ifdef CONFIG_FUNCTION_TRACER
15670 #ifdef CONFIG_DYNAMIC_FTRACE
15671 ENTRY(mcount)
15672 + pax_force_retaddr
15673 retq
15674 -END(mcount)
15675 +ENDPROC(mcount)
15676
15677 ENTRY(ftrace_caller)
15678 cmpl $0, function_trace_stop
15679 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15680 #endif
15681
15682 GLOBAL(ftrace_stub)
15683 + pax_force_retaddr
15684 retq
15685 -END(ftrace_caller)
15686 +ENDPROC(ftrace_caller)
15687
15688 #else /* ! CONFIG_DYNAMIC_FTRACE */
15689 ENTRY(mcount)
15690 @@ -113,6 +117,7 @@ ENTRY(mcount)
15691 #endif
15692
15693 GLOBAL(ftrace_stub)
15694 + pax_force_retaddr
15695 retq
15696
15697 trace:
15698 @@ -122,12 +127,13 @@ trace:
15699 movq 8(%rbp), %rsi
15700 subq $MCOUNT_INSN_SIZE, %rdi
15701
15702 + pax_force_fptr ftrace_trace_function
15703 call *ftrace_trace_function
15704
15705 MCOUNT_RESTORE_FRAME
15706
15707 jmp ftrace_stub
15708 -END(mcount)
15709 +ENDPROC(mcount)
15710 #endif /* CONFIG_DYNAMIC_FTRACE */
15711 #endif /* CONFIG_FUNCTION_TRACER */
15712
15713 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15714
15715 MCOUNT_RESTORE_FRAME
15716
15717 + pax_force_retaddr
15718 retq
15719 -END(ftrace_graph_caller)
15720 +ENDPROC(ftrace_graph_caller)
15721
15722 GLOBAL(return_to_handler)
15723 subq $24, %rsp
15724 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15725 movq 8(%rsp), %rdx
15726 movq (%rsp), %rax
15727 addq $24, %rsp
15728 + pax_force_fptr %rdi
15729 jmp *%rdi
15730 #endif
15731
15732 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15733 ENDPROC(native_usergs_sysret64)
15734 #endif /* CONFIG_PARAVIRT */
15735
15736 + .macro ljmpq sel, off
15737 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15738 + .byte 0x48; ljmp *1234f(%rip)
15739 + .pushsection .rodata
15740 + .align 16
15741 + 1234: .quad \off; .word \sel
15742 + .popsection
15743 +#else
15744 + pushq $\sel
15745 + pushq $\off
15746 + lretq
15747 +#endif
15748 + .endm
15749 +
15750 + .macro pax_enter_kernel
15751 + pax_set_fptr_mask
15752 +#ifdef CONFIG_PAX_KERNEXEC
15753 + call pax_enter_kernel
15754 +#endif
15755 + .endm
15756 +
15757 + .macro pax_exit_kernel
15758 +#ifdef CONFIG_PAX_KERNEXEC
15759 + call pax_exit_kernel
15760 +#endif
15761 + .endm
15762 +
15763 +#ifdef CONFIG_PAX_KERNEXEC
15764 +ENTRY(pax_enter_kernel)
15765 + pushq %rdi
15766 +
15767 +#ifdef CONFIG_PARAVIRT
15768 + PV_SAVE_REGS(CLBR_RDI)
15769 +#endif
15770 +
15771 + GET_CR0_INTO_RDI
15772 + bts $16,%rdi
15773 + jnc 3f
15774 + mov %cs,%edi
15775 + cmp $__KERNEL_CS,%edi
15776 + jnz 2f
15777 +1:
15778 +
15779 +#ifdef CONFIG_PARAVIRT
15780 + PV_RESTORE_REGS(CLBR_RDI)
15781 +#endif
15782 +
15783 + popq %rdi
15784 + pax_force_retaddr
15785 + retq
15786 +
15787 +2: ljmpq __KERNEL_CS,1f
15788 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15789 +4: SET_RDI_INTO_CR0
15790 + jmp 1b
15791 +ENDPROC(pax_enter_kernel)
15792 +
15793 +ENTRY(pax_exit_kernel)
15794 + pushq %rdi
15795 +
15796 +#ifdef CONFIG_PARAVIRT
15797 + PV_SAVE_REGS(CLBR_RDI)
15798 +#endif
15799 +
15800 + mov %cs,%rdi
15801 + cmp $__KERNEXEC_KERNEL_CS,%edi
15802 + jz 2f
15803 +1:
15804 +
15805 +#ifdef CONFIG_PARAVIRT
15806 + PV_RESTORE_REGS(CLBR_RDI);
15807 +#endif
15808 +
15809 + popq %rdi
15810 + pax_force_retaddr
15811 + retq
15812 +
15813 +2: GET_CR0_INTO_RDI
15814 + btr $16,%rdi
15815 + ljmpq __KERNEL_CS,3f
15816 +3: SET_RDI_INTO_CR0
15817 + jmp 1b
15818 +#ifdef CONFIG_PARAVIRT
15819 + PV_RESTORE_REGS(CLBR_RDI);
15820 +#endif
15821 +
15822 + popq %rdi
15823 + pax_force_retaddr
15824 + retq
15825 +ENDPROC(pax_exit_kernel)
15826 +#endif
15827 +
15828 + .macro pax_enter_kernel_user
15829 + pax_set_fptr_mask
15830 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15831 + call pax_enter_kernel_user
15832 +#endif
15833 + .endm
15834 +
15835 + .macro pax_exit_kernel_user
15836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15837 + call pax_exit_kernel_user
15838 +#endif
15839 +#ifdef CONFIG_PAX_RANDKSTACK
15840 + pushq %rax
15841 + call pax_randomize_kstack
15842 + popq %rax
15843 +#endif
15844 + .endm
15845 +
15846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15847 +ENTRY(pax_enter_kernel_user)
15848 + pushq %rdi
15849 + pushq %rbx
15850 +
15851 +#ifdef CONFIG_PARAVIRT
15852 + PV_SAVE_REGS(CLBR_RDI)
15853 +#endif
15854 +
15855 + GET_CR3_INTO_RDI
15856 + mov %rdi,%rbx
15857 + add $__START_KERNEL_map,%rbx
15858 + sub phys_base(%rip),%rbx
15859 +
15860 +#ifdef CONFIG_PARAVIRT
15861 + pushq %rdi
15862 + cmpl $0, pv_info+PARAVIRT_enabled
15863 + jz 1f
15864 + i = 0
15865 + .rept USER_PGD_PTRS
15866 + mov i*8(%rbx),%rsi
15867 + mov $0,%sil
15868 + lea i*8(%rbx),%rdi
15869 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15870 + i = i + 1
15871 + .endr
15872 + jmp 2f
15873 +1:
15874 +#endif
15875 +
15876 + i = 0
15877 + .rept USER_PGD_PTRS
15878 + movb $0,i*8(%rbx)
15879 + i = i + 1
15880 + .endr
15881 +
15882 +#ifdef CONFIG_PARAVIRT
15883 +2: popq %rdi
15884 +#endif
15885 + SET_RDI_INTO_CR3
15886 +
15887 +#ifdef CONFIG_PAX_KERNEXEC
15888 + GET_CR0_INTO_RDI
15889 + bts $16,%rdi
15890 + SET_RDI_INTO_CR0
15891 +#endif
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 + PV_RESTORE_REGS(CLBR_RDI)
15895 +#endif
15896 +
15897 + popq %rbx
15898 + popq %rdi
15899 + pax_force_retaddr
15900 + retq
15901 +ENDPROC(pax_enter_kernel_user)
15902 +
15903 +ENTRY(pax_exit_kernel_user)
15904 + push %rdi
15905 +
15906 +#ifdef CONFIG_PARAVIRT
15907 + pushq %rbx
15908 + PV_SAVE_REGS(CLBR_RDI)
15909 +#endif
15910 +
15911 +#ifdef CONFIG_PAX_KERNEXEC
15912 + GET_CR0_INTO_RDI
15913 + btr $16,%rdi
15914 + SET_RDI_INTO_CR0
15915 +#endif
15916 +
15917 + GET_CR3_INTO_RDI
15918 + add $__START_KERNEL_map,%rdi
15919 + sub phys_base(%rip),%rdi
15920 +
15921 +#ifdef CONFIG_PARAVIRT
15922 + cmpl $0, pv_info+PARAVIRT_enabled
15923 + jz 1f
15924 + mov %rdi,%rbx
15925 + i = 0
15926 + .rept USER_PGD_PTRS
15927 + mov i*8(%rbx),%rsi
15928 + mov $0x67,%sil
15929 + lea i*8(%rbx),%rdi
15930 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15931 + i = i + 1
15932 + .endr
15933 + jmp 2f
15934 +1:
15935 +#endif
15936 +
15937 + i = 0
15938 + .rept USER_PGD_PTRS
15939 + movb $0x67,i*8(%rdi)
15940 + i = i + 1
15941 + .endr
15942 +
15943 +#ifdef CONFIG_PARAVIRT
15944 +2: PV_RESTORE_REGS(CLBR_RDI)
15945 + popq %rbx
15946 +#endif
15947 +
15948 + popq %rdi
15949 + pax_force_retaddr
15950 + retq
15951 +ENDPROC(pax_exit_kernel_user)
15952 +#endif
15953 +
15954 +.macro pax_erase_kstack
15955 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15956 + call pax_erase_kstack
15957 +#endif
15958 +.endm
15959 +
15960 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15961 +/*
15962 + * r11: thread_info
15963 + * rcx, rdx: can be clobbered
15964 + */
15965 +ENTRY(pax_erase_kstack)
15966 + pushq %rdi
15967 + pushq %rax
15968 + pushq %r11
15969 +
15970 + GET_THREAD_INFO(%r11)
15971 + mov TI_lowest_stack(%r11), %rdi
15972 + mov $-0xBEEF, %rax
15973 + std
15974 +
15975 +1: mov %edi, %ecx
15976 + and $THREAD_SIZE_asm - 1, %ecx
15977 + shr $3, %ecx
15978 + repne scasq
15979 + jecxz 2f
15980 +
15981 + cmp $2*8, %ecx
15982 + jc 2f
15983 +
15984 + mov $2*8, %ecx
15985 + repe scasq
15986 + jecxz 2f
15987 + jne 1b
15988 +
15989 +2: cld
15990 + mov %esp, %ecx
15991 + sub %edi, %ecx
15992 +
15993 + cmp $THREAD_SIZE_asm, %rcx
15994 + jb 3f
15995 + ud2
15996 +3:
15997 +
15998 + shr $3, %ecx
15999 + rep stosq
16000 +
16001 + mov TI_task_thread_sp0(%r11), %rdi
16002 + sub $256, %rdi
16003 + mov %rdi, TI_lowest_stack(%r11)
16004 +
16005 + popq %r11
16006 + popq %rax
16007 + popq %rdi
16008 + pax_force_retaddr
16009 + ret
16010 +ENDPROC(pax_erase_kstack)
16011 +#endif
16012
16013 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16014 #ifdef CONFIG_TRACE_IRQFLAGS
16015 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16016 .endm
16017
16018 .macro UNFAKE_STACK_FRAME
16019 - addq $8*6, %rsp
16020 - CFI_ADJUST_CFA_OFFSET -(6*8)
16021 + addq $8*6 + ARG_SKIP, %rsp
16022 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16023 .endm
16024
16025 /*
16026 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16027 movq %rsp, %rsi
16028
16029 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16030 - testl $3, CS-RBP(%rsi)
16031 + testb $3, CS-RBP(%rsi)
16032 je 1f
16033 SWAPGS
16034 /*
16035 @@ -355,9 +639,10 @@ ENTRY(save_rest)
16036 movq_cfi r15, R15+16
16037 movq %r11, 8(%rsp) /* return address */
16038 FIXUP_TOP_OF_STACK %r11, 16
16039 + pax_force_retaddr
16040 ret
16041 CFI_ENDPROC
16042 -END(save_rest)
16043 +ENDPROC(save_rest)
16044
16045 /* save complete stack frame */
16046 .pushsection .kprobes.text, "ax"
16047 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16048 js 1f /* negative -> in kernel */
16049 SWAPGS
16050 xorl %ebx,%ebx
16051 -1: ret
16052 +1: pax_force_retaddr_bts
16053 + ret
16054 CFI_ENDPROC
16055 -END(save_paranoid)
16056 +ENDPROC(save_paranoid)
16057 .popsection
16058
16059 /*
16060 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16061
16062 RESTORE_REST
16063
16064 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16065 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16066 jz retint_restore_args
16067
16068 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16069 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16070 jmp ret_from_sys_call # go to the SYSRET fastpath
16071
16072 CFI_ENDPROC
16073 -END(ret_from_fork)
16074 +ENDPROC(ret_from_fork)
16075
16076 /*
16077 * System call entry. Up to 6 arguments in registers are supported.
16078 @@ -456,7 +742,7 @@ END(ret_from_fork)
16079 ENTRY(system_call)
16080 CFI_STARTPROC simple
16081 CFI_SIGNAL_FRAME
16082 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16083 + CFI_DEF_CFA rsp,0
16084 CFI_REGISTER rip,rcx
16085 /*CFI_REGISTER rflags,r11*/
16086 SWAPGS_UNSAFE_STACK
16087 @@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16088
16089 movq %rsp,PER_CPU_VAR(old_rsp)
16090 movq PER_CPU_VAR(kernel_stack),%rsp
16091 + SAVE_ARGS 8*6,0
16092 + pax_enter_kernel_user
16093 /*
16094 * No need to follow this irqs off/on section - it's straight
16095 * and short:
16096 */
16097 ENABLE_INTERRUPTS(CLBR_NONE)
16098 - SAVE_ARGS 8,0
16099 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16100 movq %rcx,RIP-ARGOFFSET(%rsp)
16101 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16102 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16103 + GET_THREAD_INFO(%rcx)
16104 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16105 jnz tracesys
16106 system_call_fastpath:
16107 #if __SYSCALL_MASK == ~0
16108 @@ -488,7 +776,7 @@ system_call_fastpath:
16109 cmpl $__NR_syscall_max,%eax
16110 #endif
16111 ja badsys
16112 - movq %r10,%rcx
16113 + movq R10-ARGOFFSET(%rsp),%rcx
16114 call *sys_call_table(,%rax,8) # XXX: rip relative
16115 movq %rax,RAX-ARGOFFSET(%rsp)
16116 /*
16117 @@ -502,10 +790,13 @@ sysret_check:
16118 LOCKDEP_SYS_EXIT
16119 DISABLE_INTERRUPTS(CLBR_NONE)
16120 TRACE_IRQS_OFF
16121 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16122 + GET_THREAD_INFO(%rcx)
16123 + movl TI_flags(%rcx),%edx
16124 andl %edi,%edx
16125 jnz sysret_careful
16126 CFI_REMEMBER_STATE
16127 + pax_exit_kernel_user
16128 + pax_erase_kstack
16129 /*
16130 * sysretq will re-enable interrupts:
16131 */
16132 @@ -557,14 +848,18 @@ badsys:
16133 * jump back to the normal fast path.
16134 */
16135 auditsys:
16136 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16137 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16138 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16139 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16140 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16141 movq %rax,%rsi /* 2nd arg: syscall number */
16142 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16143 call __audit_syscall_entry
16144 +
16145 + pax_erase_kstack
16146 +
16147 LOAD_ARGS 0 /* reload call-clobbered registers */
16148 + pax_set_fptr_mask
16149 jmp system_call_fastpath
16150
16151 /*
16152 @@ -585,7 +880,7 @@ sysret_audit:
16153 /* Do syscall tracing */
16154 tracesys:
16155 #ifdef CONFIG_AUDITSYSCALL
16156 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16157 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16158 jz auditsys
16159 #endif
16160 SAVE_REST
16161 @@ -593,12 +888,16 @@ tracesys:
16162 FIXUP_TOP_OF_STACK %rdi
16163 movq %rsp,%rdi
16164 call syscall_trace_enter
16165 +
16166 + pax_erase_kstack
16167 +
16168 /*
16169 * Reload arg registers from stack in case ptrace changed them.
16170 * We don't reload %rax because syscall_trace_enter() returned
16171 * the value it wants us to use in the table lookup.
16172 */
16173 LOAD_ARGS ARGOFFSET, 1
16174 + pax_set_fptr_mask
16175 RESTORE_REST
16176 #if __SYSCALL_MASK == ~0
16177 cmpq $__NR_syscall_max,%rax
16178 @@ -607,7 +906,7 @@ tracesys:
16179 cmpl $__NR_syscall_max,%eax
16180 #endif
16181 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16182 - movq %r10,%rcx /* fixup for C */
16183 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16184 call *sys_call_table(,%rax,8)
16185 movq %rax,RAX-ARGOFFSET(%rsp)
16186 /* Use IRET because user could have changed frame */
16187 @@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16188 andl %edi,%edx
16189 jnz int_careful
16190 andl $~TS_COMPAT,TI_status(%rcx)
16191 + pax_erase_kstack
16192 jmp retint_swapgs
16193
16194 /* Either reschedule or signal or syscall exit tracking needed. */
16195 @@ -674,7 +974,7 @@ int_restore_rest:
16196 TRACE_IRQS_OFF
16197 jmp int_with_check
16198 CFI_ENDPROC
16199 -END(system_call)
16200 +ENDPROC(system_call)
16201
16202 /*
16203 * Certain special system calls that need to save a complete full stack frame.
16204 @@ -690,7 +990,7 @@ ENTRY(\label)
16205 call \func
16206 jmp ptregscall_common
16207 CFI_ENDPROC
16208 -END(\label)
16209 +ENDPROC(\label)
16210 .endm
16211
16212 PTREGSCALL stub_clone, sys_clone, %r8
16213 @@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16214 movq_cfi_restore R12+8, r12
16215 movq_cfi_restore RBP+8, rbp
16216 movq_cfi_restore RBX+8, rbx
16217 + pax_force_retaddr
16218 ret $REST_SKIP /* pop extended registers */
16219 CFI_ENDPROC
16220 -END(ptregscall_common)
16221 +ENDPROC(ptregscall_common)
16222
16223 ENTRY(stub_execve)
16224 CFI_STARTPROC
16225 @@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16226 RESTORE_REST
16227 jmp int_ret_from_sys_call
16228 CFI_ENDPROC
16229 -END(stub_execve)
16230 +ENDPROC(stub_execve)
16231
16232 /*
16233 * sigreturn is special because it needs to restore all registers on return.
16234 @@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16235 RESTORE_REST
16236 jmp int_ret_from_sys_call
16237 CFI_ENDPROC
16238 -END(stub_rt_sigreturn)
16239 +ENDPROC(stub_rt_sigreturn)
16240
16241 #ifdef CONFIG_X86_X32_ABI
16242 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16243 @@ -812,7 +1113,7 @@ vector=vector+1
16244 2: jmp common_interrupt
16245 .endr
16246 CFI_ENDPROC
16247 -END(irq_entries_start)
16248 +ENDPROC(irq_entries_start)
16249
16250 .previous
16251 END(interrupt)
16252 @@ -832,6 +1133,16 @@ END(interrupt)
16253 subq $ORIG_RAX-RBP, %rsp
16254 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16255 SAVE_ARGS_IRQ
16256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16257 + testb $3, CS(%rdi)
16258 + jnz 1f
16259 + pax_enter_kernel
16260 + jmp 2f
16261 +1: pax_enter_kernel_user
16262 +2:
16263 +#else
16264 + pax_enter_kernel
16265 +#endif
16266 call \func
16267 .endm
16268
16269 @@ -863,7 +1174,7 @@ ret_from_intr:
16270
16271 exit_intr:
16272 GET_THREAD_INFO(%rcx)
16273 - testl $3,CS-ARGOFFSET(%rsp)
16274 + testb $3,CS-ARGOFFSET(%rsp)
16275 je retint_kernel
16276
16277 /* Interrupt came from user space */
16278 @@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16279 * The iretq could re-enable interrupts:
16280 */
16281 DISABLE_INTERRUPTS(CLBR_ANY)
16282 + pax_exit_kernel_user
16283 TRACE_IRQS_IRETQ
16284 SWAPGS
16285 jmp restore_args
16286
16287 retint_restore_args: /* return to kernel space */
16288 DISABLE_INTERRUPTS(CLBR_ANY)
16289 + pax_exit_kernel
16290 + pax_force_retaddr RIP-ARGOFFSET
16291 /*
16292 * The iretq could re-enable interrupts:
16293 */
16294 @@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16295 #endif
16296
16297 CFI_ENDPROC
16298 -END(common_interrupt)
16299 +ENDPROC(common_interrupt)
16300 /*
16301 * End of kprobes section
16302 */
16303 @@ -996,7 +1310,7 @@ ENTRY(\sym)
16304 interrupt \do_sym
16305 jmp ret_from_intr
16306 CFI_ENDPROC
16307 -END(\sym)
16308 +ENDPROC(\sym)
16309 .endm
16310
16311 #ifdef CONFIG_SMP
16312 @@ -1069,12 +1383,22 @@ ENTRY(\sym)
16313 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16314 call error_entry
16315 DEFAULT_FRAME 0
16316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16317 + testb $3, CS(%rsp)
16318 + jnz 1f
16319 + pax_enter_kernel
16320 + jmp 2f
16321 +1: pax_enter_kernel_user
16322 +2:
16323 +#else
16324 + pax_enter_kernel
16325 +#endif
16326 movq %rsp,%rdi /* pt_regs pointer */
16327 xorl %esi,%esi /* no error code */
16328 call \do_sym
16329 jmp error_exit /* %ebx: no swapgs flag */
16330 CFI_ENDPROC
16331 -END(\sym)
16332 +ENDPROC(\sym)
16333 .endm
16334
16335 .macro paranoidzeroentry sym do_sym
16336 @@ -1086,15 +1410,25 @@ ENTRY(\sym)
16337 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16338 call save_paranoid
16339 TRACE_IRQS_OFF
16340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16341 + testb $3, CS(%rsp)
16342 + jnz 1f
16343 + pax_enter_kernel
16344 + jmp 2f
16345 +1: pax_enter_kernel_user
16346 +2:
16347 +#else
16348 + pax_enter_kernel
16349 +#endif
16350 movq %rsp,%rdi /* pt_regs pointer */
16351 xorl %esi,%esi /* no error code */
16352 call \do_sym
16353 jmp paranoid_exit /* %ebx: no swapgs flag */
16354 CFI_ENDPROC
16355 -END(\sym)
16356 +ENDPROC(\sym)
16357 .endm
16358
16359 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16360 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16361 .macro paranoidzeroentry_ist sym do_sym ist
16362 ENTRY(\sym)
16363 INTR_FRAME
16364 @@ -1104,14 +1438,30 @@ ENTRY(\sym)
16365 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16366 call save_paranoid
16367 TRACE_IRQS_OFF
16368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16369 + testb $3, CS(%rsp)
16370 + jnz 1f
16371 + pax_enter_kernel
16372 + jmp 2f
16373 +1: pax_enter_kernel_user
16374 +2:
16375 +#else
16376 + pax_enter_kernel
16377 +#endif
16378 movq %rsp,%rdi /* pt_regs pointer */
16379 xorl %esi,%esi /* no error code */
16380 +#ifdef CONFIG_SMP
16381 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16382 + lea init_tss(%r12), %r12
16383 +#else
16384 + lea init_tss(%rip), %r12
16385 +#endif
16386 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16387 call \do_sym
16388 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16389 jmp paranoid_exit /* %ebx: no swapgs flag */
16390 CFI_ENDPROC
16391 -END(\sym)
16392 +ENDPROC(\sym)
16393 .endm
16394
16395 .macro errorentry sym do_sym
16396 @@ -1122,13 +1472,23 @@ ENTRY(\sym)
16397 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16398 call error_entry
16399 DEFAULT_FRAME 0
16400 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16401 + testb $3, CS(%rsp)
16402 + jnz 1f
16403 + pax_enter_kernel
16404 + jmp 2f
16405 +1: pax_enter_kernel_user
16406 +2:
16407 +#else
16408 + pax_enter_kernel
16409 +#endif
16410 movq %rsp,%rdi /* pt_regs pointer */
16411 movq ORIG_RAX(%rsp),%rsi /* get error code */
16412 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16413 call \do_sym
16414 jmp error_exit /* %ebx: no swapgs flag */
16415 CFI_ENDPROC
16416 -END(\sym)
16417 +ENDPROC(\sym)
16418 .endm
16419
16420 /* error code is on the stack already */
16421 @@ -1141,13 +1501,23 @@ ENTRY(\sym)
16422 call save_paranoid
16423 DEFAULT_FRAME 0
16424 TRACE_IRQS_OFF
16425 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16426 + testb $3, CS(%rsp)
16427 + jnz 1f
16428 + pax_enter_kernel
16429 + jmp 2f
16430 +1: pax_enter_kernel_user
16431 +2:
16432 +#else
16433 + pax_enter_kernel
16434 +#endif
16435 movq %rsp,%rdi /* pt_regs pointer */
16436 movq ORIG_RAX(%rsp),%rsi /* get error code */
16437 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16438 call \do_sym
16439 jmp paranoid_exit /* %ebx: no swapgs flag */
16440 CFI_ENDPROC
16441 -END(\sym)
16442 +ENDPROC(\sym)
16443 .endm
16444
16445 zeroentry divide_error do_divide_error
16446 @@ -1177,9 +1547,10 @@ gs_change:
16447 2: mfence /* workaround */
16448 SWAPGS
16449 popfq_cfi
16450 + pax_force_retaddr
16451 ret
16452 CFI_ENDPROC
16453 -END(native_load_gs_index)
16454 +ENDPROC(native_load_gs_index)
16455
16456 .section __ex_table,"a"
16457 .align 8
16458 @@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16459 * Here we are in the child and the registers are set as they were
16460 * at kernel_thread() invocation in the parent.
16461 */
16462 + pax_force_fptr %rsi
16463 call *%rsi
16464 # exit
16465 mov %eax, %edi
16466 call do_exit
16467 ud2 # padding for call trace
16468 CFI_ENDPROC
16469 -END(kernel_thread_helper)
16470 +ENDPROC(kernel_thread_helper)
16471
16472 /*
16473 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16474 @@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16475 RESTORE_REST
16476 testq %rax,%rax
16477 je int_ret_from_sys_call
16478 - RESTORE_ARGS
16479 UNFAKE_STACK_FRAME
16480 + pax_force_retaddr
16481 ret
16482 CFI_ENDPROC
16483 -END(kernel_execve)
16484 +ENDPROC(kernel_execve)
16485
16486 /* Call softirq on interrupt stack. Interrupts are off. */
16487 ENTRY(call_softirq)
16488 @@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16489 CFI_DEF_CFA_REGISTER rsp
16490 CFI_ADJUST_CFA_OFFSET -8
16491 decl PER_CPU_VAR(irq_count)
16492 + pax_force_retaddr
16493 ret
16494 CFI_ENDPROC
16495 -END(call_softirq)
16496 +ENDPROC(call_softirq)
16497
16498 #ifdef CONFIG_XEN
16499 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16500 @@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16501 decl PER_CPU_VAR(irq_count)
16502 jmp error_exit
16503 CFI_ENDPROC
16504 -END(xen_do_hypervisor_callback)
16505 +ENDPROC(xen_do_hypervisor_callback)
16506
16507 /*
16508 * Hypervisor uses this for application faults while it executes.
16509 @@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16510 SAVE_ALL
16511 jmp error_exit
16512 CFI_ENDPROC
16513 -END(xen_failsafe_callback)
16514 +ENDPROC(xen_failsafe_callback)
16515
16516 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16517 xen_hvm_callback_vector xen_evtchn_do_upcall
16518 @@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16519 TRACE_IRQS_OFF
16520 testl %ebx,%ebx /* swapgs needed? */
16521 jnz paranoid_restore
16522 - testl $3,CS(%rsp)
16523 + testb $3,CS(%rsp)
16524 jnz paranoid_userspace
16525 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16526 + pax_exit_kernel
16527 + TRACE_IRQS_IRETQ 0
16528 + SWAPGS_UNSAFE_STACK
16529 + RESTORE_ALL 8
16530 + pax_force_retaddr_bts
16531 + jmp irq_return
16532 +#endif
16533 paranoid_swapgs:
16534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16535 + pax_exit_kernel_user
16536 +#else
16537 + pax_exit_kernel
16538 +#endif
16539 TRACE_IRQS_IRETQ 0
16540 SWAPGS_UNSAFE_STACK
16541 RESTORE_ALL 8
16542 jmp irq_return
16543 paranoid_restore:
16544 + pax_exit_kernel
16545 TRACE_IRQS_IRETQ 0
16546 RESTORE_ALL 8
16547 + pax_force_retaddr_bts
16548 jmp irq_return
16549 paranoid_userspace:
16550 GET_THREAD_INFO(%rcx)
16551 @@ -1442,7 +1830,7 @@ paranoid_schedule:
16552 TRACE_IRQS_OFF
16553 jmp paranoid_userspace
16554 CFI_ENDPROC
16555 -END(paranoid_exit)
16556 +ENDPROC(paranoid_exit)
16557
16558 /*
16559 * Exception entry point. This expects an error code/orig_rax on the stack.
16560 @@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16561 movq_cfi r14, R14+8
16562 movq_cfi r15, R15+8
16563 xorl %ebx,%ebx
16564 - testl $3,CS+8(%rsp)
16565 + testb $3,CS+8(%rsp)
16566 je error_kernelspace
16567 error_swapgs:
16568 SWAPGS
16569 error_sti:
16570 TRACE_IRQS_OFF
16571 + pax_force_retaddr_bts
16572 ret
16573
16574 /*
16575 @@ -1501,7 +1890,7 @@ bstep_iret:
16576 movq %rcx,RIP+8(%rsp)
16577 jmp error_swapgs
16578 CFI_ENDPROC
16579 -END(error_entry)
16580 +ENDPROC(error_entry)
16581
16582
16583 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16584 @@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16585 jnz retint_careful
16586 jmp retint_swapgs
16587 CFI_ENDPROC
16588 -END(error_exit)
16589 +ENDPROC(error_exit)
16590
16591 /*
16592 * Test if a given stack is an NMI stack or not.
16593 @@ -1579,9 +1968,11 @@ ENTRY(nmi)
16594 * If %cs was not the kernel segment, then the NMI triggered in user
16595 * space, which means it is definitely not nested.
16596 */
16597 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16598 + je 1f
16599 cmpl $__KERNEL_CS, 16(%rsp)
16600 jne first_nmi
16601 -
16602 +1:
16603 /*
16604 * Check the special variable on the stack to see if NMIs are
16605 * executing.
16606 @@ -1728,6 +2119,16 @@ end_repeat_nmi:
16607 */
16608 call save_paranoid
16609 DEFAULT_FRAME 0
16610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16611 + testb $3, CS(%rsp)
16612 + jnz 1f
16613 + pax_enter_kernel
16614 + jmp 2f
16615 +1: pax_enter_kernel_user
16616 +2:
16617 +#else
16618 + pax_enter_kernel
16619 +#endif
16620 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16621 movq %rsp,%rdi
16622 movq $-1,%rsi
16623 @@ -1735,21 +2136,32 @@ end_repeat_nmi:
16624 testl %ebx,%ebx /* swapgs needed? */
16625 jnz nmi_restore
16626 nmi_swapgs:
16627 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16628 + pax_exit_kernel_user
16629 +#else
16630 + pax_exit_kernel
16631 +#endif
16632 SWAPGS_UNSAFE_STACK
16633 + RESTORE_ALL 8
16634 + /* Clear the NMI executing stack variable */
16635 + movq $0, 10*8(%rsp)
16636 + jmp irq_return
16637 nmi_restore:
16638 + pax_exit_kernel
16639 RESTORE_ALL 8
16640 + pax_force_retaddr_bts
16641 /* Clear the NMI executing stack variable */
16642 movq $0, 10*8(%rsp)
16643 jmp irq_return
16644 CFI_ENDPROC
16645 -END(nmi)
16646 +ENDPROC(nmi)
16647
16648 ENTRY(ignore_sysret)
16649 CFI_STARTPROC
16650 mov $-ENOSYS,%eax
16651 sysret
16652 CFI_ENDPROC
16653 -END(ignore_sysret)
16654 +ENDPROC(ignore_sysret)
16655
16656 /*
16657 * End of kprobes section
16658 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16659 index c9a281f..ce2f317 100644
16660 --- a/arch/x86/kernel/ftrace.c
16661 +++ b/arch/x86/kernel/ftrace.c
16662 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16663 static const void *mod_code_newcode; /* holds the text to write to the IP */
16664
16665 static unsigned nmi_wait_count;
16666 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16667 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16668
16669 int ftrace_arch_read_dyn_info(char *buf, int size)
16670 {
16671 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16672
16673 r = snprintf(buf, size, "%u %u",
16674 nmi_wait_count,
16675 - atomic_read(&nmi_update_count));
16676 + atomic_read_unchecked(&nmi_update_count));
16677 return r;
16678 }
16679
16680 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16681
16682 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16683 smp_rmb();
16684 + pax_open_kernel();
16685 ftrace_mod_code();
16686 - atomic_inc(&nmi_update_count);
16687 + pax_close_kernel();
16688 + atomic_inc_unchecked(&nmi_update_count);
16689 }
16690 /* Must have previous changes seen before executions */
16691 smp_mb();
16692 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16693 {
16694 unsigned char replaced[MCOUNT_INSN_SIZE];
16695
16696 + ip = ktla_ktva(ip);
16697 +
16698 /*
16699 * Note: Due to modules and __init, code can
16700 * disappear and change, we need to protect against faulting
16701 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16702 unsigned char old[MCOUNT_INSN_SIZE], *new;
16703 int ret;
16704
16705 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16706 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16707 new = ftrace_call_replace(ip, (unsigned long)func);
16708 ret = ftrace_modify_code(ip, old, new);
16709
16710 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16711 {
16712 unsigned char code[MCOUNT_INSN_SIZE];
16713
16714 + ip = ktla_ktva(ip);
16715 +
16716 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16717 return -EFAULT;
16718
16719 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16720 index 51ff186..9e77418 100644
16721 --- a/arch/x86/kernel/head32.c
16722 +++ b/arch/x86/kernel/head32.c
16723 @@ -19,6 +19,7 @@
16724 #include <asm/io_apic.h>
16725 #include <asm/bios_ebda.h>
16726 #include <asm/tlbflush.h>
16727 +#include <asm/boot.h>
16728
16729 static void __init i386_default_early_setup(void)
16730 {
16731 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16732
16733 void __init i386_start_kernel(void)
16734 {
16735 - memblock_reserve(__pa_symbol(&_text),
16736 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16737 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16738
16739 #ifdef CONFIG_BLK_DEV_INITRD
16740 /* Reserve INITRD */
16741 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16742 index ce0be7c..c41476e 100644
16743 --- a/arch/x86/kernel/head_32.S
16744 +++ b/arch/x86/kernel/head_32.S
16745 @@ -25,6 +25,12 @@
16746 /* Physical address */
16747 #define pa(X) ((X) - __PAGE_OFFSET)
16748
16749 +#ifdef CONFIG_PAX_KERNEXEC
16750 +#define ta(X) (X)
16751 +#else
16752 +#define ta(X) ((X) - __PAGE_OFFSET)
16753 +#endif
16754 +
16755 /*
16756 * References to members of the new_cpu_data structure.
16757 */
16758 @@ -54,11 +60,7 @@
16759 * and small than max_low_pfn, otherwise will waste some page table entries
16760 */
16761
16762 -#if PTRS_PER_PMD > 1
16763 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16764 -#else
16765 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16766 -#endif
16767 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16768
16769 /* Number of possible pages in the lowmem region */
16770 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16771 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16772 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16773
16774 /*
16775 + * Real beginning of normal "text" segment
16776 + */
16777 +ENTRY(stext)
16778 +ENTRY(_stext)
16779 +
16780 +/*
16781 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16782 * %esi points to the real-mode code as a 32-bit pointer.
16783 * CS and DS must be 4 GB flat segments, but we don't depend on
16784 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16785 * can.
16786 */
16787 __HEAD
16788 +
16789 +#ifdef CONFIG_PAX_KERNEXEC
16790 + jmp startup_32
16791 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16792 +.fill PAGE_SIZE-5,1,0xcc
16793 +#endif
16794 +
16795 ENTRY(startup_32)
16796 movl pa(stack_start),%ecx
16797
16798 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16799 2:
16800 leal -__PAGE_OFFSET(%ecx),%esp
16801
16802 +#ifdef CONFIG_SMP
16803 + movl $pa(cpu_gdt_table),%edi
16804 + movl $__per_cpu_load,%eax
16805 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16806 + rorl $16,%eax
16807 + movb %al,__KERNEL_PERCPU + 4(%edi)
16808 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16809 + movl $__per_cpu_end - 1,%eax
16810 + subl $__per_cpu_start,%eax
16811 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16812 +#endif
16813 +
16814 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16815 + movl $NR_CPUS,%ecx
16816 + movl $pa(cpu_gdt_table),%edi
16817 +1:
16818 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16819 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16820 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16821 + addl $PAGE_SIZE_asm,%edi
16822 + loop 1b
16823 +#endif
16824 +
16825 +#ifdef CONFIG_PAX_KERNEXEC
16826 + movl $pa(boot_gdt),%edi
16827 + movl $__LOAD_PHYSICAL_ADDR,%eax
16828 + movw %ax,__BOOT_CS + 2(%edi)
16829 + rorl $16,%eax
16830 + movb %al,__BOOT_CS + 4(%edi)
16831 + movb %ah,__BOOT_CS + 7(%edi)
16832 + rorl $16,%eax
16833 +
16834 + ljmp $(__BOOT_CS),$1f
16835 +1:
16836 +
16837 + movl $NR_CPUS,%ecx
16838 + movl $pa(cpu_gdt_table),%edi
16839 + addl $__PAGE_OFFSET,%eax
16840 +1:
16841 + movw %ax,__KERNEL_CS + 2(%edi)
16842 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16843 + rorl $16,%eax
16844 + movb %al,__KERNEL_CS + 4(%edi)
16845 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16846 + movb %ah,__KERNEL_CS + 7(%edi)
16847 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16848 + rorl $16,%eax
16849 + addl $PAGE_SIZE_asm,%edi
16850 + loop 1b
16851 +#endif
16852 +
16853 /*
16854 * Clear BSS first so that there are no surprises...
16855 */
16856 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16857 movl %eax, pa(max_pfn_mapped)
16858
16859 /* Do early initialization of the fixmap area */
16860 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16861 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16862 +#ifdef CONFIG_COMPAT_VDSO
16863 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16864 +#else
16865 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16866 +#endif
16867 #else /* Not PAE */
16868
16869 page_pde_offset = (__PAGE_OFFSET >> 20);
16870 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16871 movl %eax, pa(max_pfn_mapped)
16872
16873 /* Do early initialization of the fixmap area */
16874 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16875 - movl %eax,pa(initial_page_table+0xffc)
16876 +#ifdef CONFIG_COMPAT_VDSO
16877 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16878 +#else
16879 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16880 +#endif
16881 #endif
16882
16883 #ifdef CONFIG_PARAVIRT
16884 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16885 cmpl $num_subarch_entries, %eax
16886 jae bad_subarch
16887
16888 - movl pa(subarch_entries)(,%eax,4), %eax
16889 - subl $__PAGE_OFFSET, %eax
16890 - jmp *%eax
16891 + jmp *pa(subarch_entries)(,%eax,4)
16892
16893 bad_subarch:
16894 WEAK(lguest_entry)
16895 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16896 __INITDATA
16897
16898 subarch_entries:
16899 - .long default_entry /* normal x86/PC */
16900 - .long lguest_entry /* lguest hypervisor */
16901 - .long xen_entry /* Xen hypervisor */
16902 - .long default_entry /* Moorestown MID */
16903 + .long ta(default_entry) /* normal x86/PC */
16904 + .long ta(lguest_entry) /* lguest hypervisor */
16905 + .long ta(xen_entry) /* Xen hypervisor */
16906 + .long ta(default_entry) /* Moorestown MID */
16907 num_subarch_entries = (. - subarch_entries) / 4
16908 .previous
16909 #else
16910 @@ -312,6 +382,7 @@ default_entry:
16911 orl %edx,%eax
16912 movl %eax,%cr4
16913
16914 +#ifdef CONFIG_X86_PAE
16915 testb $X86_CR4_PAE, %al # check if PAE is enabled
16916 jz 6f
16917
16918 @@ -340,6 +411,9 @@ default_entry:
16919 /* Make changes effective */
16920 wrmsr
16921
16922 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16923 +#endif
16924 +
16925 6:
16926
16927 /*
16928 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16929 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16930 movl %eax,%ss # after changing gdt.
16931
16932 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16933 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16934 movl %eax,%ds
16935 movl %eax,%es
16936
16937 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16938 */
16939 cmpb $0,ready
16940 jne 1f
16941 - movl $gdt_page,%eax
16942 + movl $cpu_gdt_table,%eax
16943 movl $stack_canary,%ecx
16944 +#ifdef CONFIG_SMP
16945 + addl $__per_cpu_load,%ecx
16946 +#endif
16947 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16948 shrl $16, %ecx
16949 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16950 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16951 1:
16952 -#endif
16953 movl $(__KERNEL_STACK_CANARY),%eax
16954 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16955 + movl $(__USER_DS),%eax
16956 +#else
16957 + xorl %eax,%eax
16958 +#endif
16959 movl %eax,%gs
16960
16961 xorl %eax,%eax # Clear LDT
16962 @@ -558,22 +639,22 @@ early_page_fault:
16963 jmp early_fault
16964
16965 early_fault:
16966 - cld
16967 #ifdef CONFIG_PRINTK
16968 + cmpl $1,%ss:early_recursion_flag
16969 + je hlt_loop
16970 + incl %ss:early_recursion_flag
16971 + cld
16972 pusha
16973 movl $(__KERNEL_DS),%eax
16974 movl %eax,%ds
16975 movl %eax,%es
16976 - cmpl $2,early_recursion_flag
16977 - je hlt_loop
16978 - incl early_recursion_flag
16979 movl %cr2,%eax
16980 pushl %eax
16981 pushl %edx /* trapno */
16982 pushl $fault_msg
16983 call printk
16984 +; call dump_stack
16985 #endif
16986 - call dump_stack
16987 hlt_loop:
16988 hlt
16989 jmp hlt_loop
16990 @@ -581,8 +662,11 @@ hlt_loop:
16991 /* This is the default interrupt "handler" :-) */
16992 ALIGN
16993 ignore_int:
16994 - cld
16995 #ifdef CONFIG_PRINTK
16996 + cmpl $2,%ss:early_recursion_flag
16997 + je hlt_loop
16998 + incl %ss:early_recursion_flag
16999 + cld
17000 pushl %eax
17001 pushl %ecx
17002 pushl %edx
17003 @@ -591,9 +675,6 @@ ignore_int:
17004 movl $(__KERNEL_DS),%eax
17005 movl %eax,%ds
17006 movl %eax,%es
17007 - cmpl $2,early_recursion_flag
17008 - je hlt_loop
17009 - incl early_recursion_flag
17010 pushl 16(%esp)
17011 pushl 24(%esp)
17012 pushl 32(%esp)
17013 @@ -622,29 +703,43 @@ ENTRY(initial_code)
17014 /*
17015 * BSS section
17016 */
17017 -__PAGE_ALIGNED_BSS
17018 - .align PAGE_SIZE
17019 #ifdef CONFIG_X86_PAE
17020 +.section .initial_pg_pmd,"a",@progbits
17021 initial_pg_pmd:
17022 .fill 1024*KPMDS,4,0
17023 #else
17024 +.section .initial_page_table,"a",@progbits
17025 ENTRY(initial_page_table)
17026 .fill 1024,4,0
17027 #endif
17028 +.section .initial_pg_fixmap,"a",@progbits
17029 initial_pg_fixmap:
17030 .fill 1024,4,0
17031 +.section .empty_zero_page,"a",@progbits
17032 ENTRY(empty_zero_page)
17033 .fill 4096,1,0
17034 +.section .swapper_pg_dir,"a",@progbits
17035 ENTRY(swapper_pg_dir)
17036 +#ifdef CONFIG_X86_PAE
17037 + .fill 4,8,0
17038 +#else
17039 .fill 1024,4,0
17040 +#endif
17041 +
17042 +/*
17043 + * The IDT has to be page-aligned to simplify the Pentium
17044 + * F0 0F bug workaround.. We have a special link segment
17045 + * for this.
17046 + */
17047 +.section .idt,"a",@progbits
17048 +ENTRY(idt_table)
17049 + .fill 256,8,0
17050
17051 /*
17052 * This starts the data section.
17053 */
17054 #ifdef CONFIG_X86_PAE
17055 -__PAGE_ALIGNED_DATA
17056 - /* Page-aligned for the benefit of paravirt? */
17057 - .align PAGE_SIZE
17058 +.section .initial_page_table,"a",@progbits
17059 ENTRY(initial_page_table)
17060 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17061 # if KPMDS == 3
17062 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17063 # error "Kernel PMDs should be 1, 2 or 3"
17064 # endif
17065 .align PAGE_SIZE /* needs to be page-sized too */
17066 +
17067 +#ifdef CONFIG_PAX_PER_CPU_PGD
17068 +ENTRY(cpu_pgd)
17069 + .rept NR_CPUS
17070 + .fill 4,8,0
17071 + .endr
17072 +#endif
17073 +
17074 #endif
17075
17076 .data
17077 .balign 4
17078 ENTRY(stack_start)
17079 - .long init_thread_union+THREAD_SIZE
17080 + .long init_thread_union+THREAD_SIZE-8
17081
17082 +ready: .byte 0
17083 +
17084 +.section .rodata,"a",@progbits
17085 early_recursion_flag:
17086 .long 0
17087
17088 -ready: .byte 0
17089 -
17090 int_msg:
17091 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17092
17093 @@ -707,7 +811,7 @@ fault_msg:
17094 .word 0 # 32 bit align gdt_desc.address
17095 boot_gdt_descr:
17096 .word __BOOT_DS+7
17097 - .long boot_gdt - __PAGE_OFFSET
17098 + .long pa(boot_gdt)
17099
17100 .word 0 # 32-bit align idt_desc.address
17101 idt_descr:
17102 @@ -718,7 +822,7 @@ idt_descr:
17103 .word 0 # 32 bit align gdt_desc.address
17104 ENTRY(early_gdt_descr)
17105 .word GDT_ENTRIES*8-1
17106 - .long gdt_page /* Overwritten for secondary CPUs */
17107 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17108
17109 /*
17110 * The boot_gdt must mirror the equivalent in setup.S and is
17111 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17112 .align L1_CACHE_BYTES
17113 ENTRY(boot_gdt)
17114 .fill GDT_ENTRY_BOOT_CS,8,0
17115 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17116 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17117 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17118 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17119 +
17120 + .align PAGE_SIZE_asm
17121 +ENTRY(cpu_gdt_table)
17122 + .rept NR_CPUS
17123 + .quad 0x0000000000000000 /* NULL descriptor */
17124 + .quad 0x0000000000000000 /* 0x0b reserved */
17125 + .quad 0x0000000000000000 /* 0x13 reserved */
17126 + .quad 0x0000000000000000 /* 0x1b reserved */
17127 +
17128 +#ifdef CONFIG_PAX_KERNEXEC
17129 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17130 +#else
17131 + .quad 0x0000000000000000 /* 0x20 unused */
17132 +#endif
17133 +
17134 + .quad 0x0000000000000000 /* 0x28 unused */
17135 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17136 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17137 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17138 + .quad 0x0000000000000000 /* 0x4b reserved */
17139 + .quad 0x0000000000000000 /* 0x53 reserved */
17140 + .quad 0x0000000000000000 /* 0x5b reserved */
17141 +
17142 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17143 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17144 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17145 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17146 +
17147 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17148 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17149 +
17150 + /*
17151 + * Segments used for calling PnP BIOS have byte granularity.
17152 + * The code segments and data segments have fixed 64k limits,
17153 + * the transfer segment sizes are set at run time.
17154 + */
17155 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17156 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17157 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17158 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17159 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17160 +
17161 + /*
17162 + * The APM segments have byte granularity and their bases
17163 + * are set at run time. All have 64k limits.
17164 + */
17165 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17166 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17167 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17168 +
17169 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17170 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17171 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17172 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17173 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17174 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17175 +
17176 + /* Be sure this is zeroed to avoid false validations in Xen */
17177 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17178 + .endr
17179 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17180 index 40f4eb3..6d24d9d 100644
17181 --- a/arch/x86/kernel/head_64.S
17182 +++ b/arch/x86/kernel/head_64.S
17183 @@ -19,6 +19,8 @@
17184 #include <asm/cache.h>
17185 #include <asm/processor-flags.h>
17186 #include <asm/percpu.h>
17187 +#include <asm/cpufeature.h>
17188 +#include <asm/alternative-asm.h>
17189
17190 #ifdef CONFIG_PARAVIRT
17191 #include <asm/asm-offsets.h>
17192 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17193 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17194 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17195 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17196 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17197 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17198 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17199 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17200 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17201 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17202
17203 .text
17204 __HEAD
17205 @@ -85,35 +93,23 @@ startup_64:
17206 */
17207 addq %rbp, init_level4_pgt + 0(%rip)
17208 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17209 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17210 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17211 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17212 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17213
17214 addq %rbp, level3_ident_pgt + 0(%rip)
17215 +#ifndef CONFIG_XEN
17216 + addq %rbp, level3_ident_pgt + 8(%rip)
17217 +#endif
17218
17219 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17220 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17221 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17222 +
17223 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17224 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17225
17226 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17227 -
17228 - /* Add an Identity mapping if I am above 1G */
17229 - leaq _text(%rip), %rdi
17230 - andq $PMD_PAGE_MASK, %rdi
17231 -
17232 - movq %rdi, %rax
17233 - shrq $PUD_SHIFT, %rax
17234 - andq $(PTRS_PER_PUD - 1), %rax
17235 - jz ident_complete
17236 -
17237 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17238 - leaq level3_ident_pgt(%rip), %rbx
17239 - movq %rdx, 0(%rbx, %rax, 8)
17240 -
17241 - movq %rdi, %rax
17242 - shrq $PMD_SHIFT, %rax
17243 - andq $(PTRS_PER_PMD - 1), %rax
17244 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17245 - leaq level2_spare_pgt(%rip), %rbx
17246 - movq %rdx, 0(%rbx, %rax, 8)
17247 -ident_complete:
17248 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17249
17250 /*
17251 * Fixup the kernel text+data virtual addresses. Note that
17252 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17253 * after the boot processor executes this code.
17254 */
17255
17256 - /* Enable PAE mode and PGE */
17257 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17258 + /* Enable PAE mode and PSE/PGE */
17259 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17260 movq %rax, %cr4
17261
17262 /* Setup early boot stage 4 level pagetables. */
17263 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17264 movl $MSR_EFER, %ecx
17265 rdmsr
17266 btsl $_EFER_SCE, %eax /* Enable System Call */
17267 - btl $20,%edi /* No Execute supported? */
17268 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17269 jnc 1f
17270 btsl $_EFER_NX, %eax
17271 + leaq init_level4_pgt(%rip), %rdi
17272 +#ifndef CONFIG_EFI
17273 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17274 +#endif
17275 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17276 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17277 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17278 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17279 1: wrmsr /* Make changes effective */
17280
17281 /* Setup cr0 */
17282 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17283 * jump. In addition we need to ensure %cs is set so we make this
17284 * a far return.
17285 */
17286 + pax_set_fptr_mask
17287 movq initial_code(%rip),%rax
17288 pushq $0 # fake return address to stop unwinder
17289 pushq $__KERNEL_CS # set correct cs
17290 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17291 bad_address:
17292 jmp bad_address
17293
17294 - .section ".init.text","ax"
17295 + __INIT
17296 #ifdef CONFIG_EARLY_PRINTK
17297 .globl early_idt_handlers
17298 early_idt_handlers:
17299 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17300 #endif /* EARLY_PRINTK */
17301 1: hlt
17302 jmp 1b
17303 + .previous
17304
17305 #ifdef CONFIG_EARLY_PRINTK
17306 + __INITDATA
17307 early_recursion_flag:
17308 .long 0
17309 + .previous
17310
17311 + .section .rodata,"a",@progbits
17312 early_idt_msg:
17313 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17314 early_idt_ripmsg:
17315 .asciz "RIP %s\n"
17316 + .previous
17317 #endif /* CONFIG_EARLY_PRINTK */
17318 - .previous
17319
17320 + .section .rodata,"a",@progbits
17321 #define NEXT_PAGE(name) \
17322 .balign PAGE_SIZE; \
17323 ENTRY(name)
17324 @@ -338,7 +348,6 @@ ENTRY(name)
17325 i = i + 1 ; \
17326 .endr
17327
17328 - .data
17329 /*
17330 * This default setting generates an ident mapping at address 0x100000
17331 * and a mapping for the kernel that precisely maps virtual address
17332 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17333 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17334 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17335 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17336 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17337 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17338 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17339 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17340 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17341 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17342 .org init_level4_pgt + L4_START_KERNEL*8, 0
17343 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17344 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17345
17346 +#ifdef CONFIG_PAX_PER_CPU_PGD
17347 +NEXT_PAGE(cpu_pgd)
17348 + .rept NR_CPUS
17349 + .fill 512,8,0
17350 + .endr
17351 +#endif
17352 +
17353 NEXT_PAGE(level3_ident_pgt)
17354 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17355 +#ifdef CONFIG_XEN
17356 .fill 511,8,0
17357 +#else
17358 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17359 + .fill 510,8,0
17360 +#endif
17361 +
17362 +NEXT_PAGE(level3_vmalloc_start_pgt)
17363 + .fill 512,8,0
17364 +
17365 +NEXT_PAGE(level3_vmalloc_end_pgt)
17366 + .fill 512,8,0
17367 +
17368 +NEXT_PAGE(level3_vmemmap_pgt)
17369 + .fill L3_VMEMMAP_START,8,0
17370 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17371
17372 NEXT_PAGE(level3_kernel_pgt)
17373 .fill L3_START_KERNEL,8,0
17374 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17375 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17376 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17377
17378 +NEXT_PAGE(level2_vmemmap_pgt)
17379 + .fill 512,8,0
17380 +
17381 NEXT_PAGE(level2_fixmap_pgt)
17382 - .fill 506,8,0
17383 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17384 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17385 - .fill 5,8,0
17386 + .fill 507,8,0
17387 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17388 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17389 + .fill 4,8,0
17390
17391 -NEXT_PAGE(level1_fixmap_pgt)
17392 +NEXT_PAGE(level1_vsyscall_pgt)
17393 .fill 512,8,0
17394
17395 -NEXT_PAGE(level2_ident_pgt)
17396 - /* Since I easily can, map the first 1G.
17397 + /* Since I easily can, map the first 2G.
17398 * Don't set NX because code runs from these pages.
17399 */
17400 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17401 +NEXT_PAGE(level2_ident_pgt)
17402 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17403
17404 NEXT_PAGE(level2_kernel_pgt)
17405 /*
17406 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17407 * If you want to increase this then increase MODULES_VADDR
17408 * too.)
17409 */
17410 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17411 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17412 -
17413 -NEXT_PAGE(level2_spare_pgt)
17414 - .fill 512, 8, 0
17415 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17416
17417 #undef PMDS
17418 #undef NEXT_PAGE
17419
17420 - .data
17421 + .align PAGE_SIZE
17422 +ENTRY(cpu_gdt_table)
17423 + .rept NR_CPUS
17424 + .quad 0x0000000000000000 /* NULL descriptor */
17425 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17426 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17427 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17428 + .quad 0x00cffb000000ffff /* __USER32_CS */
17429 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17430 + .quad 0x00affb000000ffff /* __USER_CS */
17431 +
17432 +#ifdef CONFIG_PAX_KERNEXEC
17433 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17434 +#else
17435 + .quad 0x0 /* unused */
17436 +#endif
17437 +
17438 + .quad 0,0 /* TSS */
17439 + .quad 0,0 /* LDT */
17440 + .quad 0,0,0 /* three TLS descriptors */
17441 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17442 + /* asm/segment.h:GDT_ENTRIES must match this */
17443 +
17444 + /* zero the remaining page */
17445 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17446 + .endr
17447 +
17448 .align 16
17449 .globl early_gdt_descr
17450 early_gdt_descr:
17451 .word GDT_ENTRIES*8-1
17452 early_gdt_descr_base:
17453 - .quad INIT_PER_CPU_VAR(gdt_page)
17454 + .quad cpu_gdt_table
17455
17456 ENTRY(phys_base)
17457 /* This must match the first entry in level2_kernel_pgt */
17458 .quad 0x0000000000000000
17459
17460 #include "../../x86/xen/xen-head.S"
17461 -
17462 - .section .bss, "aw", @nobits
17463 +
17464 + .section .rodata,"a",@progbits
17465 .align L1_CACHE_BYTES
17466 ENTRY(idt_table)
17467 - .skip IDT_ENTRIES * 16
17468 + .fill 512,8,0
17469
17470 .align L1_CACHE_BYTES
17471 ENTRY(nmi_idt_table)
17472 - .skip IDT_ENTRIES * 16
17473 + .fill 512,8,0
17474
17475 __PAGE_ALIGNED_BSS
17476 .align PAGE_SIZE
17477 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17478 index 9c3bd4a..e1d9b35 100644
17479 --- a/arch/x86/kernel/i386_ksyms_32.c
17480 +++ b/arch/x86/kernel/i386_ksyms_32.c
17481 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17482 EXPORT_SYMBOL(cmpxchg8b_emu);
17483 #endif
17484
17485 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17486 +
17487 /* Networking helper routines. */
17488 EXPORT_SYMBOL(csum_partial_copy_generic);
17489 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17490 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17491
17492 EXPORT_SYMBOL(__get_user_1);
17493 EXPORT_SYMBOL(__get_user_2);
17494 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17495
17496 EXPORT_SYMBOL(csum_partial);
17497 EXPORT_SYMBOL(empty_zero_page);
17498 +
17499 +#ifdef CONFIG_PAX_KERNEXEC
17500 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17501 +#endif
17502 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17503 index 2d6e649..df6e1af 100644
17504 --- a/arch/x86/kernel/i387.c
17505 +++ b/arch/x86/kernel/i387.c
17506 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17507 static inline bool interrupted_user_mode(void)
17508 {
17509 struct pt_regs *regs = get_irq_regs();
17510 - return regs && user_mode_vm(regs);
17511 + return regs && user_mode(regs);
17512 }
17513
17514 /*
17515 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17516 index 36d1853..bf25736 100644
17517 --- a/arch/x86/kernel/i8259.c
17518 +++ b/arch/x86/kernel/i8259.c
17519 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17520 "spurious 8259A interrupt: IRQ%d.\n", irq);
17521 spurious_irq_mask |= irqmask;
17522 }
17523 - atomic_inc(&irq_err_count);
17524 + atomic_inc_unchecked(&irq_err_count);
17525 /*
17526 * Theoretically we do not have to handle this IRQ,
17527 * but in Linux this does not cause problems and is
17528 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17529 index 43e9ccf..44ccf6f 100644
17530 --- a/arch/x86/kernel/init_task.c
17531 +++ b/arch/x86/kernel/init_task.c
17532 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17533 * way process stacks are handled. This is done by having a special
17534 * "init_task" linker map entry..
17535 */
17536 -union thread_union init_thread_union __init_task_data =
17537 - { INIT_THREAD_INFO(init_task) };
17538 +union thread_union init_thread_union __init_task_data;
17539
17540 /*
17541 * Initial task structure.
17542 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17543 * section. Since TSS's are completely CPU-local, we want them
17544 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17545 */
17546 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17547 -
17548 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17549 +EXPORT_SYMBOL(init_tss);
17550 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17551 index 8c96897..be66bfa 100644
17552 --- a/arch/x86/kernel/ioport.c
17553 +++ b/arch/x86/kernel/ioport.c
17554 @@ -6,6 +6,7 @@
17555 #include <linux/sched.h>
17556 #include <linux/kernel.h>
17557 #include <linux/capability.h>
17558 +#include <linux/security.h>
17559 #include <linux/errno.h>
17560 #include <linux/types.h>
17561 #include <linux/ioport.h>
17562 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17563
17564 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17565 return -EINVAL;
17566 +#ifdef CONFIG_GRKERNSEC_IO
17567 + if (turn_on && grsec_disable_privio) {
17568 + gr_handle_ioperm();
17569 + return -EPERM;
17570 + }
17571 +#endif
17572 if (turn_on && !capable(CAP_SYS_RAWIO))
17573 return -EPERM;
17574
17575 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17576 * because the ->io_bitmap_max value must match the bitmap
17577 * contents:
17578 */
17579 - tss = &per_cpu(init_tss, get_cpu());
17580 + tss = init_tss + get_cpu();
17581
17582 if (turn_on)
17583 bitmap_clear(t->io_bitmap_ptr, from, num);
17584 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17585 return -EINVAL;
17586 /* Trying to gain more privileges? */
17587 if (level > old) {
17588 +#ifdef CONFIG_GRKERNSEC_IO
17589 + if (grsec_disable_privio) {
17590 + gr_handle_iopl();
17591 + return -EPERM;
17592 + }
17593 +#endif
17594 if (!capable(CAP_SYS_RAWIO))
17595 return -EPERM;
17596 }
17597 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17598 index 3dafc60..aa8e9c4 100644
17599 --- a/arch/x86/kernel/irq.c
17600 +++ b/arch/x86/kernel/irq.c
17601 @@ -18,7 +18,7 @@
17602 #include <asm/mce.h>
17603 #include <asm/hw_irq.h>
17604
17605 -atomic_t irq_err_count;
17606 +atomic_unchecked_t irq_err_count;
17607
17608 /* Function pointer for generic interrupt vector handling */
17609 void (*x86_platform_ipi_callback)(void) = NULL;
17610 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17611 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17612 seq_printf(p, " Machine check polls\n");
17613 #endif
17614 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17615 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17616 #if defined(CONFIG_X86_IO_APIC)
17617 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17618 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17619 #endif
17620 return 0;
17621 }
17622 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17623
17624 u64 arch_irq_stat(void)
17625 {
17626 - u64 sum = atomic_read(&irq_err_count);
17627 + u64 sum = atomic_read_unchecked(&irq_err_count);
17628
17629 #ifdef CONFIG_X86_IO_APIC
17630 - sum += atomic_read(&irq_mis_count);
17631 + sum += atomic_read_unchecked(&irq_mis_count);
17632 #endif
17633 return sum;
17634 }
17635 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17636 index 58b7f27..e112d08 100644
17637 --- a/arch/x86/kernel/irq_32.c
17638 +++ b/arch/x86/kernel/irq_32.c
17639 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17640 __asm__ __volatile__("andl %%esp,%0" :
17641 "=r" (sp) : "0" (THREAD_SIZE - 1));
17642
17643 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17644 + return sp < STACK_WARN;
17645 }
17646
17647 static void print_stack_overflow(void)
17648 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17649 * per-CPU IRQ handling contexts (thread information and stack)
17650 */
17651 union irq_ctx {
17652 - struct thread_info tinfo;
17653 - u32 stack[THREAD_SIZE/sizeof(u32)];
17654 + unsigned long previous_esp;
17655 + u32 stack[THREAD_SIZE/sizeof(u32)];
17656 } __attribute__((aligned(THREAD_SIZE)));
17657
17658 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17659 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17660 static inline int
17661 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17662 {
17663 - union irq_ctx *curctx, *irqctx;
17664 + union irq_ctx *irqctx;
17665 u32 *isp, arg1, arg2;
17666
17667 - curctx = (union irq_ctx *) current_thread_info();
17668 irqctx = __this_cpu_read(hardirq_ctx);
17669
17670 /*
17671 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17672 * handler) we can't do that and just have to keep using the
17673 * current stack (which is the irq stack already after all)
17674 */
17675 - if (unlikely(curctx == irqctx))
17676 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17677 return 0;
17678
17679 /* build the stack frame on the IRQ stack */
17680 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17681 - irqctx->tinfo.task = curctx->tinfo.task;
17682 - irqctx->tinfo.previous_esp = current_stack_pointer;
17683 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17684 + irqctx->previous_esp = current_stack_pointer;
17685
17686 - /* Copy the preempt_count so that the [soft]irq checks work. */
17687 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17689 + __set_fs(MAKE_MM_SEG(0));
17690 +#endif
17691
17692 if (unlikely(overflow))
17693 call_on_stack(print_stack_overflow, isp);
17694 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17695 : "0" (irq), "1" (desc), "2" (isp),
17696 "D" (desc->handle_irq)
17697 : "memory", "cc", "ecx");
17698 +
17699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17700 + __set_fs(current_thread_info()->addr_limit);
17701 +#endif
17702 +
17703 return 1;
17704 }
17705
17706 @@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17707 */
17708 void __cpuinit irq_ctx_init(int cpu)
17709 {
17710 - union irq_ctx *irqctx;
17711 -
17712 if (per_cpu(hardirq_ctx, cpu))
17713 return;
17714
17715 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17716 - THREAD_FLAGS,
17717 - THREAD_ORDER));
17718 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17719 - irqctx->tinfo.cpu = cpu;
17720 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17721 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17722 -
17723 - per_cpu(hardirq_ctx, cpu) = irqctx;
17724 -
17725 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17726 - THREAD_FLAGS,
17727 - THREAD_ORDER));
17728 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17729 - irqctx->tinfo.cpu = cpu;
17730 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17731 -
17732 - per_cpu(softirq_ctx, cpu) = irqctx;
17733 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17734 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17735
17736 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17737 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17738 @@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17739 asmlinkage void do_softirq(void)
17740 {
17741 unsigned long flags;
17742 - struct thread_info *curctx;
17743 union irq_ctx *irqctx;
17744 u32 *isp;
17745
17746 @@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17747 local_irq_save(flags);
17748
17749 if (local_softirq_pending()) {
17750 - curctx = current_thread_info();
17751 irqctx = __this_cpu_read(softirq_ctx);
17752 - irqctx->tinfo.task = curctx->task;
17753 - irqctx->tinfo.previous_esp = current_stack_pointer;
17754 + irqctx->previous_esp = current_stack_pointer;
17755
17756 /* build the stack frame on the softirq stack */
17757 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17758 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17759 +
17760 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17761 + __set_fs(MAKE_MM_SEG(0));
17762 +#endif
17763
17764 call_on_stack(__do_softirq, isp);
17765 +
17766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17767 + __set_fs(current_thread_info()->addr_limit);
17768 +#endif
17769 +
17770 /*
17771 * Shouldn't happen, we returned above if in_interrupt():
17772 */
17773 @@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17774 if (unlikely(!desc))
17775 return false;
17776
17777 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17778 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17779 if (unlikely(overflow))
17780 print_stack_overflow();
17781 desc->handle_irq(irq, desc);
17782 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17783 index d04d3ec..ea4b374 100644
17784 --- a/arch/x86/kernel/irq_64.c
17785 +++ b/arch/x86/kernel/irq_64.c
17786 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17787 u64 estack_top, estack_bottom;
17788 u64 curbase = (u64)task_stack_page(current);
17789
17790 - if (user_mode_vm(regs))
17791 + if (user_mode(regs))
17792 return;
17793
17794 if (regs->sp >= curbase + sizeof(struct thread_info) +
17795 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17796 index 1d5d31e..ab846ed 100644
17797 --- a/arch/x86/kernel/kdebugfs.c
17798 +++ b/arch/x86/kernel/kdebugfs.c
17799 @@ -28,6 +28,8 @@ struct setup_data_node {
17800 };
17801
17802 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17803 + size_t count, loff_t *ppos) __size_overflow(3);
17804 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17805 size_t count, loff_t *ppos)
17806 {
17807 struct setup_data_node *node = file->private_data;
17808 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17809 index 8bfb614..2b3b35f 100644
17810 --- a/arch/x86/kernel/kgdb.c
17811 +++ b/arch/x86/kernel/kgdb.c
17812 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17813 #ifdef CONFIG_X86_32
17814 switch (regno) {
17815 case GDB_SS:
17816 - if (!user_mode_vm(regs))
17817 + if (!user_mode(regs))
17818 *(unsigned long *)mem = __KERNEL_DS;
17819 break;
17820 case GDB_SP:
17821 - if (!user_mode_vm(regs))
17822 + if (!user_mode(regs))
17823 *(unsigned long *)mem = kernel_stack_pointer(regs);
17824 break;
17825 case GDB_GS:
17826 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17827 case 'k':
17828 /* clear the trace bit */
17829 linux_regs->flags &= ~X86_EFLAGS_TF;
17830 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17831 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17832
17833 /* set the trace bit if we're stepping */
17834 if (remcomInBuffer[0] == 's') {
17835 linux_regs->flags |= X86_EFLAGS_TF;
17836 - atomic_set(&kgdb_cpu_doing_single_step,
17837 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17838 raw_smp_processor_id());
17839 }
17840
17841 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17842
17843 switch (cmd) {
17844 case DIE_DEBUG:
17845 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17846 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17847 if (user_mode(regs))
17848 return single_step_cont(regs, args);
17849 break;
17850 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17851 index c5e410e..da6aaf9 100644
17852 --- a/arch/x86/kernel/kprobes-opt.c
17853 +++ b/arch/x86/kernel/kprobes-opt.c
17854 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17855 * Verify if the address gap is in 2GB range, because this uses
17856 * a relative jump.
17857 */
17858 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17859 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17860 if (abs(rel) > 0x7fffffff)
17861 return -ERANGE;
17862
17863 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17864 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17865
17866 /* Set probe function call */
17867 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17868 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17869
17870 /* Set returning jmp instruction at the tail of out-of-line buffer */
17871 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17872 - (u8 *)op->kp.addr + op->optinsn.size);
17873 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17874
17875 flush_icache_range((unsigned long) buf,
17876 (unsigned long) buf + TMPL_END_IDX +
17877 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17878 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17879
17880 /* Backup instructions which will be replaced by jump address */
17881 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17882 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17883 RELATIVE_ADDR_SIZE);
17884
17885 insn_buf[0] = RELATIVEJUMP_OPCODE;
17886 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17887 index e213fc8..d783ba4 100644
17888 --- a/arch/x86/kernel/kprobes.c
17889 +++ b/arch/x86/kernel/kprobes.c
17890 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17891 } __attribute__((packed)) *insn;
17892
17893 insn = (struct __arch_relative_insn *)from;
17894 +
17895 + pax_open_kernel();
17896 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17897 insn->op = op;
17898 + pax_close_kernel();
17899 }
17900
17901 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17902 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17903 kprobe_opcode_t opcode;
17904 kprobe_opcode_t *orig_opcodes = opcodes;
17905
17906 - if (search_exception_tables((unsigned long)opcodes))
17907 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17908 return 0; /* Page fault may occur on this address. */
17909
17910 retry:
17911 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17912 /* Another subsystem puts a breakpoint, failed to recover */
17913 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17914 return 0;
17915 + pax_open_kernel();
17916 memcpy(dest, insn.kaddr, insn.length);
17917 + pax_close_kernel();
17918
17919 #ifdef CONFIG_X86_64
17920 if (insn_rip_relative(&insn)) {
17921 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17922 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17923 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17924 disp = (u8 *) dest + insn_offset_displacement(&insn);
17925 + pax_open_kernel();
17926 *(s32 *) disp = (s32) newdisp;
17927 + pax_close_kernel();
17928 }
17929 #endif
17930 return insn.length;
17931 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17932 * nor set current_kprobe, because it doesn't use single
17933 * stepping.
17934 */
17935 - regs->ip = (unsigned long)p->ainsn.insn;
17936 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17937 preempt_enable_no_resched();
17938 return;
17939 }
17940 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17941 if (p->opcode == BREAKPOINT_INSTRUCTION)
17942 regs->ip = (unsigned long)p->addr;
17943 else
17944 - regs->ip = (unsigned long)p->ainsn.insn;
17945 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17946 }
17947
17948 /*
17949 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17950 setup_singlestep(p, regs, kcb, 0);
17951 return 1;
17952 }
17953 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17954 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17955 /*
17956 * The breakpoint instruction was removed right
17957 * after we hit it. Another cpu has removed
17958 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17959 " movq %rax, 152(%rsp)\n"
17960 RESTORE_REGS_STRING
17961 " popfq\n"
17962 +#ifdef KERNEXEC_PLUGIN
17963 + " btsq $63,(%rsp)\n"
17964 +#endif
17965 #else
17966 " pushf\n"
17967 SAVE_REGS_STRING
17968 @@ -765,7 +775,7 @@ static void __kprobes
17969 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17970 {
17971 unsigned long *tos = stack_addr(regs);
17972 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17973 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17974 unsigned long orig_ip = (unsigned long)p->addr;
17975 kprobe_opcode_t *insn = p->ainsn.insn;
17976
17977 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17978 struct die_args *args = data;
17979 int ret = NOTIFY_DONE;
17980
17981 - if (args->regs && user_mode_vm(args->regs))
17982 + if (args->regs && user_mode(args->regs))
17983 return ret;
17984
17985 switch (val) {
17986 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17987 index ebc9873..1b9724b 100644
17988 --- a/arch/x86/kernel/ldt.c
17989 +++ b/arch/x86/kernel/ldt.c
17990 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17991 if (reload) {
17992 #ifdef CONFIG_SMP
17993 preempt_disable();
17994 - load_LDT(pc);
17995 + load_LDT_nolock(pc);
17996 if (!cpumask_equal(mm_cpumask(current->mm),
17997 cpumask_of(smp_processor_id())))
17998 smp_call_function(flush_ldt, current->mm, 1);
17999 preempt_enable();
18000 #else
18001 - load_LDT(pc);
18002 + load_LDT_nolock(pc);
18003 #endif
18004 }
18005 if (oldsize) {
18006 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18007 return err;
18008
18009 for (i = 0; i < old->size; i++)
18010 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18011 + write_ldt_entry(new->ldt, i, old->ldt + i);
18012 return 0;
18013 }
18014
18015 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18016 retval = copy_ldt(&mm->context, &old_mm->context);
18017 mutex_unlock(&old_mm->context.lock);
18018 }
18019 +
18020 + if (tsk == current) {
18021 + mm->context.vdso = 0;
18022 +
18023 +#ifdef CONFIG_X86_32
18024 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18025 + mm->context.user_cs_base = 0UL;
18026 + mm->context.user_cs_limit = ~0UL;
18027 +
18028 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18029 + cpus_clear(mm->context.cpu_user_cs_mask);
18030 +#endif
18031 +
18032 +#endif
18033 +#endif
18034 +
18035 + }
18036 +
18037 return retval;
18038 }
18039
18040 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18041 }
18042 }
18043
18044 +#ifdef CONFIG_PAX_SEGMEXEC
18045 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18046 + error = -EINVAL;
18047 + goto out_unlock;
18048 + }
18049 +#endif
18050 +
18051 fill_ldt(&ldt, &ldt_info);
18052 if (oldmode)
18053 ldt.avl = 0;
18054 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18055 index 5b19e4d..6476a76 100644
18056 --- a/arch/x86/kernel/machine_kexec_32.c
18057 +++ b/arch/x86/kernel/machine_kexec_32.c
18058 @@ -26,7 +26,7 @@
18059 #include <asm/cacheflush.h>
18060 #include <asm/debugreg.h>
18061
18062 -static void set_idt(void *newidt, __u16 limit)
18063 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18064 {
18065 struct desc_ptr curidt;
18066
18067 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18068 }
18069
18070
18071 -static void set_gdt(void *newgdt, __u16 limit)
18072 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18073 {
18074 struct desc_ptr curgdt;
18075
18076 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18077 }
18078
18079 control_page = page_address(image->control_code_page);
18080 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18081 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18082
18083 relocate_kernel_ptr = control_page;
18084 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18085 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18086 index 0327e2b..e43737b 100644
18087 --- a/arch/x86/kernel/microcode_intel.c
18088 +++ b/arch/x86/kernel/microcode_intel.c
18089 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18090
18091 static int get_ucode_user(void *to, const void *from, size_t n)
18092 {
18093 - return copy_from_user(to, from, n);
18094 + return copy_from_user(to, (const void __force_user *)from, n);
18095 }
18096
18097 static enum ucode_state
18098 request_microcode_user(int cpu, const void __user *buf, size_t size)
18099 {
18100 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18101 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18102 }
18103
18104 static void microcode_fini_cpu(int cpu)
18105 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18106 index f21fd94..61565cd 100644
18107 --- a/arch/x86/kernel/module.c
18108 +++ b/arch/x86/kernel/module.c
18109 @@ -35,15 +35,60 @@
18110 #define DEBUGP(fmt...)
18111 #endif
18112
18113 -void *module_alloc(unsigned long size)
18114 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18115 {
18116 - if (PAGE_ALIGN(size) > MODULES_LEN)
18117 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18118 return NULL;
18119 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18120 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18121 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18122 -1, __builtin_return_address(0));
18123 }
18124
18125 +void *module_alloc(unsigned long size)
18126 +{
18127 +
18128 +#ifdef CONFIG_PAX_KERNEXEC
18129 + return __module_alloc(size, PAGE_KERNEL);
18130 +#else
18131 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18132 +#endif
18133 +
18134 +}
18135 +
18136 +#ifdef CONFIG_PAX_KERNEXEC
18137 +#ifdef CONFIG_X86_32
18138 +void *module_alloc_exec(unsigned long size)
18139 +{
18140 + struct vm_struct *area;
18141 +
18142 + if (size == 0)
18143 + return NULL;
18144 +
18145 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18146 + return area ? area->addr : NULL;
18147 +}
18148 +EXPORT_SYMBOL(module_alloc_exec);
18149 +
18150 +void module_free_exec(struct module *mod, void *module_region)
18151 +{
18152 + vunmap(module_region);
18153 +}
18154 +EXPORT_SYMBOL(module_free_exec);
18155 +#else
18156 +void module_free_exec(struct module *mod, void *module_region)
18157 +{
18158 + module_free(mod, module_region);
18159 +}
18160 +EXPORT_SYMBOL(module_free_exec);
18161 +
18162 +void *module_alloc_exec(unsigned long size)
18163 +{
18164 + return __module_alloc(size, PAGE_KERNEL_RX);
18165 +}
18166 +EXPORT_SYMBOL(module_alloc_exec);
18167 +#endif
18168 +#endif
18169 +
18170 #ifdef CONFIG_X86_32
18171 int apply_relocate(Elf32_Shdr *sechdrs,
18172 const char *strtab,
18173 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18174 unsigned int i;
18175 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18176 Elf32_Sym *sym;
18177 - uint32_t *location;
18178 + uint32_t *plocation, location;
18179
18180 DEBUGP("Applying relocate section %u to %u\n", relsec,
18181 sechdrs[relsec].sh_info);
18182 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18183 /* This is where to make the change */
18184 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18185 - + rel[i].r_offset;
18186 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18187 + location = (uint32_t)plocation;
18188 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18189 + plocation = ktla_ktva((void *)plocation);
18190 /* This is the symbol it is referring to. Note that all
18191 undefined symbols have been resolved. */
18192 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18193 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18194 switch (ELF32_R_TYPE(rel[i].r_info)) {
18195 case R_386_32:
18196 /* We add the value into the location given */
18197 - *location += sym->st_value;
18198 + pax_open_kernel();
18199 + *plocation += sym->st_value;
18200 + pax_close_kernel();
18201 break;
18202 case R_386_PC32:
18203 /* Add the value, subtract its postition */
18204 - *location += sym->st_value - (uint32_t)location;
18205 + pax_open_kernel();
18206 + *plocation += sym->st_value - location;
18207 + pax_close_kernel();
18208 break;
18209 default:
18210 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18211 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18212 case R_X86_64_NONE:
18213 break;
18214 case R_X86_64_64:
18215 + pax_open_kernel();
18216 *(u64 *)loc = val;
18217 + pax_close_kernel();
18218 break;
18219 case R_X86_64_32:
18220 + pax_open_kernel();
18221 *(u32 *)loc = val;
18222 + pax_close_kernel();
18223 if (val != *(u32 *)loc)
18224 goto overflow;
18225 break;
18226 case R_X86_64_32S:
18227 + pax_open_kernel();
18228 *(s32 *)loc = val;
18229 + pax_close_kernel();
18230 if ((s64)val != *(s32 *)loc)
18231 goto overflow;
18232 break;
18233 case R_X86_64_PC32:
18234 val -= (u64)loc;
18235 + pax_open_kernel();
18236 *(u32 *)loc = val;
18237 + pax_close_kernel();
18238 +
18239 #if 0
18240 if ((s64)val != *(s32 *)loc)
18241 goto overflow;
18242 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18243 index 32856fa..ce95eaa 100644
18244 --- a/arch/x86/kernel/nmi.c
18245 +++ b/arch/x86/kernel/nmi.c
18246 @@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18247 dotraplinkage notrace __kprobes void
18248 do_nmi(struct pt_regs *regs, long error_code)
18249 {
18250 +
18251 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18252 + if (!user_mode(regs)) {
18253 + unsigned long cs = regs->cs & 0xFFFF;
18254 + unsigned long ip = ktva_ktla(regs->ip);
18255 +
18256 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18257 + regs->ip = ip;
18258 + }
18259 +#endif
18260 +
18261 nmi_nesting_preprocess(regs);
18262
18263 nmi_enter();
18264 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18265 index 676b8c7..870ba04 100644
18266 --- a/arch/x86/kernel/paravirt-spinlocks.c
18267 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18268 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18269 arch_spin_lock(lock);
18270 }
18271
18272 -struct pv_lock_ops pv_lock_ops = {
18273 +struct pv_lock_ops pv_lock_ops __read_only = {
18274 #ifdef CONFIG_SMP
18275 .spin_is_locked = __ticket_spin_is_locked,
18276 .spin_is_contended = __ticket_spin_is_contended,
18277 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18278 index ab13760..01218e0 100644
18279 --- a/arch/x86/kernel/paravirt.c
18280 +++ b/arch/x86/kernel/paravirt.c
18281 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18282 {
18283 return x;
18284 }
18285 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18286 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18287 +#endif
18288
18289 void __init default_banner(void)
18290 {
18291 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18292 if (opfunc == NULL)
18293 /* If there's no function, patch it with a ud2a (BUG) */
18294 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18295 - else if (opfunc == _paravirt_nop)
18296 + else if (opfunc == (void *)_paravirt_nop)
18297 /* If the operation is a nop, then nop the callsite */
18298 ret = paravirt_patch_nop();
18299
18300 /* identity functions just return their single argument */
18301 - else if (opfunc == _paravirt_ident_32)
18302 + else if (opfunc == (void *)_paravirt_ident_32)
18303 ret = paravirt_patch_ident_32(insnbuf, len);
18304 - else if (opfunc == _paravirt_ident_64)
18305 + else if (opfunc == (void *)_paravirt_ident_64)
18306 ret = paravirt_patch_ident_64(insnbuf, len);
18307 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18308 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18309 + ret = paravirt_patch_ident_64(insnbuf, len);
18310 +#endif
18311
18312 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18313 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18314 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18315 if (insn_len > len || start == NULL)
18316 insn_len = len;
18317 else
18318 - memcpy(insnbuf, start, insn_len);
18319 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18320
18321 return insn_len;
18322 }
18323 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18324 preempt_enable();
18325 }
18326
18327 -struct pv_info pv_info = {
18328 +struct pv_info pv_info __read_only = {
18329 .name = "bare hardware",
18330 .paravirt_enabled = 0,
18331 .kernel_rpl = 0,
18332 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18333 #endif
18334 };
18335
18336 -struct pv_init_ops pv_init_ops = {
18337 +struct pv_init_ops pv_init_ops __read_only = {
18338 .patch = native_patch,
18339 };
18340
18341 -struct pv_time_ops pv_time_ops = {
18342 +struct pv_time_ops pv_time_ops __read_only = {
18343 .sched_clock = native_sched_clock,
18344 .steal_clock = native_steal_clock,
18345 };
18346
18347 -struct pv_irq_ops pv_irq_ops = {
18348 +struct pv_irq_ops pv_irq_ops __read_only = {
18349 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18350 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18351 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18352 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18353 #endif
18354 };
18355
18356 -struct pv_cpu_ops pv_cpu_ops = {
18357 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18358 .cpuid = native_cpuid,
18359 .get_debugreg = native_get_debugreg,
18360 .set_debugreg = native_set_debugreg,
18361 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18362 .end_context_switch = paravirt_nop,
18363 };
18364
18365 -struct pv_apic_ops pv_apic_ops = {
18366 +struct pv_apic_ops pv_apic_ops __read_only = {
18367 #ifdef CONFIG_X86_LOCAL_APIC
18368 .startup_ipi_hook = paravirt_nop,
18369 #endif
18370 };
18371
18372 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18373 +#ifdef CONFIG_X86_32
18374 +#ifdef CONFIG_X86_PAE
18375 +/* 64-bit pagetable entries */
18376 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18377 +#else
18378 /* 32-bit pagetable entries */
18379 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18380 +#endif
18381 #else
18382 /* 64-bit pagetable entries */
18383 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18384 #endif
18385
18386 -struct pv_mmu_ops pv_mmu_ops = {
18387 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18388
18389 .read_cr2 = native_read_cr2,
18390 .write_cr2 = native_write_cr2,
18391 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18392 .make_pud = PTE_IDENT,
18393
18394 .set_pgd = native_set_pgd,
18395 + .set_pgd_batched = native_set_pgd_batched,
18396 #endif
18397 #endif /* PAGETABLE_LEVELS >= 3 */
18398
18399 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18400 },
18401
18402 .set_fixmap = native_set_fixmap,
18403 +
18404 +#ifdef CONFIG_PAX_KERNEXEC
18405 + .pax_open_kernel = native_pax_open_kernel,
18406 + .pax_close_kernel = native_pax_close_kernel,
18407 +#endif
18408 +
18409 };
18410
18411 EXPORT_SYMBOL_GPL(pv_time_ops);
18412 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18413 index 35ccf75..7a15747 100644
18414 --- a/arch/x86/kernel/pci-iommu_table.c
18415 +++ b/arch/x86/kernel/pci-iommu_table.c
18416 @@ -2,7 +2,7 @@
18417 #include <asm/iommu_table.h>
18418 #include <linux/string.h>
18419 #include <linux/kallsyms.h>
18420 -
18421 +#include <linux/sched.h>
18422
18423 #define DEBUG 1
18424
18425 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18426 index 1d92a5a..7bc8c29 100644
18427 --- a/arch/x86/kernel/process.c
18428 +++ b/arch/x86/kernel/process.c
18429 @@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18430
18431 void free_thread_info(struct thread_info *ti)
18432 {
18433 - free_thread_xstate(ti->task);
18434 free_pages((unsigned long)ti, THREAD_ORDER);
18435 }
18436
18437 +static struct kmem_cache *task_struct_cachep;
18438 +
18439 void arch_task_cache_init(void)
18440 {
18441 - task_xstate_cachep =
18442 - kmem_cache_create("task_xstate", xstate_size,
18443 + /* create a slab on which task_structs can be allocated */
18444 + task_struct_cachep =
18445 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18446 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18447 +
18448 + task_xstate_cachep =
18449 + kmem_cache_create("task_xstate", xstate_size,
18450 __alignof__(union thread_xstate),
18451 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18452 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18453 +}
18454 +
18455 +struct task_struct *alloc_task_struct_node(int node)
18456 +{
18457 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18458 +}
18459 +
18460 +void free_task_struct(struct task_struct *task)
18461 +{
18462 + free_thread_xstate(task);
18463 + kmem_cache_free(task_struct_cachep, task);
18464 }
18465
18466 /*
18467 @@ -91,7 +108,7 @@ void exit_thread(void)
18468 unsigned long *bp = t->io_bitmap_ptr;
18469
18470 if (bp) {
18471 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18472 + struct tss_struct *tss = init_tss + get_cpu();
18473
18474 t->io_bitmap_ptr = NULL;
18475 clear_thread_flag(TIF_IO_BITMAP);
18476 @@ -127,7 +144,7 @@ void show_regs_common(void)
18477
18478 printk(KERN_CONT "\n");
18479 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18480 - current->pid, current->comm, print_tainted(),
18481 + task_pid_nr(current), current->comm, print_tainted(),
18482 init_utsname()->release,
18483 (int)strcspn(init_utsname()->version, " "),
18484 init_utsname()->version);
18485 @@ -141,6 +158,9 @@ void flush_thread(void)
18486 {
18487 struct task_struct *tsk = current;
18488
18489 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18490 + loadsegment(gs, 0);
18491 +#endif
18492 flush_ptrace_hw_breakpoint(tsk);
18493 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18494 /*
18495 @@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18496 regs.di = (unsigned long) arg;
18497
18498 #ifdef CONFIG_X86_32
18499 - regs.ds = __USER_DS;
18500 - regs.es = __USER_DS;
18501 + regs.ds = __KERNEL_DS;
18502 + regs.es = __KERNEL_DS;
18503 regs.fs = __KERNEL_PERCPU;
18504 - regs.gs = __KERNEL_STACK_CANARY;
18505 + savesegment(gs, regs.gs);
18506 #else
18507 regs.ss = __KERNEL_DS;
18508 #endif
18509 @@ -392,7 +412,7 @@ static void __exit_idle(void)
18510 void exit_idle(void)
18511 {
18512 /* idle loop has pid 0 */
18513 - if (current->pid)
18514 + if (task_pid_nr(current))
18515 return;
18516 __exit_idle();
18517 }
18518 @@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18519
18520 return ret;
18521 }
18522 -void stop_this_cpu(void *dummy)
18523 +__noreturn void stop_this_cpu(void *dummy)
18524 {
18525 local_irq_disable();
18526 /*
18527 @@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18528 }
18529 early_param("idle", idle_setup);
18530
18531 -unsigned long arch_align_stack(unsigned long sp)
18532 +#ifdef CONFIG_PAX_RANDKSTACK
18533 +void pax_randomize_kstack(struct pt_regs *regs)
18534 {
18535 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18536 - sp -= get_random_int() % 8192;
18537 - return sp & ~0xf;
18538 -}
18539 + struct thread_struct *thread = &current->thread;
18540 + unsigned long time;
18541
18542 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18543 -{
18544 - unsigned long range_end = mm->brk + 0x02000000;
18545 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18546 -}
18547 + if (!randomize_va_space)
18548 + return;
18549 +
18550 + if (v8086_mode(regs))
18551 + return;
18552
18553 + rdtscl(time);
18554 +
18555 + /* P4 seems to return a 0 LSB, ignore it */
18556 +#ifdef CONFIG_MPENTIUM4
18557 + time &= 0x3EUL;
18558 + time <<= 2;
18559 +#elif defined(CONFIG_X86_64)
18560 + time &= 0xFUL;
18561 + time <<= 4;
18562 +#else
18563 + time &= 0x1FUL;
18564 + time <<= 3;
18565 +#endif
18566 +
18567 + thread->sp0 ^= time;
18568 + load_sp0(init_tss + smp_processor_id(), thread);
18569 +
18570 +#ifdef CONFIG_X86_64
18571 + percpu_write(kernel_stack, thread->sp0);
18572 +#endif
18573 +}
18574 +#endif
18575 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18576 index ae68473..7b0bb71 100644
18577 --- a/arch/x86/kernel/process_32.c
18578 +++ b/arch/x86/kernel/process_32.c
18579 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18580 unsigned long thread_saved_pc(struct task_struct *tsk)
18581 {
18582 return ((unsigned long *)tsk->thread.sp)[3];
18583 +//XXX return tsk->thread.eip;
18584 }
18585
18586 void __show_regs(struct pt_regs *regs, int all)
18587 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18588 unsigned long sp;
18589 unsigned short ss, gs;
18590
18591 - if (user_mode_vm(regs)) {
18592 + if (user_mode(regs)) {
18593 sp = regs->sp;
18594 ss = regs->ss & 0xffff;
18595 - gs = get_user_gs(regs);
18596 } else {
18597 sp = kernel_stack_pointer(regs);
18598 savesegment(ss, ss);
18599 - savesegment(gs, gs);
18600 }
18601 + gs = get_user_gs(regs);
18602
18603 show_regs_common();
18604
18605 @@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18606 struct task_struct *tsk;
18607 int err;
18608
18609 - childregs = task_pt_regs(p);
18610 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18611 *childregs = *regs;
18612 childregs->ax = 0;
18613 childregs->sp = sp;
18614
18615 p->thread.sp = (unsigned long) childregs;
18616 p->thread.sp0 = (unsigned long) (childregs+1);
18617 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18618
18619 p->thread.ip = (unsigned long) ret_from_fork;
18620
18621 @@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18622 struct thread_struct *prev = &prev_p->thread,
18623 *next = &next_p->thread;
18624 int cpu = smp_processor_id();
18625 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18626 + struct tss_struct *tss = init_tss + cpu;
18627 fpu_switch_t fpu;
18628
18629 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18630 @@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18631 */
18632 lazy_save_gs(prev->gs);
18633
18634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18635 + __set_fs(task_thread_info(next_p)->addr_limit);
18636 +#endif
18637 +
18638 /*
18639 * Load the per-thread Thread-Local Storage descriptor.
18640 */
18641 @@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18642 */
18643 arch_end_context_switch(next_p);
18644
18645 + percpu_write(current_task, next_p);
18646 + percpu_write(current_tinfo, &next_p->tinfo);
18647 +
18648 /*
18649 * Restore %gs if needed (which is common)
18650 */
18651 @@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18652
18653 switch_fpu_finish(next_p, fpu);
18654
18655 - percpu_write(current_task, next_p);
18656 -
18657 return prev_p;
18658 }
18659
18660 @@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18661 } while (count++ < 16);
18662 return 0;
18663 }
18664 -
18665 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18666 index 43d8b48..c45d566 100644
18667 --- a/arch/x86/kernel/process_64.c
18668 +++ b/arch/x86/kernel/process_64.c
18669 @@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18670 struct pt_regs *childregs;
18671 struct task_struct *me = current;
18672
18673 - childregs = ((struct pt_regs *)
18674 - (THREAD_SIZE + task_stack_page(p))) - 1;
18675 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18676 *childregs = *regs;
18677
18678 childregs->ax = 0;
18679 @@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18680 p->thread.sp = (unsigned long) childregs;
18681 p->thread.sp0 = (unsigned long) (childregs+1);
18682 p->thread.usersp = me->thread.usersp;
18683 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18684
18685 set_tsk_thread_flag(p, TIF_FORK);
18686
18687 @@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 struct thread_struct *prev = &prev_p->thread;
18689 struct thread_struct *next = &next_p->thread;
18690 int cpu = smp_processor_id();
18691 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18692 + struct tss_struct *tss = init_tss + cpu;
18693 unsigned fsindex, gsindex;
18694 fpu_switch_t fpu;
18695
18696 @@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18697 prev->usersp = percpu_read(old_rsp);
18698 percpu_write(old_rsp, next->usersp);
18699 percpu_write(current_task, next_p);
18700 + percpu_write(current_tinfo, &next_p->tinfo);
18701
18702 - percpu_write(kernel_stack,
18703 - (unsigned long)task_stack_page(next_p) +
18704 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18705 + percpu_write(kernel_stack, next->sp0);
18706
18707 /*
18708 * Now maybe reload the debug registers and handle I/O bitmaps
18709 @@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18710 if (!p || p == current || p->state == TASK_RUNNING)
18711 return 0;
18712 stack = (unsigned long)task_stack_page(p);
18713 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18714 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18715 return 0;
18716 fp = *(u64 *)(p->thread.sp);
18717 do {
18718 - if (fp < (unsigned long)stack ||
18719 - fp >= (unsigned long)stack+THREAD_SIZE)
18720 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18721 return 0;
18722 ip = *(u64 *)(fp+8);
18723 if (!in_sched_functions(ip))
18724 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18725 index cf11783..e7ce551 100644
18726 --- a/arch/x86/kernel/ptrace.c
18727 +++ b/arch/x86/kernel/ptrace.c
18728 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18729 unsigned long addr, unsigned long data)
18730 {
18731 int ret;
18732 - unsigned long __user *datap = (unsigned long __user *)data;
18733 + unsigned long __user *datap = (__force unsigned long __user *)data;
18734
18735 switch (request) {
18736 /* read the word at location addr in the USER area. */
18737 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18738 if ((int) addr < 0)
18739 return -EIO;
18740 ret = do_get_thread_area(child, addr,
18741 - (struct user_desc __user *)data);
18742 + (__force struct user_desc __user *) data);
18743 break;
18744
18745 case PTRACE_SET_THREAD_AREA:
18746 if ((int) addr < 0)
18747 return -EIO;
18748 ret = do_set_thread_area(child, addr,
18749 - (struct user_desc __user *)data, 0);
18750 + (__force struct user_desc __user *) data, 0);
18751 break;
18752 #endif
18753
18754 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18755 memset(info, 0, sizeof(*info));
18756 info->si_signo = SIGTRAP;
18757 info->si_code = si_code;
18758 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18759 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18760 }
18761
18762 void user_single_step_siginfo(struct task_struct *tsk,
18763 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18764 # define IS_IA32 0
18765 #endif
18766
18767 +#ifdef CONFIG_GRKERNSEC_SETXID
18768 +extern void gr_delayed_cred_worker(void);
18769 +#endif
18770 +
18771 /*
18772 * We must return the syscall number to actually look up in the table.
18773 * This can be -1L to skip running any syscall at all.
18774 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18775 {
18776 long ret = 0;
18777
18778 +#ifdef CONFIG_GRKERNSEC_SETXID
18779 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18780 + gr_delayed_cred_worker();
18781 +#endif
18782 +
18783 /*
18784 * If we stepped into a sysenter/syscall insn, it trapped in
18785 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18786 @@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18787 {
18788 bool step;
18789
18790 +#ifdef CONFIG_GRKERNSEC_SETXID
18791 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18792 + gr_delayed_cred_worker();
18793 +#endif
18794 +
18795 audit_syscall_exit(regs);
18796
18797 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18798 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18799 index 42eb330..139955c 100644
18800 --- a/arch/x86/kernel/pvclock.c
18801 +++ b/arch/x86/kernel/pvclock.c
18802 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18803 return pv_tsc_khz;
18804 }
18805
18806 -static atomic64_t last_value = ATOMIC64_INIT(0);
18807 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18808
18809 void pvclock_resume(void)
18810 {
18811 - atomic64_set(&last_value, 0);
18812 + atomic64_set_unchecked(&last_value, 0);
18813 }
18814
18815 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18816 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18817 * updating at the same time, and one of them could be slightly behind,
18818 * making the assumption that last_value always go forward fail to hold.
18819 */
18820 - last = atomic64_read(&last_value);
18821 + last = atomic64_read_unchecked(&last_value);
18822 do {
18823 if (ret < last)
18824 return last;
18825 - last = atomic64_cmpxchg(&last_value, last, ret);
18826 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18827 } while (unlikely(last != ret));
18828
18829 return ret;
18830 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18831 index 3034ee5..7cfbfa6 100644
18832 --- a/arch/x86/kernel/reboot.c
18833 +++ b/arch/x86/kernel/reboot.c
18834 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18835 EXPORT_SYMBOL(pm_power_off);
18836
18837 static const struct desc_ptr no_idt = {};
18838 -static int reboot_mode;
18839 +static unsigned short reboot_mode;
18840 enum reboot_type reboot_type = BOOT_ACPI;
18841 int reboot_force;
18842
18843 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18844 extern const unsigned char machine_real_restart_asm[];
18845 extern const u64 machine_real_restart_gdt[3];
18846
18847 -void machine_real_restart(unsigned int type)
18848 +__noreturn void machine_real_restart(unsigned int type)
18849 {
18850 void *restart_va;
18851 unsigned long restart_pa;
18852 - void (*restart_lowmem)(unsigned int);
18853 + void (* __noreturn restart_lowmem)(unsigned int);
18854 u64 *lowmem_gdt;
18855
18856 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18857 + struct desc_struct *gdt;
18858 +#endif
18859 +
18860 local_irq_disable();
18861
18862 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18863 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18864 boot)". This seems like a fairly standard thing that gets set by
18865 REBOOT.COM programs, and the previous reset routine did this
18866 too. */
18867 - *((unsigned short *)0x472) = reboot_mode;
18868 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18869
18870 /* Patch the GDT in the low memory trampoline */
18871 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18872
18873 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18874 restart_pa = virt_to_phys(restart_va);
18875 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18876 + restart_lowmem = (void *)restart_pa;
18877
18878 /* GDT[0]: GDT self-pointer */
18879 lowmem_gdt[0] =
18880 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18881 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18882
18883 /* Jump to the identity-mapped low memory code */
18884 +
18885 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18886 + gdt = get_cpu_gdt_table(smp_processor_id());
18887 + pax_open_kernel();
18888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18889 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18890 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18891 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18892 +#endif
18893 +#ifdef CONFIG_PAX_KERNEXEC
18894 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18895 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18896 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18897 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18898 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18899 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18900 +#endif
18901 + pax_close_kernel();
18902 +#endif
18903 +
18904 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18905 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18906 + unreachable();
18907 +#else
18908 restart_lowmem(type);
18909 +#endif
18910 +
18911 }
18912 #ifdef CONFIG_APM_MODULE
18913 EXPORT_SYMBOL(machine_real_restart);
18914 @@ -564,7 +594,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18915 * try to force a triple fault and then cycle between hitting the keyboard
18916 * controller and doing that
18917 */
18918 -static void native_machine_emergency_restart(void)
18919 +__noreturn static void native_machine_emergency_restart(void)
18920 {
18921 int i;
18922 int attempt = 0;
18923 @@ -688,13 +718,13 @@ void native_machine_shutdown(void)
18924 #endif
18925 }
18926
18927 -static void __machine_emergency_restart(int emergency)
18928 +static __noreturn void __machine_emergency_restart(int emergency)
18929 {
18930 reboot_emergency = emergency;
18931 machine_ops.emergency_restart();
18932 }
18933
18934 -static void native_machine_restart(char *__unused)
18935 +static __noreturn void native_machine_restart(char *__unused)
18936 {
18937 printk("machine restart\n");
18938
18939 @@ -703,7 +733,7 @@ static void native_machine_restart(char *__unused)
18940 __machine_emergency_restart(0);
18941 }
18942
18943 -static void native_machine_halt(void)
18944 +static __noreturn void native_machine_halt(void)
18945 {
18946 /* stop other cpus and apics */
18947 machine_shutdown();
18948 @@ -714,7 +744,7 @@ static void native_machine_halt(void)
18949 stop_this_cpu(NULL);
18950 }
18951
18952 -static void native_machine_power_off(void)
18953 +__noreturn static void native_machine_power_off(void)
18954 {
18955 if (pm_power_off) {
18956 if (!reboot_force)
18957 @@ -723,6 +753,7 @@ static void native_machine_power_off(void)
18958 }
18959 /* a fallback in case there is no PM info available */
18960 tboot_shutdown(TB_SHUTDOWN_HALT);
18961 + unreachable();
18962 }
18963
18964 struct machine_ops machine_ops = {
18965 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18966 index 7a6f3b3..bed145d7 100644
18967 --- a/arch/x86/kernel/relocate_kernel_64.S
18968 +++ b/arch/x86/kernel/relocate_kernel_64.S
18969 @@ -11,6 +11,7 @@
18970 #include <asm/kexec.h>
18971 #include <asm/processor-flags.h>
18972 #include <asm/pgtable_types.h>
18973 +#include <asm/alternative-asm.h>
18974
18975 /*
18976 * Must be relocatable PIC code callable as a C function
18977 @@ -160,13 +161,14 @@ identity_mapped:
18978 xorq %rbp, %rbp
18979 xorq %r8, %r8
18980 xorq %r9, %r9
18981 - xorq %r10, %r9
18982 + xorq %r10, %r10
18983 xorq %r11, %r11
18984 xorq %r12, %r12
18985 xorq %r13, %r13
18986 xorq %r14, %r14
18987 xorq %r15, %r15
18988
18989 + pax_force_retaddr 0, 1
18990 ret
18991
18992 1:
18993 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18994 index 1a29015..712f324 100644
18995 --- a/arch/x86/kernel/setup.c
18996 +++ b/arch/x86/kernel/setup.c
18997 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
18998
18999 switch (data->type) {
19000 case SETUP_E820_EXT:
19001 - parse_e820_ext(data);
19002 + parse_e820_ext((struct setup_data __force_kernel *)data);
19003 break;
19004 case SETUP_DTB:
19005 add_dtb(pa_data);
19006 @@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19007 * area (640->1Mb) as ram even though it is not.
19008 * take them out.
19009 */
19010 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19011 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19012 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19013 }
19014
19015 @@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19016
19017 if (!boot_params.hdr.root_flags)
19018 root_mountflags &= ~MS_RDONLY;
19019 - init_mm.start_code = (unsigned long) _text;
19020 - init_mm.end_code = (unsigned long) _etext;
19021 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19022 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19023 init_mm.end_data = (unsigned long) _edata;
19024 init_mm.brk = _brk_end;
19025
19026 - code_resource.start = virt_to_phys(_text);
19027 - code_resource.end = virt_to_phys(_etext)-1;
19028 - data_resource.start = virt_to_phys(_etext);
19029 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19030 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19031 + data_resource.start = virt_to_phys(_sdata);
19032 data_resource.end = virt_to_phys(_edata)-1;
19033 bss_resource.start = virt_to_phys(&__bss_start);
19034 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19035 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19036 index 5a98aa2..2f9288d 100644
19037 --- a/arch/x86/kernel/setup_percpu.c
19038 +++ b/arch/x86/kernel/setup_percpu.c
19039 @@ -21,19 +21,17 @@
19040 #include <asm/cpu.h>
19041 #include <asm/stackprotector.h>
19042
19043 -DEFINE_PER_CPU(int, cpu_number);
19044 +#ifdef CONFIG_SMP
19045 +DEFINE_PER_CPU(unsigned int, cpu_number);
19046 EXPORT_PER_CPU_SYMBOL(cpu_number);
19047 +#endif
19048
19049 -#ifdef CONFIG_X86_64
19050 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19051 -#else
19052 -#define BOOT_PERCPU_OFFSET 0
19053 -#endif
19054
19055 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19056 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19057
19058 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19059 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19060 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19061 };
19062 EXPORT_SYMBOL(__per_cpu_offset);
19063 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19064 {
19065 #ifdef CONFIG_X86_32
19066 struct desc_struct gdt;
19067 + unsigned long base = per_cpu_offset(cpu);
19068
19069 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19070 - 0x2 | DESCTYPE_S, 0x8);
19071 - gdt.s = 1;
19072 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19073 + 0x83 | DESCTYPE_S, 0xC);
19074 write_gdt_entry(get_cpu_gdt_table(cpu),
19075 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19076 #endif
19077 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19078 /* alrighty, percpu areas up and running */
19079 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19080 for_each_possible_cpu(cpu) {
19081 +#ifdef CONFIG_CC_STACKPROTECTOR
19082 +#ifdef CONFIG_X86_32
19083 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19084 +#endif
19085 +#endif
19086 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19087 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19088 per_cpu(cpu_number, cpu) = cpu;
19089 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19090 */
19091 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19092 #endif
19093 +#ifdef CONFIG_CC_STACKPROTECTOR
19094 +#ifdef CONFIG_X86_32
19095 + if (!cpu)
19096 + per_cpu(stack_canary.canary, cpu) = canary;
19097 +#endif
19098 +#endif
19099 /*
19100 * Up to this point, the boot CPU has been using .init.data
19101 * area. Reload any changed state for the boot CPU.
19102 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19103 index 115eac4..c0591d5 100644
19104 --- a/arch/x86/kernel/signal.c
19105 +++ b/arch/x86/kernel/signal.c
19106 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19107 * Align the stack pointer according to the i386 ABI,
19108 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19109 */
19110 - sp = ((sp + 4) & -16ul) - 4;
19111 + sp = ((sp - 12) & -16ul) - 4;
19112 #else /* !CONFIG_X86_32 */
19113 sp = round_down(sp, 16) - 8;
19114 #endif
19115 @@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19116 * Return an always-bogus address instead so we will die with SIGSEGV.
19117 */
19118 if (onsigstack && !likely(on_sig_stack(sp)))
19119 - return (void __user *)-1L;
19120 + return (__force void __user *)-1L;
19121
19122 /* save i387 state */
19123 if (used_math() && save_i387_xstate(*fpstate) < 0)
19124 - return (void __user *)-1L;
19125 + return (__force void __user *)-1L;
19126
19127 return (void __user *)sp;
19128 }
19129 @@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19130 }
19131
19132 if (current->mm->context.vdso)
19133 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19134 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19135 else
19136 - restorer = &frame->retcode;
19137 + restorer = (void __user *)&frame->retcode;
19138 if (ka->sa.sa_flags & SA_RESTORER)
19139 restorer = ka->sa.sa_restorer;
19140
19141 @@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19142 * reasons and because gdb uses it as a signature to notice
19143 * signal handler stack frames.
19144 */
19145 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19146 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19147
19148 if (err)
19149 return -EFAULT;
19150 @@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19151 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19152
19153 /* Set up to return from userspace. */
19154 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19155 + if (current->mm->context.vdso)
19156 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19157 + else
19158 + restorer = (void __user *)&frame->retcode;
19159 if (ka->sa.sa_flags & SA_RESTORER)
19160 restorer = ka->sa.sa_restorer;
19161 put_user_ex(restorer, &frame->pretcode);
19162 @@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19163 * reasons and because gdb uses it as a signature to notice
19164 * signal handler stack frames.
19165 */
19166 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19167 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19168 } put_user_catch(err);
19169
19170 if (err)
19171 @@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19172 * X86_32: vm86 regs switched out by assembly code before reaching
19173 * here, so testing against kernel CS suffices.
19174 */
19175 - if (!user_mode(regs))
19176 + if (!user_mode_novm(regs))
19177 return;
19178
19179 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19180 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19181 index 6e1e406..edfb7cb 100644
19182 --- a/arch/x86/kernel/smpboot.c
19183 +++ b/arch/x86/kernel/smpboot.c
19184 @@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19185 set_idle_for_cpu(cpu, c_idle.idle);
19186 do_rest:
19187 per_cpu(current_task, cpu) = c_idle.idle;
19188 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19189 #ifdef CONFIG_X86_32
19190 /* Stack for startup_32 can be just as for start_secondary onwards */
19191 irq_ctx_init(cpu);
19192 #else
19193 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19194 initial_gs = per_cpu_offset(cpu);
19195 - per_cpu(kernel_stack, cpu) =
19196 - (unsigned long)task_stack_page(c_idle.idle) -
19197 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19198 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19199 #endif
19200 +
19201 + pax_open_kernel();
19202 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19203 + pax_close_kernel();
19204 +
19205 initial_code = (unsigned long)start_secondary;
19206 stack_start = c_idle.idle->thread.sp;
19207
19208 @@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19209
19210 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19211
19212 +#ifdef CONFIG_PAX_PER_CPU_PGD
19213 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19214 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19215 + KERNEL_PGD_PTRS);
19216 +#endif
19217 +
19218 err = do_boot_cpu(apicid, cpu);
19219 if (err) {
19220 pr_debug("do_boot_cpu failed %d\n", err);
19221 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19222 index c346d11..d43b163 100644
19223 --- a/arch/x86/kernel/step.c
19224 +++ b/arch/x86/kernel/step.c
19225 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19226 struct desc_struct *desc;
19227 unsigned long base;
19228
19229 - seg &= ~7UL;
19230 + seg >>= 3;
19231
19232 mutex_lock(&child->mm->context.lock);
19233 - if (unlikely((seg >> 3) >= child->mm->context.size))
19234 + if (unlikely(seg >= child->mm->context.size))
19235 addr = -1L; /* bogus selector, access would fault */
19236 else {
19237 desc = child->mm->context.ldt + seg;
19238 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19239 addr += base;
19240 }
19241 mutex_unlock(&child->mm->context.lock);
19242 - }
19243 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19244 + addr = ktla_ktva(addr);
19245
19246 return addr;
19247 }
19248 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19249 unsigned char opcode[15];
19250 unsigned long addr = convert_ip_to_linear(child, regs);
19251
19252 + if (addr == -EINVAL)
19253 + return 0;
19254 +
19255 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19256 for (i = 0; i < copied; i++) {
19257 switch (opcode[i]) {
19258 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19259 index 0b0cb5f..db6b9ed 100644
19260 --- a/arch/x86/kernel/sys_i386_32.c
19261 +++ b/arch/x86/kernel/sys_i386_32.c
19262 @@ -24,17 +24,224 @@
19263
19264 #include <asm/syscalls.h>
19265
19266 -/*
19267 - * Do a system call from kernel instead of calling sys_execve so we
19268 - * end up with proper pt_regs.
19269 - */
19270 -int kernel_execve(const char *filename,
19271 - const char *const argv[],
19272 - const char *const envp[])
19273 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19274 {
19275 - long __res;
19276 - asm volatile ("int $0x80"
19277 - : "=a" (__res)
19278 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19279 - return __res;
19280 + unsigned long pax_task_size = TASK_SIZE;
19281 +
19282 +#ifdef CONFIG_PAX_SEGMEXEC
19283 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19284 + pax_task_size = SEGMEXEC_TASK_SIZE;
19285 +#endif
19286 +
19287 + if (len > pax_task_size || addr > pax_task_size - len)
19288 + return -EINVAL;
19289 +
19290 + return 0;
19291 +}
19292 +
19293 +unsigned long
19294 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19295 + unsigned long len, unsigned long pgoff, unsigned long flags)
19296 +{
19297 + struct mm_struct *mm = current->mm;
19298 + struct vm_area_struct *vma;
19299 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19300 +
19301 +#ifdef CONFIG_PAX_SEGMEXEC
19302 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19303 + pax_task_size = SEGMEXEC_TASK_SIZE;
19304 +#endif
19305 +
19306 + pax_task_size -= PAGE_SIZE;
19307 +
19308 + if (len > pax_task_size)
19309 + return -ENOMEM;
19310 +
19311 + if (flags & MAP_FIXED)
19312 + return addr;
19313 +
19314 +#ifdef CONFIG_PAX_RANDMMAP
19315 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19316 +#endif
19317 +
19318 + if (addr) {
19319 + addr = PAGE_ALIGN(addr);
19320 + if (pax_task_size - len >= addr) {
19321 + vma = find_vma(mm, addr);
19322 + if (check_heap_stack_gap(vma, addr, len))
19323 + return addr;
19324 + }
19325 + }
19326 + if (len > mm->cached_hole_size) {
19327 + start_addr = addr = mm->free_area_cache;
19328 + } else {
19329 + start_addr = addr = mm->mmap_base;
19330 + mm->cached_hole_size = 0;
19331 + }
19332 +
19333 +#ifdef CONFIG_PAX_PAGEEXEC
19334 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19335 + start_addr = 0x00110000UL;
19336 +
19337 +#ifdef CONFIG_PAX_RANDMMAP
19338 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19339 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19340 +#endif
19341 +
19342 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19343 + start_addr = addr = mm->mmap_base;
19344 + else
19345 + addr = start_addr;
19346 + }
19347 +#endif
19348 +
19349 +full_search:
19350 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19351 + /* At this point: (!vma || addr < vma->vm_end). */
19352 + if (pax_task_size - len < addr) {
19353 + /*
19354 + * Start a new search - just in case we missed
19355 + * some holes.
19356 + */
19357 + if (start_addr != mm->mmap_base) {
19358 + start_addr = addr = mm->mmap_base;
19359 + mm->cached_hole_size = 0;
19360 + goto full_search;
19361 + }
19362 + return -ENOMEM;
19363 + }
19364 + if (check_heap_stack_gap(vma, addr, len))
19365 + break;
19366 + if (addr + mm->cached_hole_size < vma->vm_start)
19367 + mm->cached_hole_size = vma->vm_start - addr;
19368 + addr = vma->vm_end;
19369 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19370 + start_addr = addr = mm->mmap_base;
19371 + mm->cached_hole_size = 0;
19372 + goto full_search;
19373 + }
19374 + }
19375 +
19376 + /*
19377 + * Remember the place where we stopped the search:
19378 + */
19379 + mm->free_area_cache = addr + len;
19380 + return addr;
19381 +}
19382 +
19383 +unsigned long
19384 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19385 + const unsigned long len, const unsigned long pgoff,
19386 + const unsigned long flags)
19387 +{
19388 + struct vm_area_struct *vma;
19389 + struct mm_struct *mm = current->mm;
19390 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19391 +
19392 +#ifdef CONFIG_PAX_SEGMEXEC
19393 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19394 + pax_task_size = SEGMEXEC_TASK_SIZE;
19395 +#endif
19396 +
19397 + pax_task_size -= PAGE_SIZE;
19398 +
19399 + /* requested length too big for entire address space */
19400 + if (len > pax_task_size)
19401 + return -ENOMEM;
19402 +
19403 + if (flags & MAP_FIXED)
19404 + return addr;
19405 +
19406 +#ifdef CONFIG_PAX_PAGEEXEC
19407 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19408 + goto bottomup;
19409 +#endif
19410 +
19411 +#ifdef CONFIG_PAX_RANDMMAP
19412 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19413 +#endif
19414 +
19415 + /* requesting a specific address */
19416 + if (addr) {
19417 + addr = PAGE_ALIGN(addr);
19418 + if (pax_task_size - len >= addr) {
19419 + vma = find_vma(mm, addr);
19420 + if (check_heap_stack_gap(vma, addr, len))
19421 + return addr;
19422 + }
19423 + }
19424 +
19425 + /* check if free_area_cache is useful for us */
19426 + if (len <= mm->cached_hole_size) {
19427 + mm->cached_hole_size = 0;
19428 + mm->free_area_cache = mm->mmap_base;
19429 + }
19430 +
19431 + /* either no address requested or can't fit in requested address hole */
19432 + addr = mm->free_area_cache;
19433 +
19434 + /* make sure it can fit in the remaining address space */
19435 + if (addr > len) {
19436 + vma = find_vma(mm, addr-len);
19437 + if (check_heap_stack_gap(vma, addr - len, len))
19438 + /* remember the address as a hint for next time */
19439 + return (mm->free_area_cache = addr-len);
19440 + }
19441 +
19442 + if (mm->mmap_base < len)
19443 + goto bottomup;
19444 +
19445 + addr = mm->mmap_base-len;
19446 +
19447 + do {
19448 + /*
19449 + * Lookup failure means no vma is above this address,
19450 + * else if new region fits below vma->vm_start,
19451 + * return with success:
19452 + */
19453 + vma = find_vma(mm, addr);
19454 + if (check_heap_stack_gap(vma, addr, len))
19455 + /* remember the address as a hint for next time */
19456 + return (mm->free_area_cache = addr);
19457 +
19458 + /* remember the largest hole we saw so far */
19459 + if (addr + mm->cached_hole_size < vma->vm_start)
19460 + mm->cached_hole_size = vma->vm_start - addr;
19461 +
19462 + /* try just below the current vma->vm_start */
19463 + addr = skip_heap_stack_gap(vma, len);
19464 + } while (!IS_ERR_VALUE(addr));
19465 +
19466 +bottomup:
19467 + /*
19468 + * A failed mmap() very likely causes application failure,
19469 + * so fall back to the bottom-up function here. This scenario
19470 + * can happen with large stack limits and large mmap()
19471 + * allocations.
19472 + */
19473 +
19474 +#ifdef CONFIG_PAX_SEGMEXEC
19475 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19476 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19477 + else
19478 +#endif
19479 +
19480 + mm->mmap_base = TASK_UNMAPPED_BASE;
19481 +
19482 +#ifdef CONFIG_PAX_RANDMMAP
19483 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19484 + mm->mmap_base += mm->delta_mmap;
19485 +#endif
19486 +
19487 + mm->free_area_cache = mm->mmap_base;
19488 + mm->cached_hole_size = ~0UL;
19489 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19490 + /*
19491 + * Restore the topdown base:
19492 + */
19493 + mm->mmap_base = base;
19494 + mm->free_area_cache = base;
19495 + mm->cached_hole_size = ~0UL;
19496 +
19497 + return addr;
19498 }
19499 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19500 index b4d3c39..82bb73b 100644
19501 --- a/arch/x86/kernel/sys_x86_64.c
19502 +++ b/arch/x86/kernel/sys_x86_64.c
19503 @@ -95,8 +95,8 @@ out:
19504 return error;
19505 }
19506
19507 -static void find_start_end(unsigned long flags, unsigned long *begin,
19508 - unsigned long *end)
19509 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19510 + unsigned long *begin, unsigned long *end)
19511 {
19512 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19513 unsigned long new_begin;
19514 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19515 *begin = new_begin;
19516 }
19517 } else {
19518 - *begin = TASK_UNMAPPED_BASE;
19519 + *begin = mm->mmap_base;
19520 *end = TASK_SIZE;
19521 }
19522 }
19523 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19524 if (flags & MAP_FIXED)
19525 return addr;
19526
19527 - find_start_end(flags, &begin, &end);
19528 + find_start_end(mm, flags, &begin, &end);
19529
19530 if (len > end)
19531 return -ENOMEM;
19532
19533 +#ifdef CONFIG_PAX_RANDMMAP
19534 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19535 +#endif
19536 +
19537 if (addr) {
19538 addr = PAGE_ALIGN(addr);
19539 vma = find_vma(mm, addr);
19540 - if (end - len >= addr &&
19541 - (!vma || addr + len <= vma->vm_start))
19542 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19543 return addr;
19544 }
19545 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19546 @@ -172,7 +175,7 @@ full_search:
19547 }
19548 return -ENOMEM;
19549 }
19550 - if (!vma || addr + len <= vma->vm_start) {
19551 + if (check_heap_stack_gap(vma, addr, len)) {
19552 /*
19553 * Remember the place where we stopped the search:
19554 */
19555 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19556 {
19557 struct vm_area_struct *vma;
19558 struct mm_struct *mm = current->mm;
19559 - unsigned long addr = addr0, start_addr;
19560 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19561
19562 /* requested length too big for entire address space */
19563 if (len > TASK_SIZE)
19564 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19565 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19566 goto bottomup;
19567
19568 +#ifdef CONFIG_PAX_RANDMMAP
19569 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19570 +#endif
19571 +
19572 /* requesting a specific address */
19573 if (addr) {
19574 addr = PAGE_ALIGN(addr);
19575 - vma = find_vma(mm, addr);
19576 - if (TASK_SIZE - len >= addr &&
19577 - (!vma || addr + len <= vma->vm_start))
19578 - return addr;
19579 + if (TASK_SIZE - len >= addr) {
19580 + vma = find_vma(mm, addr);
19581 + if (check_heap_stack_gap(vma, addr, len))
19582 + return addr;
19583 + }
19584 }
19585
19586 /* check if free_area_cache is useful for us */
19587 @@ -240,7 +248,7 @@ try_again:
19588 * return with success:
19589 */
19590 vma = find_vma(mm, addr);
19591 - if (!vma || addr+len <= vma->vm_start)
19592 + if (check_heap_stack_gap(vma, addr, len))
19593 /* remember the address as a hint for next time */
19594 return mm->free_area_cache = addr;
19595
19596 @@ -249,8 +257,8 @@ try_again:
19597 mm->cached_hole_size = vma->vm_start - addr;
19598
19599 /* try just below the current vma->vm_start */
19600 - addr = vma->vm_start-len;
19601 - } while (len < vma->vm_start);
19602 + addr = skip_heap_stack_gap(vma, len);
19603 + } while (!IS_ERR_VALUE(addr));
19604
19605 fail:
19606 /*
19607 @@ -270,13 +278,21 @@ bottomup:
19608 * can happen with large stack limits and large mmap()
19609 * allocations.
19610 */
19611 + mm->mmap_base = TASK_UNMAPPED_BASE;
19612 +
19613 +#ifdef CONFIG_PAX_RANDMMAP
19614 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19615 + mm->mmap_base += mm->delta_mmap;
19616 +#endif
19617 +
19618 + mm->free_area_cache = mm->mmap_base;
19619 mm->cached_hole_size = ~0UL;
19620 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19621 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19622 /*
19623 * Restore the topdown base:
19624 */
19625 - mm->free_area_cache = mm->mmap_base;
19626 + mm->mmap_base = base;
19627 + mm->free_area_cache = base;
19628 mm->cached_hole_size = ~0UL;
19629
19630 return addr;
19631 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19632 index 6410744..79758f0 100644
19633 --- a/arch/x86/kernel/tboot.c
19634 +++ b/arch/x86/kernel/tboot.c
19635 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19636
19637 void tboot_shutdown(u32 shutdown_type)
19638 {
19639 - void (*shutdown)(void);
19640 + void (* __noreturn shutdown)(void);
19641
19642 if (!tboot_enabled())
19643 return;
19644 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19645
19646 switch_to_tboot_pt();
19647
19648 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19649 + shutdown = (void *)tboot->shutdown_entry;
19650 shutdown();
19651
19652 /* should not reach here */
19653 @@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19654 return 0;
19655 }
19656
19657 -static atomic_t ap_wfs_count;
19658 +static atomic_unchecked_t ap_wfs_count;
19659
19660 static int tboot_wait_for_aps(int num_aps)
19661 {
19662 @@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19663 {
19664 switch (action) {
19665 case CPU_DYING:
19666 - atomic_inc(&ap_wfs_count);
19667 + atomic_inc_unchecked(&ap_wfs_count);
19668 if (num_online_cpus() == 1)
19669 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19670 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19671 return NOTIFY_BAD;
19672 break;
19673 }
19674 @@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19675
19676 tboot_create_trampoline();
19677
19678 - atomic_set(&ap_wfs_count, 0);
19679 + atomic_set_unchecked(&ap_wfs_count, 0);
19680 register_hotcpu_notifier(&tboot_cpu_notifier);
19681
19682 acpi_os_set_prepare_sleep(&tboot_sleep);
19683 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19684 index c6eba2b..3303326 100644
19685 --- a/arch/x86/kernel/time.c
19686 +++ b/arch/x86/kernel/time.c
19687 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19688 {
19689 unsigned long pc = instruction_pointer(regs);
19690
19691 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19692 + if (!user_mode(regs) && in_lock_functions(pc)) {
19693 #ifdef CONFIG_FRAME_POINTER
19694 - return *(unsigned long *)(regs->bp + sizeof(long));
19695 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19696 #else
19697 unsigned long *sp =
19698 (unsigned long *)kernel_stack_pointer(regs);
19699 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19700 * or above a saved flags. Eflags has bits 22-31 zero,
19701 * kernel addresses don't.
19702 */
19703 +
19704 +#ifdef CONFIG_PAX_KERNEXEC
19705 + return ktla_ktva(sp[0]);
19706 +#else
19707 if (sp[0] >> 22)
19708 return sp[0];
19709 if (sp[1] >> 22)
19710 return sp[1];
19711 #endif
19712 +
19713 +#endif
19714 }
19715 return pc;
19716 }
19717 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19718 index 9d9d2f9..ed344e4 100644
19719 --- a/arch/x86/kernel/tls.c
19720 +++ b/arch/x86/kernel/tls.c
19721 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19722 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19723 return -EINVAL;
19724
19725 +#ifdef CONFIG_PAX_SEGMEXEC
19726 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19727 + return -EINVAL;
19728 +#endif
19729 +
19730 set_tls_desc(p, idx, &info, 1);
19731
19732 return 0;
19733 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19734 index 451c0a7..e57f551 100644
19735 --- a/arch/x86/kernel/trampoline_32.S
19736 +++ b/arch/x86/kernel/trampoline_32.S
19737 @@ -32,6 +32,12 @@
19738 #include <asm/segment.h>
19739 #include <asm/page_types.h>
19740
19741 +#ifdef CONFIG_PAX_KERNEXEC
19742 +#define ta(X) (X)
19743 +#else
19744 +#define ta(X) ((X) - __PAGE_OFFSET)
19745 +#endif
19746 +
19747 #ifdef CONFIG_SMP
19748
19749 .section ".x86_trampoline","a"
19750 @@ -62,7 +68,7 @@ r_base = .
19751 inc %ax # protected mode (PE) bit
19752 lmsw %ax # into protected mode
19753 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19754 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19755 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19756
19757 # These need to be in the same 64K segment as the above;
19758 # hence we don't use the boot_gdt_descr defined in head.S
19759 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19760 index 09ff517..df19fbff 100644
19761 --- a/arch/x86/kernel/trampoline_64.S
19762 +++ b/arch/x86/kernel/trampoline_64.S
19763 @@ -90,7 +90,7 @@ startup_32:
19764 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19765 movl %eax, %ds
19766
19767 - movl $X86_CR4_PAE, %eax
19768 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19769 movl %eax, %cr4 # Enable PAE mode
19770
19771 # Setup trampoline 4 level pagetables
19772 @@ -138,7 +138,7 @@ tidt:
19773 # so the kernel can live anywhere
19774 .balign 4
19775 tgdt:
19776 - .short tgdt_end - tgdt # gdt limit
19777 + .short tgdt_end - tgdt - 1 # gdt limit
19778 .long tgdt - r_base
19779 .short 0
19780 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19781 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19782 index ff9281f1..30cb4ac 100644
19783 --- a/arch/x86/kernel/traps.c
19784 +++ b/arch/x86/kernel/traps.c
19785 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19786
19787 /* Do we ignore FPU interrupts ? */
19788 char ignore_fpu_irq;
19789 -
19790 -/*
19791 - * The IDT has to be page-aligned to simplify the Pentium
19792 - * F0 0F bug workaround.
19793 - */
19794 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19795 #endif
19796
19797 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19798 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19799 }
19800
19801 static void __kprobes
19802 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19803 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19804 long error_code, siginfo_t *info)
19805 {
19806 struct task_struct *tsk = current;
19807
19808 #ifdef CONFIG_X86_32
19809 - if (regs->flags & X86_VM_MASK) {
19810 + if (v8086_mode(regs)) {
19811 /*
19812 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19813 * On nmi (interrupt 2), do_trap should not be called.
19814 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19815 }
19816 #endif
19817
19818 - if (!user_mode(regs))
19819 + if (!user_mode_novm(regs))
19820 goto kernel_trap;
19821
19822 #ifdef CONFIG_X86_32
19823 @@ -148,7 +142,7 @@ trap_signal:
19824 printk_ratelimit()) {
19825 printk(KERN_INFO
19826 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19827 - tsk->comm, tsk->pid, str,
19828 + tsk->comm, task_pid_nr(tsk), str,
19829 regs->ip, regs->sp, error_code);
19830 print_vma_addr(" in ", regs->ip);
19831 printk("\n");
19832 @@ -165,8 +159,20 @@ kernel_trap:
19833 if (!fixup_exception(regs)) {
19834 tsk->thread.error_code = error_code;
19835 tsk->thread.trap_nr = trapnr;
19836 +
19837 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19838 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19839 + str = "PAX: suspicious stack segment fault";
19840 +#endif
19841 +
19842 die(str, regs, error_code);
19843 }
19844 +
19845 +#ifdef CONFIG_PAX_REFCOUNT
19846 + if (trapnr == 4)
19847 + pax_report_refcount_overflow(regs);
19848 +#endif
19849 +
19850 return;
19851
19852 #ifdef CONFIG_X86_32
19853 @@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19854 conditional_sti(regs);
19855
19856 #ifdef CONFIG_X86_32
19857 - if (regs->flags & X86_VM_MASK)
19858 + if (v8086_mode(regs))
19859 goto gp_in_vm86;
19860 #endif
19861
19862 tsk = current;
19863 - if (!user_mode(regs))
19864 + if (!user_mode_novm(regs))
19865 goto gp_in_kernel;
19866
19867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19868 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19869 + struct mm_struct *mm = tsk->mm;
19870 + unsigned long limit;
19871 +
19872 + down_write(&mm->mmap_sem);
19873 + limit = mm->context.user_cs_limit;
19874 + if (limit < TASK_SIZE) {
19875 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19876 + up_write(&mm->mmap_sem);
19877 + return;
19878 + }
19879 + up_write(&mm->mmap_sem);
19880 + }
19881 +#endif
19882 +
19883 tsk->thread.error_code = error_code;
19884 tsk->thread.trap_nr = X86_TRAP_GP;
19885
19886 @@ -299,6 +321,13 @@ gp_in_kernel:
19887 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19888 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19889 return;
19890 +
19891 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19892 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19893 + die("PAX: suspicious general protection fault", regs, error_code);
19894 + else
19895 +#endif
19896 +
19897 die("general protection fault", regs, error_code);
19898 }
19899
19900 @@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19901 /* It's safe to allow irq's after DR6 has been saved */
19902 preempt_conditional_sti(regs);
19903
19904 - if (regs->flags & X86_VM_MASK) {
19905 + if (v8086_mode(regs)) {
19906 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19907 X86_TRAP_DB);
19908 preempt_conditional_cli(regs);
19909 @@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19910 * We already checked v86 mode above, so we can check for kernel mode
19911 * by just checking the CPL of CS.
19912 */
19913 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19914 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19915 tsk->thread.debugreg6 &= ~DR_STEP;
19916 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19917 regs->flags &= ~X86_EFLAGS_TF;
19918 @@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19919 return;
19920 conditional_sti(regs);
19921
19922 - if (!user_mode_vm(regs))
19923 + if (!user_mode(regs))
19924 {
19925 if (!fixup_exception(regs)) {
19926 task->thread.error_code = error_code;
19927 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19928 index b9242ba..50c5edd 100644
19929 --- a/arch/x86/kernel/verify_cpu.S
19930 +++ b/arch/x86/kernel/verify_cpu.S
19931 @@ -20,6 +20,7 @@
19932 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19933 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19934 * arch/x86/kernel/head_32.S: processor startup
19935 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19936 *
19937 * verify_cpu, returns the status of longmode and SSE in register %eax.
19938 * 0: Success 1: Failure
19939 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19940 index 255f58a..5e91150 100644
19941 --- a/arch/x86/kernel/vm86_32.c
19942 +++ b/arch/x86/kernel/vm86_32.c
19943 @@ -41,6 +41,7 @@
19944 #include <linux/ptrace.h>
19945 #include <linux/audit.h>
19946 #include <linux/stddef.h>
19947 +#include <linux/grsecurity.h>
19948
19949 #include <asm/uaccess.h>
19950 #include <asm/io.h>
19951 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19952 do_exit(SIGSEGV);
19953 }
19954
19955 - tss = &per_cpu(init_tss, get_cpu());
19956 + tss = init_tss + get_cpu();
19957 current->thread.sp0 = current->thread.saved_sp0;
19958 current->thread.sysenter_cs = __KERNEL_CS;
19959 load_sp0(tss, &current->thread);
19960 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19961 struct task_struct *tsk;
19962 int tmp, ret = -EPERM;
19963
19964 +#ifdef CONFIG_GRKERNSEC_VM86
19965 + if (!capable(CAP_SYS_RAWIO)) {
19966 + gr_handle_vm86();
19967 + goto out;
19968 + }
19969 +#endif
19970 +
19971 tsk = current;
19972 if (tsk->thread.saved_sp0)
19973 goto out;
19974 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19975 int tmp, ret;
19976 struct vm86plus_struct __user *v86;
19977
19978 +#ifdef CONFIG_GRKERNSEC_VM86
19979 + if (!capable(CAP_SYS_RAWIO)) {
19980 + gr_handle_vm86();
19981 + ret = -EPERM;
19982 + goto out;
19983 + }
19984 +#endif
19985 +
19986 tsk = current;
19987 switch (cmd) {
19988 case VM86_REQUEST_IRQ:
19989 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19990 tsk->thread.saved_fs = info->regs32->fs;
19991 tsk->thread.saved_gs = get_user_gs(info->regs32);
19992
19993 - tss = &per_cpu(init_tss, get_cpu());
19994 + tss = init_tss + get_cpu();
19995 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19996 if (cpu_has_sep)
19997 tsk->thread.sysenter_cs = 0;
19998 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19999 goto cannot_handle;
20000 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20001 goto cannot_handle;
20002 - intr_ptr = (unsigned long __user *) (i << 2);
20003 + intr_ptr = (__force unsigned long __user *) (i << 2);
20004 if (get_user(segoffs, intr_ptr))
20005 goto cannot_handle;
20006 if ((segoffs >> 16) == BIOSSEG)
20007 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20008 index 0f703f1..9e15f64 100644
20009 --- a/arch/x86/kernel/vmlinux.lds.S
20010 +++ b/arch/x86/kernel/vmlinux.lds.S
20011 @@ -26,6 +26,13 @@
20012 #include <asm/page_types.h>
20013 #include <asm/cache.h>
20014 #include <asm/boot.h>
20015 +#include <asm/segment.h>
20016 +
20017 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20018 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20019 +#else
20020 +#define __KERNEL_TEXT_OFFSET 0
20021 +#endif
20022
20023 #undef i386 /* in case the preprocessor is a 32bit one */
20024
20025 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20026
20027 PHDRS {
20028 text PT_LOAD FLAGS(5); /* R_E */
20029 +#ifdef CONFIG_X86_32
20030 + module PT_LOAD FLAGS(5); /* R_E */
20031 +#endif
20032 +#ifdef CONFIG_XEN
20033 + rodata PT_LOAD FLAGS(5); /* R_E */
20034 +#else
20035 + rodata PT_LOAD FLAGS(4); /* R__ */
20036 +#endif
20037 data PT_LOAD FLAGS(6); /* RW_ */
20038 -#ifdef CONFIG_X86_64
20039 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20040 #ifdef CONFIG_SMP
20041 percpu PT_LOAD FLAGS(6); /* RW_ */
20042 #endif
20043 + text.init PT_LOAD FLAGS(5); /* R_E */
20044 + text.exit PT_LOAD FLAGS(5); /* R_E */
20045 init PT_LOAD FLAGS(7); /* RWE */
20046 -#endif
20047 note PT_NOTE FLAGS(0); /* ___ */
20048 }
20049
20050 SECTIONS
20051 {
20052 #ifdef CONFIG_X86_32
20053 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20054 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20055 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20056 #else
20057 - . = __START_KERNEL;
20058 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20059 + . = __START_KERNEL;
20060 #endif
20061
20062 /* Text and read-only data */
20063 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20064 - _text = .;
20065 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20066 /* bootstrapping code */
20067 +#ifdef CONFIG_X86_32
20068 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20069 +#else
20070 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20071 +#endif
20072 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20073 + _text = .;
20074 HEAD_TEXT
20075 #ifdef CONFIG_X86_32
20076 . = ALIGN(PAGE_SIZE);
20077 @@ -108,13 +128,47 @@ SECTIONS
20078 IRQENTRY_TEXT
20079 *(.fixup)
20080 *(.gnu.warning)
20081 - /* End of text section */
20082 - _etext = .;
20083 } :text = 0x9090
20084
20085 - NOTES :text :note
20086 + . += __KERNEL_TEXT_OFFSET;
20087
20088 - EXCEPTION_TABLE(16) :text = 0x9090
20089 +#ifdef CONFIG_X86_32
20090 + . = ALIGN(PAGE_SIZE);
20091 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20092 +
20093 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20094 + MODULES_EXEC_VADDR = .;
20095 + BYTE(0)
20096 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20097 + . = ALIGN(HPAGE_SIZE);
20098 + MODULES_EXEC_END = . - 1;
20099 +#endif
20100 +
20101 + } :module
20102 +#endif
20103 +
20104 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20105 + /* End of text section */
20106 + _etext = . - __KERNEL_TEXT_OFFSET;
20107 + }
20108 +
20109 +#ifdef CONFIG_X86_32
20110 + . = ALIGN(PAGE_SIZE);
20111 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20112 + *(.idt)
20113 + . = ALIGN(PAGE_SIZE);
20114 + *(.empty_zero_page)
20115 + *(.initial_pg_fixmap)
20116 + *(.initial_pg_pmd)
20117 + *(.initial_page_table)
20118 + *(.swapper_pg_dir)
20119 + } :rodata
20120 +#endif
20121 +
20122 + . = ALIGN(PAGE_SIZE);
20123 + NOTES :rodata :note
20124 +
20125 + EXCEPTION_TABLE(16) :rodata
20126
20127 #if defined(CONFIG_DEBUG_RODATA)
20128 /* .text should occupy whole number of pages */
20129 @@ -126,16 +180,20 @@ SECTIONS
20130
20131 /* Data */
20132 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20133 +
20134 +#ifdef CONFIG_PAX_KERNEXEC
20135 + . = ALIGN(HPAGE_SIZE);
20136 +#else
20137 + . = ALIGN(PAGE_SIZE);
20138 +#endif
20139 +
20140 /* Start of data section */
20141 _sdata = .;
20142
20143 /* init_task */
20144 INIT_TASK_DATA(THREAD_SIZE)
20145
20146 -#ifdef CONFIG_X86_32
20147 - /* 32 bit has nosave before _edata */
20148 NOSAVE_DATA
20149 -#endif
20150
20151 PAGE_ALIGNED_DATA(PAGE_SIZE)
20152
20153 @@ -176,12 +234,19 @@ SECTIONS
20154 #endif /* CONFIG_X86_64 */
20155
20156 /* Init code and data - will be freed after init */
20157 - . = ALIGN(PAGE_SIZE);
20158 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20159 + BYTE(0)
20160 +
20161 +#ifdef CONFIG_PAX_KERNEXEC
20162 + . = ALIGN(HPAGE_SIZE);
20163 +#else
20164 + . = ALIGN(PAGE_SIZE);
20165 +#endif
20166 +
20167 __init_begin = .; /* paired with __init_end */
20168 - }
20169 + } :init.begin
20170
20171 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20172 +#ifdef CONFIG_SMP
20173 /*
20174 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20175 * output PHDR, so the next output section - .init.text - should
20176 @@ -190,12 +255,27 @@ SECTIONS
20177 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20178 #endif
20179
20180 - INIT_TEXT_SECTION(PAGE_SIZE)
20181 -#ifdef CONFIG_X86_64
20182 - :init
20183 -#endif
20184 + . = ALIGN(PAGE_SIZE);
20185 + init_begin = .;
20186 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20187 + VMLINUX_SYMBOL(_sinittext) = .;
20188 + INIT_TEXT
20189 + VMLINUX_SYMBOL(_einittext) = .;
20190 + . = ALIGN(PAGE_SIZE);
20191 + } :text.init
20192
20193 - INIT_DATA_SECTION(16)
20194 + /*
20195 + * .exit.text is discard at runtime, not link time, to deal with
20196 + * references from .altinstructions and .eh_frame
20197 + */
20198 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20199 + EXIT_TEXT
20200 + . = ALIGN(16);
20201 + } :text.exit
20202 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20203 +
20204 + . = ALIGN(PAGE_SIZE);
20205 + INIT_DATA_SECTION(16) :init
20206
20207 /*
20208 * Code and data for a variety of lowlevel trampolines, to be
20209 @@ -269,19 +349,12 @@ SECTIONS
20210 }
20211
20212 . = ALIGN(8);
20213 - /*
20214 - * .exit.text is discard at runtime, not link time, to deal with
20215 - * references from .altinstructions and .eh_frame
20216 - */
20217 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20218 - EXIT_TEXT
20219 - }
20220
20221 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20222 EXIT_DATA
20223 }
20224
20225 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20226 +#ifndef CONFIG_SMP
20227 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20228 #endif
20229
20230 @@ -300,16 +373,10 @@ SECTIONS
20231 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20232 __smp_locks = .;
20233 *(.smp_locks)
20234 - . = ALIGN(PAGE_SIZE);
20235 __smp_locks_end = .;
20236 + . = ALIGN(PAGE_SIZE);
20237 }
20238
20239 -#ifdef CONFIG_X86_64
20240 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20241 - NOSAVE_DATA
20242 - }
20243 -#endif
20244 -
20245 /* BSS */
20246 . = ALIGN(PAGE_SIZE);
20247 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20248 @@ -325,6 +392,7 @@ SECTIONS
20249 __brk_base = .;
20250 . += 64 * 1024; /* 64k alignment slop space */
20251 *(.brk_reservation) /* areas brk users have reserved */
20252 + . = ALIGN(HPAGE_SIZE);
20253 __brk_limit = .;
20254 }
20255
20256 @@ -351,13 +419,12 @@ SECTIONS
20257 * for the boot processor.
20258 */
20259 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20260 -INIT_PER_CPU(gdt_page);
20261 INIT_PER_CPU(irq_stack_union);
20262
20263 /*
20264 * Build-time check on the image size:
20265 */
20266 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20267 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20268 "kernel image bigger than KERNEL_IMAGE_SIZE");
20269
20270 #ifdef CONFIG_SMP
20271 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20272 index 7515cf0..331a1a0 100644
20273 --- a/arch/x86/kernel/vsyscall_64.c
20274 +++ b/arch/x86/kernel/vsyscall_64.c
20275 @@ -54,15 +54,13 @@
20276 DEFINE_VVAR(int, vgetcpu_mode);
20277 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20278
20279 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20280 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20281
20282 static int __init vsyscall_setup(char *str)
20283 {
20284 if (str) {
20285 if (!strcmp("emulate", str))
20286 vsyscall_mode = EMULATE;
20287 - else if (!strcmp("native", str))
20288 - vsyscall_mode = NATIVE;
20289 else if (!strcmp("none", str))
20290 vsyscall_mode = NONE;
20291 else
20292 @@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20293
20294 tsk = current;
20295 if (seccomp_mode(&tsk->seccomp))
20296 - do_exit(SIGKILL);
20297 + do_group_exit(SIGKILL);
20298
20299 /*
20300 * With a real vsyscall, page faults cause SIGSEGV. We want to
20301 @@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20302 return true;
20303
20304 sigsegv:
20305 - force_sig(SIGSEGV, current);
20306 - return true;
20307 + do_group_exit(SIGKILL);
20308 }
20309
20310 /*
20311 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20312 extern char __vvar_page;
20313 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20314
20315 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20316 - vsyscall_mode == NATIVE
20317 - ? PAGE_KERNEL_VSYSCALL
20318 - : PAGE_KERNEL_VVAR);
20319 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20320 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20321 (unsigned long)VSYSCALL_START);
20322
20323 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20324 index 9796c2f..f686fbf 100644
20325 --- a/arch/x86/kernel/x8664_ksyms_64.c
20326 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20327 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20328 EXPORT_SYMBOL(copy_user_generic_string);
20329 EXPORT_SYMBOL(copy_user_generic_unrolled);
20330 EXPORT_SYMBOL(__copy_user_nocache);
20331 -EXPORT_SYMBOL(_copy_from_user);
20332 -EXPORT_SYMBOL(_copy_to_user);
20333
20334 EXPORT_SYMBOL(copy_page);
20335 EXPORT_SYMBOL(clear_page);
20336 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20337 index e62728e..5fc3a07 100644
20338 --- a/arch/x86/kernel/xsave.c
20339 +++ b/arch/x86/kernel/xsave.c
20340 @@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20341 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20342 return -EINVAL;
20343
20344 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20345 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20346 fx_sw_user->extended_size -
20347 FP_XSTATE_MAGIC2_SIZE));
20348 if (err)
20349 @@ -267,7 +267,7 @@ fx_only:
20350 * the other extended state.
20351 */
20352 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20353 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20354 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20355 }
20356
20357 /*
20358 @@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20359 if (use_xsave())
20360 err = restore_user_xstate(buf);
20361 else
20362 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20363 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20364 buf);
20365 if (unlikely(err)) {
20366 /*
20367 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20368 index 9fed5be..18fd595 100644
20369 --- a/arch/x86/kvm/cpuid.c
20370 +++ b/arch/x86/kvm/cpuid.c
20371 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20372 struct kvm_cpuid2 *cpuid,
20373 struct kvm_cpuid_entry2 __user *entries)
20374 {
20375 - int r;
20376 + int r, i;
20377
20378 r = -E2BIG;
20379 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20380 goto out;
20381 r = -EFAULT;
20382 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20383 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20384 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20385 goto out;
20386 + for (i = 0; i < cpuid->nent; ++i) {
20387 + struct kvm_cpuid_entry2 cpuid_entry;
20388 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20389 + goto out;
20390 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20391 + }
20392 vcpu->arch.cpuid_nent = cpuid->nent;
20393 kvm_apic_set_version(vcpu);
20394 kvm_x86_ops->cpuid_update(vcpu);
20395 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20396 struct kvm_cpuid2 *cpuid,
20397 struct kvm_cpuid_entry2 __user *entries)
20398 {
20399 - int r;
20400 + int r, i;
20401
20402 r = -E2BIG;
20403 if (cpuid->nent < vcpu->arch.cpuid_nent)
20404 goto out;
20405 r = -EFAULT;
20406 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20407 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20408 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20409 goto out;
20410 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20411 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20412 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20413 + goto out;
20414 + }
20415 return 0;
20416
20417 out:
20418 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20419 index 8375622..b7bca1a 100644
20420 --- a/arch/x86/kvm/emulate.c
20421 +++ b/arch/x86/kvm/emulate.c
20422 @@ -252,6 +252,7 @@ struct gprefix {
20423
20424 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20425 do { \
20426 + unsigned long _tmp; \
20427 __asm__ __volatile__ ( \
20428 _PRE_EFLAGS("0", "4", "2") \
20429 _op _suffix " %"_x"3,%1; " \
20430 @@ -266,8 +267,6 @@ struct gprefix {
20431 /* Raw emulation: instruction has two explicit operands. */
20432 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20433 do { \
20434 - unsigned long _tmp; \
20435 - \
20436 switch ((ctxt)->dst.bytes) { \
20437 case 2: \
20438 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20439 @@ -283,7 +282,6 @@ struct gprefix {
20440
20441 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20442 do { \
20443 - unsigned long _tmp; \
20444 switch ((ctxt)->dst.bytes) { \
20445 case 1: \
20446 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20447 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20448 index 8584322..17d5955 100644
20449 --- a/arch/x86/kvm/lapic.c
20450 +++ b/arch/x86/kvm/lapic.c
20451 @@ -54,7 +54,7 @@
20452 #define APIC_BUS_CYCLE_NS 1
20453
20454 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20455 -#define apic_debug(fmt, arg...)
20456 +#define apic_debug(fmt, arg...) do {} while (0)
20457
20458 #define APIC_LVT_NUM 6
20459 /* 14 is the version for Xeon and Pentium 8.4.8*/
20460 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20461 index df5a703..63748a7 100644
20462 --- a/arch/x86/kvm/paging_tmpl.h
20463 +++ b/arch/x86/kvm/paging_tmpl.h
20464 @@ -197,7 +197,7 @@ retry_walk:
20465 if (unlikely(kvm_is_error_hva(host_addr)))
20466 goto error;
20467
20468 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20469 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20470 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20471 goto error;
20472
20473 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20474 index e334389..6839087 100644
20475 --- a/arch/x86/kvm/svm.c
20476 +++ b/arch/x86/kvm/svm.c
20477 @@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20478 int cpu = raw_smp_processor_id();
20479
20480 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20481 +
20482 + pax_open_kernel();
20483 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20484 + pax_close_kernel();
20485 +
20486 load_TR_desc();
20487 }
20488
20489 @@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20490 #endif
20491 #endif
20492
20493 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20494 + __set_fs(current_thread_info()->addr_limit);
20495 +#endif
20496 +
20497 reload_tss(vcpu);
20498
20499 local_irq_disable();
20500 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20501 index 4ff0ab9..2ff68d3 100644
20502 --- a/arch/x86/kvm/vmx.c
20503 +++ b/arch/x86/kvm/vmx.c
20504 @@ -1303,7 +1303,11 @@ static void reload_tss(void)
20505 struct desc_struct *descs;
20506
20507 descs = (void *)gdt->address;
20508 +
20509 + pax_open_kernel();
20510 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20511 + pax_close_kernel();
20512 +
20513 load_TR_desc();
20514 }
20515
20516 @@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20517 if (!cpu_has_vmx_flexpriority())
20518 flexpriority_enabled = 0;
20519
20520 - if (!cpu_has_vmx_tpr_shadow())
20521 - kvm_x86_ops->update_cr8_intercept = NULL;
20522 + if (!cpu_has_vmx_tpr_shadow()) {
20523 + pax_open_kernel();
20524 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20525 + pax_close_kernel();
20526 + }
20527
20528 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20529 kvm_disable_largepages();
20530 @@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20531 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20532
20533 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20534 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20535 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20536
20537 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20538 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20539 @@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20540 "jmp .Lkvm_vmx_return \n\t"
20541 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20542 ".Lkvm_vmx_return: "
20543 +
20544 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20545 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20546 + ".Lkvm_vmx_return2: "
20547 +#endif
20548 +
20549 /* Save guest registers, load host registers, keep flags */
20550 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20551 "pop %0 \n\t"
20552 @@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20553 #endif
20554 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20555 [wordsize]"i"(sizeof(ulong))
20556 +
20557 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20558 + ,[cs]"i"(__KERNEL_CS)
20559 +#endif
20560 +
20561 : "cc", "memory"
20562 , R"ax", R"bx", R"di", R"si"
20563 #ifdef CONFIG_X86_64
20564 @@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20565 }
20566 }
20567
20568 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20569 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20570 +
20571 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20572 + loadsegment(fs, __KERNEL_PERCPU);
20573 +#endif
20574 +
20575 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20576 + __set_fs(current_thread_info()->addr_limit);
20577 +#endif
20578 +
20579 vmx->loaded_vmcs->launched = 1;
20580
20581 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20582 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20583 index 185a2b8..866d2a6 100644
20584 --- a/arch/x86/kvm/x86.c
20585 +++ b/arch/x86/kvm/x86.c
20586 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20587 {
20588 struct kvm *kvm = vcpu->kvm;
20589 int lm = is_long_mode(vcpu);
20590 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20591 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20592 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20593 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20594 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20595 : kvm->arch.xen_hvm_config.blob_size_32;
20596 u32 page_num = data & ~PAGE_MASK;
20597 @@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20598 if (n < msr_list.nmsrs)
20599 goto out;
20600 r = -EFAULT;
20601 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20602 + goto out;
20603 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20604 num_msrs_to_save * sizeof(u32)))
20605 goto out;
20606 @@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20607 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20608 struct kvm_interrupt *irq)
20609 {
20610 - if (irq->irq < 0 || irq->irq >= 256)
20611 + if (irq->irq >= 256)
20612 return -EINVAL;
20613 if (irqchip_in_kernel(vcpu->kvm))
20614 return -ENXIO;
20615 @@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20616 kvm_mmu_set_mmio_spte_mask(mask);
20617 }
20618
20619 -int kvm_arch_init(void *opaque)
20620 +int kvm_arch_init(const void *opaque)
20621 {
20622 int r;
20623 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20624 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20625 index 642d880..44e0f3f 100644
20626 --- a/arch/x86/lguest/boot.c
20627 +++ b/arch/x86/lguest/boot.c
20628 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20629 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20630 * Launcher to reboot us.
20631 */
20632 -static void lguest_restart(char *reason)
20633 +static __noreturn void lguest_restart(char *reason)
20634 {
20635 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20636 + BUG();
20637 }
20638
20639 /*G:050
20640 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20641 index 00933d5..3a64af9 100644
20642 --- a/arch/x86/lib/atomic64_386_32.S
20643 +++ b/arch/x86/lib/atomic64_386_32.S
20644 @@ -48,6 +48,10 @@ BEGIN(read)
20645 movl (v), %eax
20646 movl 4(v), %edx
20647 RET_ENDP
20648 +BEGIN(read_unchecked)
20649 + movl (v), %eax
20650 + movl 4(v), %edx
20651 +RET_ENDP
20652 #undef v
20653
20654 #define v %esi
20655 @@ -55,6 +59,10 @@ BEGIN(set)
20656 movl %ebx, (v)
20657 movl %ecx, 4(v)
20658 RET_ENDP
20659 +BEGIN(set_unchecked)
20660 + movl %ebx, (v)
20661 + movl %ecx, 4(v)
20662 +RET_ENDP
20663 #undef v
20664
20665 #define v %esi
20666 @@ -70,6 +78,20 @@ RET_ENDP
20667 BEGIN(add)
20668 addl %eax, (v)
20669 adcl %edx, 4(v)
20670 +
20671 +#ifdef CONFIG_PAX_REFCOUNT
20672 + jno 0f
20673 + subl %eax, (v)
20674 + sbbl %edx, 4(v)
20675 + int $4
20676 +0:
20677 + _ASM_EXTABLE(0b, 0b)
20678 +#endif
20679 +
20680 +RET_ENDP
20681 +BEGIN(add_unchecked)
20682 + addl %eax, (v)
20683 + adcl %edx, 4(v)
20684 RET_ENDP
20685 #undef v
20686
20687 @@ -77,6 +99,24 @@ RET_ENDP
20688 BEGIN(add_return)
20689 addl (v), %eax
20690 adcl 4(v), %edx
20691 +
20692 +#ifdef CONFIG_PAX_REFCOUNT
20693 + into
20694 +1234:
20695 + _ASM_EXTABLE(1234b, 2f)
20696 +#endif
20697 +
20698 + movl %eax, (v)
20699 + movl %edx, 4(v)
20700 +
20701 +#ifdef CONFIG_PAX_REFCOUNT
20702 +2:
20703 +#endif
20704 +
20705 +RET_ENDP
20706 +BEGIN(add_return_unchecked)
20707 + addl (v), %eax
20708 + adcl 4(v), %edx
20709 movl %eax, (v)
20710 movl %edx, 4(v)
20711 RET_ENDP
20712 @@ -86,6 +126,20 @@ RET_ENDP
20713 BEGIN(sub)
20714 subl %eax, (v)
20715 sbbl %edx, 4(v)
20716 +
20717 +#ifdef CONFIG_PAX_REFCOUNT
20718 + jno 0f
20719 + addl %eax, (v)
20720 + adcl %edx, 4(v)
20721 + int $4
20722 +0:
20723 + _ASM_EXTABLE(0b, 0b)
20724 +#endif
20725 +
20726 +RET_ENDP
20727 +BEGIN(sub_unchecked)
20728 + subl %eax, (v)
20729 + sbbl %edx, 4(v)
20730 RET_ENDP
20731 #undef v
20732
20733 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20734 sbbl $0, %edx
20735 addl (v), %eax
20736 adcl 4(v), %edx
20737 +
20738 +#ifdef CONFIG_PAX_REFCOUNT
20739 + into
20740 +1234:
20741 + _ASM_EXTABLE(1234b, 2f)
20742 +#endif
20743 +
20744 + movl %eax, (v)
20745 + movl %edx, 4(v)
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 +2:
20749 +#endif
20750 +
20751 +RET_ENDP
20752 +BEGIN(sub_return_unchecked)
20753 + negl %edx
20754 + negl %eax
20755 + sbbl $0, %edx
20756 + addl (v), %eax
20757 + adcl 4(v), %edx
20758 movl %eax, (v)
20759 movl %edx, 4(v)
20760 RET_ENDP
20761 @@ -105,6 +180,20 @@ RET_ENDP
20762 BEGIN(inc)
20763 addl $1, (v)
20764 adcl $0, 4(v)
20765 +
20766 +#ifdef CONFIG_PAX_REFCOUNT
20767 + jno 0f
20768 + subl $1, (v)
20769 + sbbl $0, 4(v)
20770 + int $4
20771 +0:
20772 + _ASM_EXTABLE(0b, 0b)
20773 +#endif
20774 +
20775 +RET_ENDP
20776 +BEGIN(inc_unchecked)
20777 + addl $1, (v)
20778 + adcl $0, 4(v)
20779 RET_ENDP
20780 #undef v
20781
20782 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20783 movl 4(v), %edx
20784 addl $1, %eax
20785 adcl $0, %edx
20786 +
20787 +#ifdef CONFIG_PAX_REFCOUNT
20788 + into
20789 +1234:
20790 + _ASM_EXTABLE(1234b, 2f)
20791 +#endif
20792 +
20793 + movl %eax, (v)
20794 + movl %edx, 4(v)
20795 +
20796 +#ifdef CONFIG_PAX_REFCOUNT
20797 +2:
20798 +#endif
20799 +
20800 +RET_ENDP
20801 +BEGIN(inc_return_unchecked)
20802 + movl (v), %eax
20803 + movl 4(v), %edx
20804 + addl $1, %eax
20805 + adcl $0, %edx
20806 movl %eax, (v)
20807 movl %edx, 4(v)
20808 RET_ENDP
20809 @@ -123,6 +232,20 @@ RET_ENDP
20810 BEGIN(dec)
20811 subl $1, (v)
20812 sbbl $0, 4(v)
20813 +
20814 +#ifdef CONFIG_PAX_REFCOUNT
20815 + jno 0f
20816 + addl $1, (v)
20817 + adcl $0, 4(v)
20818 + int $4
20819 +0:
20820 + _ASM_EXTABLE(0b, 0b)
20821 +#endif
20822 +
20823 +RET_ENDP
20824 +BEGIN(dec_unchecked)
20825 + subl $1, (v)
20826 + sbbl $0, 4(v)
20827 RET_ENDP
20828 #undef v
20829
20830 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20831 movl 4(v), %edx
20832 subl $1, %eax
20833 sbbl $0, %edx
20834 +
20835 +#ifdef CONFIG_PAX_REFCOUNT
20836 + into
20837 +1234:
20838 + _ASM_EXTABLE(1234b, 2f)
20839 +#endif
20840 +
20841 + movl %eax, (v)
20842 + movl %edx, 4(v)
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 +2:
20846 +#endif
20847 +
20848 +RET_ENDP
20849 +BEGIN(dec_return_unchecked)
20850 + movl (v), %eax
20851 + movl 4(v), %edx
20852 + subl $1, %eax
20853 + sbbl $0, %edx
20854 movl %eax, (v)
20855 movl %edx, 4(v)
20856 RET_ENDP
20857 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20858 adcl %edx, %edi
20859 addl (v), %eax
20860 adcl 4(v), %edx
20861 +
20862 +#ifdef CONFIG_PAX_REFCOUNT
20863 + into
20864 +1234:
20865 + _ASM_EXTABLE(1234b, 2f)
20866 +#endif
20867 +
20868 cmpl %eax, %ecx
20869 je 3f
20870 1:
20871 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20872 1:
20873 addl $1, %eax
20874 adcl $0, %edx
20875 +
20876 +#ifdef CONFIG_PAX_REFCOUNT
20877 + into
20878 +1234:
20879 + _ASM_EXTABLE(1234b, 2f)
20880 +#endif
20881 +
20882 movl %eax, (v)
20883 movl %edx, 4(v)
20884 movl $1, %eax
20885 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889 +
20890 +#ifdef CONFIG_PAX_REFCOUNT
20891 + into
20892 +1234:
20893 + _ASM_EXTABLE(1234b, 1f)
20894 +#endif
20895 +
20896 js 1f
20897 movl %eax, (v)
20898 movl %edx, 4(v)
20899 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20900 index f5cc9eb..51fa319 100644
20901 --- a/arch/x86/lib/atomic64_cx8_32.S
20902 +++ b/arch/x86/lib/atomic64_cx8_32.S
20903 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20904 CFI_STARTPROC
20905
20906 read64 %ecx
20907 + pax_force_retaddr
20908 ret
20909 CFI_ENDPROC
20910 ENDPROC(atomic64_read_cx8)
20911
20912 +ENTRY(atomic64_read_unchecked_cx8)
20913 + CFI_STARTPROC
20914 +
20915 + read64 %ecx
20916 + pax_force_retaddr
20917 + ret
20918 + CFI_ENDPROC
20919 +ENDPROC(atomic64_read_unchecked_cx8)
20920 +
20921 ENTRY(atomic64_set_cx8)
20922 CFI_STARTPROC
20923
20924 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20925 cmpxchg8b (%esi)
20926 jne 1b
20927
20928 + pax_force_retaddr
20929 ret
20930 CFI_ENDPROC
20931 ENDPROC(atomic64_set_cx8)
20932
20933 +ENTRY(atomic64_set_unchecked_cx8)
20934 + CFI_STARTPROC
20935 +
20936 +1:
20937 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20938 + * are atomic on 586 and newer */
20939 + cmpxchg8b (%esi)
20940 + jne 1b
20941 +
20942 + pax_force_retaddr
20943 + ret
20944 + CFI_ENDPROC
20945 +ENDPROC(atomic64_set_unchecked_cx8)
20946 +
20947 ENTRY(atomic64_xchg_cx8)
20948 CFI_STARTPROC
20949
20950 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20951 cmpxchg8b (%esi)
20952 jne 1b
20953
20954 + pax_force_retaddr
20955 ret
20956 CFI_ENDPROC
20957 ENDPROC(atomic64_xchg_cx8)
20958
20959 -.macro addsub_return func ins insc
20960 -ENTRY(atomic64_\func\()_return_cx8)
20961 +.macro addsub_return func ins insc unchecked=""
20962 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20963 CFI_STARTPROC
20964 SAVE ebp
20965 SAVE ebx
20966 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20967 movl %edx, %ecx
20968 \ins\()l %esi, %ebx
20969 \insc\()l %edi, %ecx
20970 +
20971 +.ifb \unchecked
20972 +#ifdef CONFIG_PAX_REFCOUNT
20973 + into
20974 +2:
20975 + _ASM_EXTABLE(2b, 3f)
20976 +#endif
20977 +.endif
20978 +
20979 LOCK_PREFIX
20980 cmpxchg8b (%ebp)
20981 jne 1b
20982 -
20983 -10:
20984 movl %ebx, %eax
20985 movl %ecx, %edx
20986 +
20987 +.ifb \unchecked
20988 +#ifdef CONFIG_PAX_REFCOUNT
20989 +3:
20990 +#endif
20991 +.endif
20992 +
20993 RESTORE edi
20994 RESTORE esi
20995 RESTORE ebx
20996 RESTORE ebp
20997 + pax_force_retaddr
20998 ret
20999 CFI_ENDPROC
21000 -ENDPROC(atomic64_\func\()_return_cx8)
21001 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21002 .endm
21003
21004 addsub_return add add adc
21005 addsub_return sub sub sbb
21006 +addsub_return add add adc _unchecked
21007 +addsub_return sub sub sbb _unchecked
21008
21009 -.macro incdec_return func ins insc
21010 -ENTRY(atomic64_\func\()_return_cx8)
21011 +.macro incdec_return func ins insc unchecked=""
21012 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21013 CFI_STARTPROC
21014 SAVE ebx
21015
21016 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21017 movl %edx, %ecx
21018 \ins\()l $1, %ebx
21019 \insc\()l $0, %ecx
21020 +
21021 +.ifb \unchecked
21022 +#ifdef CONFIG_PAX_REFCOUNT
21023 + into
21024 +2:
21025 + _ASM_EXTABLE(2b, 3f)
21026 +#endif
21027 +.endif
21028 +
21029 LOCK_PREFIX
21030 cmpxchg8b (%esi)
21031 jne 1b
21032
21033 -10:
21034 movl %ebx, %eax
21035 movl %ecx, %edx
21036 +
21037 +.ifb \unchecked
21038 +#ifdef CONFIG_PAX_REFCOUNT
21039 +3:
21040 +#endif
21041 +.endif
21042 +
21043 RESTORE ebx
21044 + pax_force_retaddr
21045 ret
21046 CFI_ENDPROC
21047 -ENDPROC(atomic64_\func\()_return_cx8)
21048 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21049 .endm
21050
21051 incdec_return inc add adc
21052 incdec_return dec sub sbb
21053 +incdec_return inc add adc _unchecked
21054 +incdec_return dec sub sbb _unchecked
21055
21056 ENTRY(atomic64_dec_if_positive_cx8)
21057 CFI_STARTPROC
21058 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21059 movl %edx, %ecx
21060 subl $1, %ebx
21061 sbb $0, %ecx
21062 +
21063 +#ifdef CONFIG_PAX_REFCOUNT
21064 + into
21065 +1234:
21066 + _ASM_EXTABLE(1234b, 2f)
21067 +#endif
21068 +
21069 js 2f
21070 LOCK_PREFIX
21071 cmpxchg8b (%esi)
21072 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21073 movl %ebx, %eax
21074 movl %ecx, %edx
21075 RESTORE ebx
21076 + pax_force_retaddr
21077 ret
21078 CFI_ENDPROC
21079 ENDPROC(atomic64_dec_if_positive_cx8)
21080 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21081 movl %edx, %ecx
21082 addl %ebp, %ebx
21083 adcl %edi, %ecx
21084 +
21085 +#ifdef CONFIG_PAX_REFCOUNT
21086 + into
21087 +1234:
21088 + _ASM_EXTABLE(1234b, 3f)
21089 +#endif
21090 +
21091 LOCK_PREFIX
21092 cmpxchg8b (%esi)
21093 jne 1b
21094 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21095 CFI_ADJUST_CFA_OFFSET -8
21096 RESTORE ebx
21097 RESTORE ebp
21098 + pax_force_retaddr
21099 ret
21100 4:
21101 cmpl %edx, 4(%esp)
21102 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21103 xorl %ecx, %ecx
21104 addl $1, %ebx
21105 adcl %edx, %ecx
21106 +
21107 +#ifdef CONFIG_PAX_REFCOUNT
21108 + into
21109 +1234:
21110 + _ASM_EXTABLE(1234b, 3f)
21111 +#endif
21112 +
21113 LOCK_PREFIX
21114 cmpxchg8b (%esi)
21115 jne 1b
21116 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21117 movl $1, %eax
21118 3:
21119 RESTORE ebx
21120 + pax_force_retaddr
21121 ret
21122 CFI_ENDPROC
21123 ENDPROC(atomic64_inc_not_zero_cx8)
21124 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21125 index 78d16a5..fbcf666 100644
21126 --- a/arch/x86/lib/checksum_32.S
21127 +++ b/arch/x86/lib/checksum_32.S
21128 @@ -28,7 +28,8 @@
21129 #include <linux/linkage.h>
21130 #include <asm/dwarf2.h>
21131 #include <asm/errno.h>
21132 -
21133 +#include <asm/segment.h>
21134 +
21135 /*
21136 * computes a partial checksum, e.g. for TCP/UDP fragments
21137 */
21138 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21139
21140 #define ARGBASE 16
21141 #define FP 12
21142 -
21143 -ENTRY(csum_partial_copy_generic)
21144 +
21145 +ENTRY(csum_partial_copy_generic_to_user)
21146 CFI_STARTPROC
21147 +
21148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21149 + pushl_cfi %gs
21150 + popl_cfi %es
21151 + jmp csum_partial_copy_generic
21152 +#endif
21153 +
21154 +ENTRY(csum_partial_copy_generic_from_user)
21155 +
21156 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21157 + pushl_cfi %gs
21158 + popl_cfi %ds
21159 +#endif
21160 +
21161 +ENTRY(csum_partial_copy_generic)
21162 subl $4,%esp
21163 CFI_ADJUST_CFA_OFFSET 4
21164 pushl_cfi %edi
21165 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21166 jmp 4f
21167 SRC(1: movw (%esi), %bx )
21168 addl $2, %esi
21169 -DST( movw %bx, (%edi) )
21170 +DST( movw %bx, %es:(%edi) )
21171 addl $2, %edi
21172 addw %bx, %ax
21173 adcl $0, %eax
21174 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21175 SRC(1: movl (%esi), %ebx )
21176 SRC( movl 4(%esi), %edx )
21177 adcl %ebx, %eax
21178 -DST( movl %ebx, (%edi) )
21179 +DST( movl %ebx, %es:(%edi) )
21180 adcl %edx, %eax
21181 -DST( movl %edx, 4(%edi) )
21182 +DST( movl %edx, %es:4(%edi) )
21183
21184 SRC( movl 8(%esi), %ebx )
21185 SRC( movl 12(%esi), %edx )
21186 adcl %ebx, %eax
21187 -DST( movl %ebx, 8(%edi) )
21188 +DST( movl %ebx, %es:8(%edi) )
21189 adcl %edx, %eax
21190 -DST( movl %edx, 12(%edi) )
21191 +DST( movl %edx, %es:12(%edi) )
21192
21193 SRC( movl 16(%esi), %ebx )
21194 SRC( movl 20(%esi), %edx )
21195 adcl %ebx, %eax
21196 -DST( movl %ebx, 16(%edi) )
21197 +DST( movl %ebx, %es:16(%edi) )
21198 adcl %edx, %eax
21199 -DST( movl %edx, 20(%edi) )
21200 +DST( movl %edx, %es:20(%edi) )
21201
21202 SRC( movl 24(%esi), %ebx )
21203 SRC( movl 28(%esi), %edx )
21204 adcl %ebx, %eax
21205 -DST( movl %ebx, 24(%edi) )
21206 +DST( movl %ebx, %es:24(%edi) )
21207 adcl %edx, %eax
21208 -DST( movl %edx, 28(%edi) )
21209 +DST( movl %edx, %es:28(%edi) )
21210
21211 lea 32(%esi), %esi
21212 lea 32(%edi), %edi
21213 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21214 shrl $2, %edx # This clears CF
21215 SRC(3: movl (%esi), %ebx )
21216 adcl %ebx, %eax
21217 -DST( movl %ebx, (%edi) )
21218 +DST( movl %ebx, %es:(%edi) )
21219 lea 4(%esi), %esi
21220 lea 4(%edi), %edi
21221 dec %edx
21222 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21223 jb 5f
21224 SRC( movw (%esi), %cx )
21225 leal 2(%esi), %esi
21226 -DST( movw %cx, (%edi) )
21227 +DST( movw %cx, %es:(%edi) )
21228 leal 2(%edi), %edi
21229 je 6f
21230 shll $16,%ecx
21231 SRC(5: movb (%esi), %cl )
21232 -DST( movb %cl, (%edi) )
21233 +DST( movb %cl, %es:(%edi) )
21234 6: addl %ecx, %eax
21235 adcl $0, %eax
21236 7:
21237 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21238
21239 6001:
21240 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21241 - movl $-EFAULT, (%ebx)
21242 + movl $-EFAULT, %ss:(%ebx)
21243
21244 # zero the complete destination - computing the rest
21245 # is too much work
21246 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21247
21248 6002:
21249 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21250 - movl $-EFAULT,(%ebx)
21251 + movl $-EFAULT,%ss:(%ebx)
21252 jmp 5000b
21253
21254 .previous
21255
21256 + pushl_cfi %ss
21257 + popl_cfi %ds
21258 + pushl_cfi %ss
21259 + popl_cfi %es
21260 popl_cfi %ebx
21261 CFI_RESTORE ebx
21262 popl_cfi %esi
21263 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21264 popl_cfi %ecx # equivalent to addl $4,%esp
21265 ret
21266 CFI_ENDPROC
21267 -ENDPROC(csum_partial_copy_generic)
21268 +ENDPROC(csum_partial_copy_generic_to_user)
21269
21270 #else
21271
21272 /* Version for PentiumII/PPro */
21273
21274 #define ROUND1(x) \
21275 + nop; nop; nop; \
21276 SRC(movl x(%esi), %ebx ) ; \
21277 addl %ebx, %eax ; \
21278 - DST(movl %ebx, x(%edi) ) ;
21279 + DST(movl %ebx, %es:x(%edi)) ;
21280
21281 #define ROUND(x) \
21282 + nop; nop; nop; \
21283 SRC(movl x(%esi), %ebx ) ; \
21284 adcl %ebx, %eax ; \
21285 - DST(movl %ebx, x(%edi) ) ;
21286 + DST(movl %ebx, %es:x(%edi)) ;
21287
21288 #define ARGBASE 12
21289 -
21290 -ENTRY(csum_partial_copy_generic)
21291 +
21292 +ENTRY(csum_partial_copy_generic_to_user)
21293 CFI_STARTPROC
21294 +
21295 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21296 + pushl_cfi %gs
21297 + popl_cfi %es
21298 + jmp csum_partial_copy_generic
21299 +#endif
21300 +
21301 +ENTRY(csum_partial_copy_generic_from_user)
21302 +
21303 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21304 + pushl_cfi %gs
21305 + popl_cfi %ds
21306 +#endif
21307 +
21308 +ENTRY(csum_partial_copy_generic)
21309 pushl_cfi %ebx
21310 CFI_REL_OFFSET ebx, 0
21311 pushl_cfi %edi
21312 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21313 subl %ebx, %edi
21314 lea -1(%esi),%edx
21315 andl $-32,%edx
21316 - lea 3f(%ebx,%ebx), %ebx
21317 + lea 3f(%ebx,%ebx,2), %ebx
21318 testl %esi, %esi
21319 jmp *%ebx
21320 1: addl $64,%esi
21321 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21322 jb 5f
21323 SRC( movw (%esi), %dx )
21324 leal 2(%esi), %esi
21325 -DST( movw %dx, (%edi) )
21326 +DST( movw %dx, %es:(%edi) )
21327 leal 2(%edi), %edi
21328 je 6f
21329 shll $16,%edx
21330 5:
21331 SRC( movb (%esi), %dl )
21332 -DST( movb %dl, (%edi) )
21333 +DST( movb %dl, %es:(%edi) )
21334 6: addl %edx, %eax
21335 adcl $0, %eax
21336 7:
21337 .section .fixup, "ax"
21338 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21339 - movl $-EFAULT, (%ebx)
21340 + movl $-EFAULT, %ss:(%ebx)
21341 # zero the complete destination (computing the rest is too much work)
21342 movl ARGBASE+8(%esp),%edi # dst
21343 movl ARGBASE+12(%esp),%ecx # len
21344 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21345 rep; stosb
21346 jmp 7b
21347 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21348 - movl $-EFAULT, (%ebx)
21349 + movl $-EFAULT, %ss:(%ebx)
21350 jmp 7b
21351 .previous
21352
21353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21354 + pushl_cfi %ss
21355 + popl_cfi %ds
21356 + pushl_cfi %ss
21357 + popl_cfi %es
21358 +#endif
21359 +
21360 popl_cfi %esi
21361 CFI_RESTORE esi
21362 popl_cfi %edi
21363 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21364 CFI_RESTORE ebx
21365 ret
21366 CFI_ENDPROC
21367 -ENDPROC(csum_partial_copy_generic)
21368 +ENDPROC(csum_partial_copy_generic_to_user)
21369
21370 #undef ROUND
21371 #undef ROUND1
21372 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21373 index f2145cf..cea889d 100644
21374 --- a/arch/x86/lib/clear_page_64.S
21375 +++ b/arch/x86/lib/clear_page_64.S
21376 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21377 movl $4096/8,%ecx
21378 xorl %eax,%eax
21379 rep stosq
21380 + pax_force_retaddr
21381 ret
21382 CFI_ENDPROC
21383 ENDPROC(clear_page_c)
21384 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21385 movl $4096,%ecx
21386 xorl %eax,%eax
21387 rep stosb
21388 + pax_force_retaddr
21389 ret
21390 CFI_ENDPROC
21391 ENDPROC(clear_page_c_e)
21392 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21393 leaq 64(%rdi),%rdi
21394 jnz .Lloop
21395 nop
21396 + pax_force_retaddr
21397 ret
21398 CFI_ENDPROC
21399 .Lclear_page_end:
21400 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21401
21402 #include <asm/cpufeature.h>
21403
21404 - .section .altinstr_replacement,"ax"
21405 + .section .altinstr_replacement,"a"
21406 1: .byte 0xeb /* jmp <disp8> */
21407 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21408 2: .byte 0xeb /* jmp <disp8> */
21409 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21410 index 1e572c5..2a162cd 100644
21411 --- a/arch/x86/lib/cmpxchg16b_emu.S
21412 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21413 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21414
21415 popf
21416 mov $1, %al
21417 + pax_force_retaddr
21418 ret
21419
21420 not_same:
21421 popf
21422 xor %al,%al
21423 + pax_force_retaddr
21424 ret
21425
21426 CFI_ENDPROC
21427 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21428 index 6b34d04..dccb07f 100644
21429 --- a/arch/x86/lib/copy_page_64.S
21430 +++ b/arch/x86/lib/copy_page_64.S
21431 @@ -9,6 +9,7 @@ copy_page_c:
21432 CFI_STARTPROC
21433 movl $4096/8,%ecx
21434 rep movsq
21435 + pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(copy_page_c)
21439 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21440
21441 ENTRY(copy_page)
21442 CFI_STARTPROC
21443 - subq $2*8,%rsp
21444 - CFI_ADJUST_CFA_OFFSET 2*8
21445 + subq $3*8,%rsp
21446 + CFI_ADJUST_CFA_OFFSET 3*8
21447 movq %rbx,(%rsp)
21448 CFI_REL_OFFSET rbx, 0
21449 movq %r12,1*8(%rsp)
21450 CFI_REL_OFFSET r12, 1*8
21451 + movq %r13,2*8(%rsp)
21452 + CFI_REL_OFFSET r13, 2*8
21453
21454 movl $(4096/64)-5,%ecx
21455 .p2align 4
21456 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21457 movq 16 (%rsi), %rdx
21458 movq 24 (%rsi), %r8
21459 movq 32 (%rsi), %r9
21460 - movq 40 (%rsi), %r10
21461 + movq 40 (%rsi), %r13
21462 movq 48 (%rsi), %r11
21463 movq 56 (%rsi), %r12
21464
21465 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21466 movq %rdx, 16 (%rdi)
21467 movq %r8, 24 (%rdi)
21468 movq %r9, 32 (%rdi)
21469 - movq %r10, 40 (%rdi)
21470 + movq %r13, 40 (%rdi)
21471 movq %r11, 48 (%rdi)
21472 movq %r12, 56 (%rdi)
21473
21474 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21475 movq 16 (%rsi), %rdx
21476 movq 24 (%rsi), %r8
21477 movq 32 (%rsi), %r9
21478 - movq 40 (%rsi), %r10
21479 + movq 40 (%rsi), %r13
21480 movq 48 (%rsi), %r11
21481 movq 56 (%rsi), %r12
21482
21483 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21484 movq %rdx, 16 (%rdi)
21485 movq %r8, 24 (%rdi)
21486 movq %r9, 32 (%rdi)
21487 - movq %r10, 40 (%rdi)
21488 + movq %r13, 40 (%rdi)
21489 movq %r11, 48 (%rdi)
21490 movq %r12, 56 (%rdi)
21491
21492 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21493 CFI_RESTORE rbx
21494 movq 1*8(%rsp),%r12
21495 CFI_RESTORE r12
21496 - addq $2*8,%rsp
21497 - CFI_ADJUST_CFA_OFFSET -2*8
21498 + movq 2*8(%rsp),%r13
21499 + CFI_RESTORE r13
21500 + addq $3*8,%rsp
21501 + CFI_ADJUST_CFA_OFFSET -3*8
21502 + pax_force_retaddr
21503 ret
21504 .Lcopy_page_end:
21505 CFI_ENDPROC
21506 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21507
21508 #include <asm/cpufeature.h>
21509
21510 - .section .altinstr_replacement,"ax"
21511 + .section .altinstr_replacement,"a"
21512 1: .byte 0xeb /* jmp <disp8> */
21513 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21514 2:
21515 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21516 index 0248402..821c786 100644
21517 --- a/arch/x86/lib/copy_user_64.S
21518 +++ b/arch/x86/lib/copy_user_64.S
21519 @@ -16,6 +16,7 @@
21520 #include <asm/thread_info.h>
21521 #include <asm/cpufeature.h>
21522 #include <asm/alternative-asm.h>
21523 +#include <asm/pgtable.h>
21524
21525 /*
21526 * By placing feature2 after feature1 in altinstructions section, we logically
21527 @@ -29,7 +30,7 @@
21528 .byte 0xe9 /* 32bit jump */
21529 .long \orig-1f /* by default jump to orig */
21530 1:
21531 - .section .altinstr_replacement,"ax"
21532 + .section .altinstr_replacement,"a"
21533 2: .byte 0xe9 /* near jump with 32bit immediate */
21534 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21535 3: .byte 0xe9 /* near jump with 32bit immediate */
21536 @@ -71,47 +72,20 @@
21537 #endif
21538 .endm
21539
21540 -/* Standard copy_to_user with segment limit checking */
21541 -ENTRY(_copy_to_user)
21542 - CFI_STARTPROC
21543 - GET_THREAD_INFO(%rax)
21544 - movq %rdi,%rcx
21545 - addq %rdx,%rcx
21546 - jc bad_to_user
21547 - cmpq TI_addr_limit(%rax),%rcx
21548 - ja bad_to_user
21549 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21550 - copy_user_generic_unrolled,copy_user_generic_string, \
21551 - copy_user_enhanced_fast_string
21552 - CFI_ENDPROC
21553 -ENDPROC(_copy_to_user)
21554 -
21555 -/* Standard copy_from_user with segment limit checking */
21556 -ENTRY(_copy_from_user)
21557 - CFI_STARTPROC
21558 - GET_THREAD_INFO(%rax)
21559 - movq %rsi,%rcx
21560 - addq %rdx,%rcx
21561 - jc bad_from_user
21562 - cmpq TI_addr_limit(%rax),%rcx
21563 - ja bad_from_user
21564 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21565 - copy_user_generic_unrolled,copy_user_generic_string, \
21566 - copy_user_enhanced_fast_string
21567 - CFI_ENDPROC
21568 -ENDPROC(_copy_from_user)
21569 -
21570 .section .fixup,"ax"
21571 /* must zero dest */
21572 ENTRY(bad_from_user)
21573 bad_from_user:
21574 CFI_STARTPROC
21575 + testl %edx,%edx
21576 + js bad_to_user
21577 movl %edx,%ecx
21578 xorl %eax,%eax
21579 rep
21580 stosb
21581 bad_to_user:
21582 movl %edx,%eax
21583 + pax_force_retaddr
21584 ret
21585 CFI_ENDPROC
21586 ENDPROC(bad_from_user)
21587 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21588 jz 17f
21589 1: movq (%rsi),%r8
21590 2: movq 1*8(%rsi),%r9
21591 -3: movq 2*8(%rsi),%r10
21592 +3: movq 2*8(%rsi),%rax
21593 4: movq 3*8(%rsi),%r11
21594 5: movq %r8,(%rdi)
21595 6: movq %r9,1*8(%rdi)
21596 -7: movq %r10,2*8(%rdi)
21597 +7: movq %rax,2*8(%rdi)
21598 8: movq %r11,3*8(%rdi)
21599 9: movq 4*8(%rsi),%r8
21600 10: movq 5*8(%rsi),%r9
21601 -11: movq 6*8(%rsi),%r10
21602 +11: movq 6*8(%rsi),%rax
21603 12: movq 7*8(%rsi),%r11
21604 13: movq %r8,4*8(%rdi)
21605 14: movq %r9,5*8(%rdi)
21606 -15: movq %r10,6*8(%rdi)
21607 +15: movq %rax,6*8(%rdi)
21608 16: movq %r11,7*8(%rdi)
21609 leaq 64(%rsi),%rsi
21610 leaq 64(%rdi),%rdi
21611 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21612 decl %ecx
21613 jnz 21b
21614 23: xor %eax,%eax
21615 + pax_force_retaddr
21616 ret
21617
21618 .section .fixup,"ax"
21619 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21620 3: rep
21621 movsb
21622 4: xorl %eax,%eax
21623 + pax_force_retaddr
21624 ret
21625
21626 .section .fixup,"ax"
21627 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21628 1: rep
21629 movsb
21630 2: xorl %eax,%eax
21631 + pax_force_retaddr
21632 ret
21633
21634 .section .fixup,"ax"
21635 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21636 index cb0c112..e3a6895 100644
21637 --- a/arch/x86/lib/copy_user_nocache_64.S
21638 +++ b/arch/x86/lib/copy_user_nocache_64.S
21639 @@ -8,12 +8,14 @@
21640
21641 #include <linux/linkage.h>
21642 #include <asm/dwarf2.h>
21643 +#include <asm/alternative-asm.h>
21644
21645 #define FIX_ALIGNMENT 1
21646
21647 #include <asm/current.h>
21648 #include <asm/asm-offsets.h>
21649 #include <asm/thread_info.h>
21650 +#include <asm/pgtable.h>
21651
21652 .macro ALIGN_DESTINATION
21653 #ifdef FIX_ALIGNMENT
21654 @@ -50,6 +52,15 @@
21655 */
21656 ENTRY(__copy_user_nocache)
21657 CFI_STARTPROC
21658 +
21659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21660 + mov $PAX_USER_SHADOW_BASE,%rcx
21661 + cmp %rcx,%rsi
21662 + jae 1f
21663 + add %rcx,%rsi
21664 +1:
21665 +#endif
21666 +
21667 cmpl $8,%edx
21668 jb 20f /* less then 8 bytes, go to byte copy loop */
21669 ALIGN_DESTINATION
21670 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21671 jz 17f
21672 1: movq (%rsi),%r8
21673 2: movq 1*8(%rsi),%r9
21674 -3: movq 2*8(%rsi),%r10
21675 +3: movq 2*8(%rsi),%rax
21676 4: movq 3*8(%rsi),%r11
21677 5: movnti %r8,(%rdi)
21678 6: movnti %r9,1*8(%rdi)
21679 -7: movnti %r10,2*8(%rdi)
21680 +7: movnti %rax,2*8(%rdi)
21681 8: movnti %r11,3*8(%rdi)
21682 9: movq 4*8(%rsi),%r8
21683 10: movq 5*8(%rsi),%r9
21684 -11: movq 6*8(%rsi),%r10
21685 +11: movq 6*8(%rsi),%rax
21686 12: movq 7*8(%rsi),%r11
21687 13: movnti %r8,4*8(%rdi)
21688 14: movnti %r9,5*8(%rdi)
21689 -15: movnti %r10,6*8(%rdi)
21690 +15: movnti %rax,6*8(%rdi)
21691 16: movnti %r11,7*8(%rdi)
21692 leaq 64(%rsi),%rsi
21693 leaq 64(%rdi),%rdi
21694 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21695 jnz 21b
21696 23: xorl %eax,%eax
21697 sfence
21698 + pax_force_retaddr
21699 ret
21700
21701 .section .fixup,"ax"
21702 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21703 index fb903b7..c92b7f7 100644
21704 --- a/arch/x86/lib/csum-copy_64.S
21705 +++ b/arch/x86/lib/csum-copy_64.S
21706 @@ -8,6 +8,7 @@
21707 #include <linux/linkage.h>
21708 #include <asm/dwarf2.h>
21709 #include <asm/errno.h>
21710 +#include <asm/alternative-asm.h>
21711
21712 /*
21713 * Checksum copy with exception handling.
21714 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21715 CFI_RESTORE rbp
21716 addq $7*8, %rsp
21717 CFI_ADJUST_CFA_OFFSET -7*8
21718 + pax_force_retaddr 0, 1
21719 ret
21720 CFI_RESTORE_STATE
21721
21722 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21723 index 459b58a..9570bc7 100644
21724 --- a/arch/x86/lib/csum-wrappers_64.c
21725 +++ b/arch/x86/lib/csum-wrappers_64.c
21726 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21727 len -= 2;
21728 }
21729 }
21730 - isum = csum_partial_copy_generic((__force const void *)src,
21731 +
21732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21733 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21734 + src += PAX_USER_SHADOW_BASE;
21735 +#endif
21736 +
21737 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21738 dst, len, isum, errp, NULL);
21739 if (unlikely(*errp))
21740 goto out_err;
21741 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21742 }
21743
21744 *errp = 0;
21745 - return csum_partial_copy_generic(src, (void __force *)dst,
21746 +
21747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21748 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21749 + dst += PAX_USER_SHADOW_BASE;
21750 +#endif
21751 +
21752 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21753 len, isum, NULL, errp);
21754 }
21755 EXPORT_SYMBOL(csum_partial_copy_to_user);
21756 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21757 index 51f1504..ddac4c1 100644
21758 --- a/arch/x86/lib/getuser.S
21759 +++ b/arch/x86/lib/getuser.S
21760 @@ -33,15 +33,38 @@
21761 #include <asm/asm-offsets.h>
21762 #include <asm/thread_info.h>
21763 #include <asm/asm.h>
21764 +#include <asm/segment.h>
21765 +#include <asm/pgtable.h>
21766 +#include <asm/alternative-asm.h>
21767 +
21768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21769 +#define __copyuser_seg gs;
21770 +#else
21771 +#define __copyuser_seg
21772 +#endif
21773
21774 .text
21775 ENTRY(__get_user_1)
21776 CFI_STARTPROC
21777 +
21778 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21779 GET_THREAD_INFO(%_ASM_DX)
21780 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21781 jae bad_get_user
21782 -1: movzb (%_ASM_AX),%edx
21783 +
21784 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21785 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21786 + cmp %_ASM_DX,%_ASM_AX
21787 + jae 1234f
21788 + add %_ASM_DX,%_ASM_AX
21789 +1234:
21790 +#endif
21791 +
21792 +#endif
21793 +
21794 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21795 xor %eax,%eax
21796 + pax_force_retaddr
21797 ret
21798 CFI_ENDPROC
21799 ENDPROC(__get_user_1)
21800 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21801 ENTRY(__get_user_2)
21802 CFI_STARTPROC
21803 add $1,%_ASM_AX
21804 +
21805 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21806 jc bad_get_user
21807 GET_THREAD_INFO(%_ASM_DX)
21808 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21809 jae bad_get_user
21810 -2: movzwl -1(%_ASM_AX),%edx
21811 +
21812 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21813 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21814 + cmp %_ASM_DX,%_ASM_AX
21815 + jae 1234f
21816 + add %_ASM_DX,%_ASM_AX
21817 +1234:
21818 +#endif
21819 +
21820 +#endif
21821 +
21822 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21823 xor %eax,%eax
21824 + pax_force_retaddr
21825 ret
21826 CFI_ENDPROC
21827 ENDPROC(__get_user_2)
21828 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21829 ENTRY(__get_user_4)
21830 CFI_STARTPROC
21831 add $3,%_ASM_AX
21832 +
21833 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21834 jc bad_get_user
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838 -3: mov -3(%_ASM_AX),%edx
21839 +
21840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842 + cmp %_ASM_DX,%_ASM_AX
21843 + jae 1234f
21844 + add %_ASM_DX,%_ASM_AX
21845 +1234:
21846 +#endif
21847 +
21848 +#endif
21849 +
21850 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21851 xor %eax,%eax
21852 + pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_4)
21856 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21857 GET_THREAD_INFO(%_ASM_DX)
21858 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21859 jae bad_get_user
21860 +
21861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21862 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21863 + cmp %_ASM_DX,%_ASM_AX
21864 + jae 1234f
21865 + add %_ASM_DX,%_ASM_AX
21866 +1234:
21867 +#endif
21868 +
21869 4: movq -7(%_ASM_AX),%_ASM_DX
21870 xor %eax,%eax
21871 + pax_force_retaddr
21872 ret
21873 CFI_ENDPROC
21874 ENDPROC(__get_user_8)
21875 @@ -91,6 +152,7 @@ bad_get_user:
21876 CFI_STARTPROC
21877 xor %edx,%edx
21878 mov $(-EFAULT),%_ASM_AX
21879 + pax_force_retaddr
21880 ret
21881 CFI_ENDPROC
21882 END(bad_get_user)
21883 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21884 index b1e6c4b..21ae8fc 100644
21885 --- a/arch/x86/lib/insn.c
21886 +++ b/arch/x86/lib/insn.c
21887 @@ -21,6 +21,11 @@
21888 #include <linux/string.h>
21889 #include <asm/inat.h>
21890 #include <asm/insn.h>
21891 +#ifdef __KERNEL__
21892 +#include <asm/pgtable_types.h>
21893 +#else
21894 +#define ktla_ktva(addr) addr
21895 +#endif
21896
21897 /* Verify next sizeof(t) bytes can be on the same instruction */
21898 #define validate_next(t, insn, n) \
21899 @@ -49,8 +54,8 @@
21900 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21901 {
21902 memset(insn, 0, sizeof(*insn));
21903 - insn->kaddr = kaddr;
21904 - insn->next_byte = kaddr;
21905 + insn->kaddr = ktla_ktva(kaddr);
21906 + insn->next_byte = ktla_ktva(kaddr);
21907 insn->x86_64 = x86_64 ? 1 : 0;
21908 insn->opnd_bytes = 4;
21909 if (x86_64)
21910 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21911 index 05a95e7..326f2fa 100644
21912 --- a/arch/x86/lib/iomap_copy_64.S
21913 +++ b/arch/x86/lib/iomap_copy_64.S
21914 @@ -17,6 +17,7 @@
21915
21916 #include <linux/linkage.h>
21917 #include <asm/dwarf2.h>
21918 +#include <asm/alternative-asm.h>
21919
21920 /*
21921 * override generic version in lib/iomap_copy.c
21922 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21923 CFI_STARTPROC
21924 movl %edx,%ecx
21925 rep movsd
21926 + pax_force_retaddr
21927 ret
21928 CFI_ENDPROC
21929 ENDPROC(__iowrite32_copy)
21930 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21931 index 1c273be..da9cc0e 100644
21932 --- a/arch/x86/lib/memcpy_64.S
21933 +++ b/arch/x86/lib/memcpy_64.S
21934 @@ -33,6 +33,7 @@
21935 rep movsq
21936 movl %edx, %ecx
21937 rep movsb
21938 + pax_force_retaddr
21939 ret
21940 .Lmemcpy_e:
21941 .previous
21942 @@ -49,6 +50,7 @@
21943 movq %rdi, %rax
21944 movq %rdx, %rcx
21945 rep movsb
21946 + pax_force_retaddr
21947 ret
21948 .Lmemcpy_e_e:
21949 .previous
21950 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21951 */
21952 movq 0*8(%rsi), %r8
21953 movq 1*8(%rsi), %r9
21954 - movq 2*8(%rsi), %r10
21955 + movq 2*8(%rsi), %rcx
21956 movq 3*8(%rsi), %r11
21957 leaq 4*8(%rsi), %rsi
21958
21959 movq %r8, 0*8(%rdi)
21960 movq %r9, 1*8(%rdi)
21961 - movq %r10, 2*8(%rdi)
21962 + movq %rcx, 2*8(%rdi)
21963 movq %r11, 3*8(%rdi)
21964 leaq 4*8(%rdi), %rdi
21965 jae .Lcopy_forward_loop
21966 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21967 subq $0x20, %rdx
21968 movq -1*8(%rsi), %r8
21969 movq -2*8(%rsi), %r9
21970 - movq -3*8(%rsi), %r10
21971 + movq -3*8(%rsi), %rcx
21972 movq -4*8(%rsi), %r11
21973 leaq -4*8(%rsi), %rsi
21974 movq %r8, -1*8(%rdi)
21975 movq %r9, -2*8(%rdi)
21976 - movq %r10, -3*8(%rdi)
21977 + movq %rcx, -3*8(%rdi)
21978 movq %r11, -4*8(%rdi)
21979 leaq -4*8(%rdi), %rdi
21980 jae .Lcopy_backward_loop
21981 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21982 */
21983 movq 0*8(%rsi), %r8
21984 movq 1*8(%rsi), %r9
21985 - movq -2*8(%rsi, %rdx), %r10
21986 + movq -2*8(%rsi, %rdx), %rcx
21987 movq -1*8(%rsi, %rdx), %r11
21988 movq %r8, 0*8(%rdi)
21989 movq %r9, 1*8(%rdi)
21990 - movq %r10, -2*8(%rdi, %rdx)
21991 + movq %rcx, -2*8(%rdi, %rdx)
21992 movq %r11, -1*8(%rdi, %rdx)
21993 + pax_force_retaddr
21994 retq
21995 .p2align 4
21996 .Lless_16bytes:
21997 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21998 movq -1*8(%rsi, %rdx), %r9
21999 movq %r8, 0*8(%rdi)
22000 movq %r9, -1*8(%rdi, %rdx)
22001 + pax_force_retaddr
22002 retq
22003 .p2align 4
22004 .Lless_8bytes:
22005 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22006 movl -4(%rsi, %rdx), %r8d
22007 movl %ecx, (%rdi)
22008 movl %r8d, -4(%rdi, %rdx)
22009 + pax_force_retaddr
22010 retq
22011 .p2align 4
22012 .Lless_3bytes:
22013 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22014 movb %cl, (%rdi)
22015
22016 .Lend:
22017 + pax_force_retaddr
22018 retq
22019 CFI_ENDPROC
22020 ENDPROC(memcpy)
22021 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22022 index ee16461..c39c199 100644
22023 --- a/arch/x86/lib/memmove_64.S
22024 +++ b/arch/x86/lib/memmove_64.S
22025 @@ -61,13 +61,13 @@ ENTRY(memmove)
22026 5:
22027 sub $0x20, %rdx
22028 movq 0*8(%rsi), %r11
22029 - movq 1*8(%rsi), %r10
22030 + movq 1*8(%rsi), %rcx
22031 movq 2*8(%rsi), %r9
22032 movq 3*8(%rsi), %r8
22033 leaq 4*8(%rsi), %rsi
22034
22035 movq %r11, 0*8(%rdi)
22036 - movq %r10, 1*8(%rdi)
22037 + movq %rcx, 1*8(%rdi)
22038 movq %r9, 2*8(%rdi)
22039 movq %r8, 3*8(%rdi)
22040 leaq 4*8(%rdi), %rdi
22041 @@ -81,10 +81,10 @@ ENTRY(memmove)
22042 4:
22043 movq %rdx, %rcx
22044 movq -8(%rsi, %rdx), %r11
22045 - lea -8(%rdi, %rdx), %r10
22046 + lea -8(%rdi, %rdx), %r9
22047 shrq $3, %rcx
22048 rep movsq
22049 - movq %r11, (%r10)
22050 + movq %r11, (%r9)
22051 jmp 13f
22052 .Lmemmove_end_forward:
22053
22054 @@ -95,14 +95,14 @@ ENTRY(memmove)
22055 7:
22056 movq %rdx, %rcx
22057 movq (%rsi), %r11
22058 - movq %rdi, %r10
22059 + movq %rdi, %r9
22060 leaq -8(%rsi, %rdx), %rsi
22061 leaq -8(%rdi, %rdx), %rdi
22062 shrq $3, %rcx
22063 std
22064 rep movsq
22065 cld
22066 - movq %r11, (%r10)
22067 + movq %r11, (%r9)
22068 jmp 13f
22069
22070 /*
22071 @@ -127,13 +127,13 @@ ENTRY(memmove)
22072 8:
22073 subq $0x20, %rdx
22074 movq -1*8(%rsi), %r11
22075 - movq -2*8(%rsi), %r10
22076 + movq -2*8(%rsi), %rcx
22077 movq -3*8(%rsi), %r9
22078 movq -4*8(%rsi), %r8
22079 leaq -4*8(%rsi), %rsi
22080
22081 movq %r11, -1*8(%rdi)
22082 - movq %r10, -2*8(%rdi)
22083 + movq %rcx, -2*8(%rdi)
22084 movq %r9, -3*8(%rdi)
22085 movq %r8, -4*8(%rdi)
22086 leaq -4*8(%rdi), %rdi
22087 @@ -151,11 +151,11 @@ ENTRY(memmove)
22088 * Move data from 16 bytes to 31 bytes.
22089 */
22090 movq 0*8(%rsi), %r11
22091 - movq 1*8(%rsi), %r10
22092 + movq 1*8(%rsi), %rcx
22093 movq -2*8(%rsi, %rdx), %r9
22094 movq -1*8(%rsi, %rdx), %r8
22095 movq %r11, 0*8(%rdi)
22096 - movq %r10, 1*8(%rdi)
22097 + movq %rcx, 1*8(%rdi)
22098 movq %r9, -2*8(%rdi, %rdx)
22099 movq %r8, -1*8(%rdi, %rdx)
22100 jmp 13f
22101 @@ -167,9 +167,9 @@ ENTRY(memmove)
22102 * Move data from 8 bytes to 15 bytes.
22103 */
22104 movq 0*8(%rsi), %r11
22105 - movq -1*8(%rsi, %rdx), %r10
22106 + movq -1*8(%rsi, %rdx), %r9
22107 movq %r11, 0*8(%rdi)
22108 - movq %r10, -1*8(%rdi, %rdx)
22109 + movq %r9, -1*8(%rdi, %rdx)
22110 jmp 13f
22111 10:
22112 cmpq $4, %rdx
22113 @@ -178,9 +178,9 @@ ENTRY(memmove)
22114 * Move data from 4 bytes to 7 bytes.
22115 */
22116 movl (%rsi), %r11d
22117 - movl -4(%rsi, %rdx), %r10d
22118 + movl -4(%rsi, %rdx), %r9d
22119 movl %r11d, (%rdi)
22120 - movl %r10d, -4(%rdi, %rdx)
22121 + movl %r9d, -4(%rdi, %rdx)
22122 jmp 13f
22123 11:
22124 cmp $2, %rdx
22125 @@ -189,9 +189,9 @@ ENTRY(memmove)
22126 * Move data from 2 bytes to 3 bytes.
22127 */
22128 movw (%rsi), %r11w
22129 - movw -2(%rsi, %rdx), %r10w
22130 + movw -2(%rsi, %rdx), %r9w
22131 movw %r11w, (%rdi)
22132 - movw %r10w, -2(%rdi, %rdx)
22133 + movw %r9w, -2(%rdi, %rdx)
22134 jmp 13f
22135 12:
22136 cmp $1, %rdx
22137 @@ -202,6 +202,7 @@ ENTRY(memmove)
22138 movb (%rsi), %r11b
22139 movb %r11b, (%rdi)
22140 13:
22141 + pax_force_retaddr
22142 retq
22143 CFI_ENDPROC
22144
22145 @@ -210,6 +211,7 @@ ENTRY(memmove)
22146 /* Forward moving data. */
22147 movq %rdx, %rcx
22148 rep movsb
22149 + pax_force_retaddr
22150 retq
22151 .Lmemmove_end_forward_efs:
22152 .previous
22153 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22154 index 2dcb380..963660a 100644
22155 --- a/arch/x86/lib/memset_64.S
22156 +++ b/arch/x86/lib/memset_64.S
22157 @@ -30,6 +30,7 @@
22158 movl %edx,%ecx
22159 rep stosb
22160 movq %r9,%rax
22161 + pax_force_retaddr
22162 ret
22163 .Lmemset_e:
22164 .previous
22165 @@ -52,6 +53,7 @@
22166 movq %rdx,%rcx
22167 rep stosb
22168 movq %r9,%rax
22169 + pax_force_retaddr
22170 ret
22171 .Lmemset_e_e:
22172 .previous
22173 @@ -59,7 +61,7 @@
22174 ENTRY(memset)
22175 ENTRY(__memset)
22176 CFI_STARTPROC
22177 - movq %rdi,%r10
22178 + movq %rdi,%r11
22179
22180 /* expand byte value */
22181 movzbl %sil,%ecx
22182 @@ -117,7 +119,8 @@ ENTRY(__memset)
22183 jnz .Lloop_1
22184
22185 .Lende:
22186 - movq %r10,%rax
22187 + movq %r11,%rax
22188 + pax_force_retaddr
22189 ret
22190
22191 CFI_RESTORE_STATE
22192 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22193 index c9f2d9b..e7fd2c0 100644
22194 --- a/arch/x86/lib/mmx_32.c
22195 +++ b/arch/x86/lib/mmx_32.c
22196 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22197 {
22198 void *p;
22199 int i;
22200 + unsigned long cr0;
22201
22202 if (unlikely(in_interrupt()))
22203 return __memcpy(to, from, len);
22204 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22205 kernel_fpu_begin();
22206
22207 __asm__ __volatile__ (
22208 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22209 - " prefetch 64(%0)\n"
22210 - " prefetch 128(%0)\n"
22211 - " prefetch 192(%0)\n"
22212 - " prefetch 256(%0)\n"
22213 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22214 + " prefetch 64(%1)\n"
22215 + " prefetch 128(%1)\n"
22216 + " prefetch 192(%1)\n"
22217 + " prefetch 256(%1)\n"
22218 "2: \n"
22219 ".section .fixup, \"ax\"\n"
22220 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22221 + "3: \n"
22222 +
22223 +#ifdef CONFIG_PAX_KERNEXEC
22224 + " movl %%cr0, %0\n"
22225 + " movl %0, %%eax\n"
22226 + " andl $0xFFFEFFFF, %%eax\n"
22227 + " movl %%eax, %%cr0\n"
22228 +#endif
22229 +
22230 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22231 +
22232 +#ifdef CONFIG_PAX_KERNEXEC
22233 + " movl %0, %%cr0\n"
22234 +#endif
22235 +
22236 " jmp 2b\n"
22237 ".previous\n"
22238 _ASM_EXTABLE(1b, 3b)
22239 - : : "r" (from));
22240 + : "=&r" (cr0) : "r" (from) : "ax");
22241
22242 for ( ; i > 5; i--) {
22243 __asm__ __volatile__ (
22244 - "1: prefetch 320(%0)\n"
22245 - "2: movq (%0), %%mm0\n"
22246 - " movq 8(%0), %%mm1\n"
22247 - " movq 16(%0), %%mm2\n"
22248 - " movq 24(%0), %%mm3\n"
22249 - " movq %%mm0, (%1)\n"
22250 - " movq %%mm1, 8(%1)\n"
22251 - " movq %%mm2, 16(%1)\n"
22252 - " movq %%mm3, 24(%1)\n"
22253 - " movq 32(%0), %%mm0\n"
22254 - " movq 40(%0), %%mm1\n"
22255 - " movq 48(%0), %%mm2\n"
22256 - " movq 56(%0), %%mm3\n"
22257 - " movq %%mm0, 32(%1)\n"
22258 - " movq %%mm1, 40(%1)\n"
22259 - " movq %%mm2, 48(%1)\n"
22260 - " movq %%mm3, 56(%1)\n"
22261 + "1: prefetch 320(%1)\n"
22262 + "2: movq (%1), %%mm0\n"
22263 + " movq 8(%1), %%mm1\n"
22264 + " movq 16(%1), %%mm2\n"
22265 + " movq 24(%1), %%mm3\n"
22266 + " movq %%mm0, (%2)\n"
22267 + " movq %%mm1, 8(%2)\n"
22268 + " movq %%mm2, 16(%2)\n"
22269 + " movq %%mm3, 24(%2)\n"
22270 + " movq 32(%1), %%mm0\n"
22271 + " movq 40(%1), %%mm1\n"
22272 + " movq 48(%1), %%mm2\n"
22273 + " movq 56(%1), %%mm3\n"
22274 + " movq %%mm0, 32(%2)\n"
22275 + " movq %%mm1, 40(%2)\n"
22276 + " movq %%mm2, 48(%2)\n"
22277 + " movq %%mm3, 56(%2)\n"
22278 ".section .fixup, \"ax\"\n"
22279 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22280 + "3:\n"
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + " movl %%cr0, %0\n"
22284 + " movl %0, %%eax\n"
22285 + " andl $0xFFFEFFFF, %%eax\n"
22286 + " movl %%eax, %%cr0\n"
22287 +#endif
22288 +
22289 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22290 +
22291 +#ifdef CONFIG_PAX_KERNEXEC
22292 + " movl %0, %%cr0\n"
22293 +#endif
22294 +
22295 " jmp 2b\n"
22296 ".previous\n"
22297 _ASM_EXTABLE(1b, 3b)
22298 - : : "r" (from), "r" (to) : "memory");
22299 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22300
22301 from += 64;
22302 to += 64;
22303 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22304 static void fast_copy_page(void *to, void *from)
22305 {
22306 int i;
22307 + unsigned long cr0;
22308
22309 kernel_fpu_begin();
22310
22311 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22312 * but that is for later. -AV
22313 */
22314 __asm__ __volatile__(
22315 - "1: prefetch (%0)\n"
22316 - " prefetch 64(%0)\n"
22317 - " prefetch 128(%0)\n"
22318 - " prefetch 192(%0)\n"
22319 - " prefetch 256(%0)\n"
22320 + "1: prefetch (%1)\n"
22321 + " prefetch 64(%1)\n"
22322 + " prefetch 128(%1)\n"
22323 + " prefetch 192(%1)\n"
22324 + " prefetch 256(%1)\n"
22325 "2: \n"
22326 ".section .fixup, \"ax\"\n"
22327 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22328 + "3: \n"
22329 +
22330 +#ifdef CONFIG_PAX_KERNEXEC
22331 + " movl %%cr0, %0\n"
22332 + " movl %0, %%eax\n"
22333 + " andl $0xFFFEFFFF, %%eax\n"
22334 + " movl %%eax, %%cr0\n"
22335 +#endif
22336 +
22337 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22338 +
22339 +#ifdef CONFIG_PAX_KERNEXEC
22340 + " movl %0, %%cr0\n"
22341 +#endif
22342 +
22343 " jmp 2b\n"
22344 ".previous\n"
22345 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22346 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22347
22348 for (i = 0; i < (4096-320)/64; i++) {
22349 __asm__ __volatile__ (
22350 - "1: prefetch 320(%0)\n"
22351 - "2: movq (%0), %%mm0\n"
22352 - " movntq %%mm0, (%1)\n"
22353 - " movq 8(%0), %%mm1\n"
22354 - " movntq %%mm1, 8(%1)\n"
22355 - " movq 16(%0), %%mm2\n"
22356 - " movntq %%mm2, 16(%1)\n"
22357 - " movq 24(%0), %%mm3\n"
22358 - " movntq %%mm3, 24(%1)\n"
22359 - " movq 32(%0), %%mm4\n"
22360 - " movntq %%mm4, 32(%1)\n"
22361 - " movq 40(%0), %%mm5\n"
22362 - " movntq %%mm5, 40(%1)\n"
22363 - " movq 48(%0), %%mm6\n"
22364 - " movntq %%mm6, 48(%1)\n"
22365 - " movq 56(%0), %%mm7\n"
22366 - " movntq %%mm7, 56(%1)\n"
22367 + "1: prefetch 320(%1)\n"
22368 + "2: movq (%1), %%mm0\n"
22369 + " movntq %%mm0, (%2)\n"
22370 + " movq 8(%1), %%mm1\n"
22371 + " movntq %%mm1, 8(%2)\n"
22372 + " movq 16(%1), %%mm2\n"
22373 + " movntq %%mm2, 16(%2)\n"
22374 + " movq 24(%1), %%mm3\n"
22375 + " movntq %%mm3, 24(%2)\n"
22376 + " movq 32(%1), %%mm4\n"
22377 + " movntq %%mm4, 32(%2)\n"
22378 + " movq 40(%1), %%mm5\n"
22379 + " movntq %%mm5, 40(%2)\n"
22380 + " movq 48(%1), %%mm6\n"
22381 + " movntq %%mm6, 48(%2)\n"
22382 + " movq 56(%1), %%mm7\n"
22383 + " movntq %%mm7, 56(%2)\n"
22384 ".section .fixup, \"ax\"\n"
22385 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22386 + "3:\n"
22387 +
22388 +#ifdef CONFIG_PAX_KERNEXEC
22389 + " movl %%cr0, %0\n"
22390 + " movl %0, %%eax\n"
22391 + " andl $0xFFFEFFFF, %%eax\n"
22392 + " movl %%eax, %%cr0\n"
22393 +#endif
22394 +
22395 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22396 +
22397 +#ifdef CONFIG_PAX_KERNEXEC
22398 + " movl %0, %%cr0\n"
22399 +#endif
22400 +
22401 " jmp 2b\n"
22402 ".previous\n"
22403 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22404 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22405
22406 from += 64;
22407 to += 64;
22408 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22409 static void fast_copy_page(void *to, void *from)
22410 {
22411 int i;
22412 + unsigned long cr0;
22413
22414 kernel_fpu_begin();
22415
22416 __asm__ __volatile__ (
22417 - "1: prefetch (%0)\n"
22418 - " prefetch 64(%0)\n"
22419 - " prefetch 128(%0)\n"
22420 - " prefetch 192(%0)\n"
22421 - " prefetch 256(%0)\n"
22422 + "1: prefetch (%1)\n"
22423 + " prefetch 64(%1)\n"
22424 + " prefetch 128(%1)\n"
22425 + " prefetch 192(%1)\n"
22426 + " prefetch 256(%1)\n"
22427 "2: \n"
22428 ".section .fixup, \"ax\"\n"
22429 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22430 + "3: \n"
22431 +
22432 +#ifdef CONFIG_PAX_KERNEXEC
22433 + " movl %%cr0, %0\n"
22434 + " movl %0, %%eax\n"
22435 + " andl $0xFFFEFFFF, %%eax\n"
22436 + " movl %%eax, %%cr0\n"
22437 +#endif
22438 +
22439 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22440 +
22441 +#ifdef CONFIG_PAX_KERNEXEC
22442 + " movl %0, %%cr0\n"
22443 +#endif
22444 +
22445 " jmp 2b\n"
22446 ".previous\n"
22447 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22448 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22449
22450 for (i = 0; i < 4096/64; i++) {
22451 __asm__ __volatile__ (
22452 - "1: prefetch 320(%0)\n"
22453 - "2: movq (%0), %%mm0\n"
22454 - " movq 8(%0), %%mm1\n"
22455 - " movq 16(%0), %%mm2\n"
22456 - " movq 24(%0), %%mm3\n"
22457 - " movq %%mm0, (%1)\n"
22458 - " movq %%mm1, 8(%1)\n"
22459 - " movq %%mm2, 16(%1)\n"
22460 - " movq %%mm3, 24(%1)\n"
22461 - " movq 32(%0), %%mm0\n"
22462 - " movq 40(%0), %%mm1\n"
22463 - " movq 48(%0), %%mm2\n"
22464 - " movq 56(%0), %%mm3\n"
22465 - " movq %%mm0, 32(%1)\n"
22466 - " movq %%mm1, 40(%1)\n"
22467 - " movq %%mm2, 48(%1)\n"
22468 - " movq %%mm3, 56(%1)\n"
22469 + "1: prefetch 320(%1)\n"
22470 + "2: movq (%1), %%mm0\n"
22471 + " movq 8(%1), %%mm1\n"
22472 + " movq 16(%1), %%mm2\n"
22473 + " movq 24(%1), %%mm3\n"
22474 + " movq %%mm0, (%2)\n"
22475 + " movq %%mm1, 8(%2)\n"
22476 + " movq %%mm2, 16(%2)\n"
22477 + " movq %%mm3, 24(%2)\n"
22478 + " movq 32(%1), %%mm0\n"
22479 + " movq 40(%1), %%mm1\n"
22480 + " movq 48(%1), %%mm2\n"
22481 + " movq 56(%1), %%mm3\n"
22482 + " movq %%mm0, 32(%2)\n"
22483 + " movq %%mm1, 40(%2)\n"
22484 + " movq %%mm2, 48(%2)\n"
22485 + " movq %%mm3, 56(%2)\n"
22486 ".section .fixup, \"ax\"\n"
22487 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22488 + "3:\n"
22489 +
22490 +#ifdef CONFIG_PAX_KERNEXEC
22491 + " movl %%cr0, %0\n"
22492 + " movl %0, %%eax\n"
22493 + " andl $0xFFFEFFFF, %%eax\n"
22494 + " movl %%eax, %%cr0\n"
22495 +#endif
22496 +
22497 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22498 +
22499 +#ifdef CONFIG_PAX_KERNEXEC
22500 + " movl %0, %%cr0\n"
22501 +#endif
22502 +
22503 " jmp 2b\n"
22504 ".previous\n"
22505 _ASM_EXTABLE(1b, 3b)
22506 - : : "r" (from), "r" (to) : "memory");
22507 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22508
22509 from += 64;
22510 to += 64;
22511 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22512 index 69fa106..adda88b 100644
22513 --- a/arch/x86/lib/msr-reg.S
22514 +++ b/arch/x86/lib/msr-reg.S
22515 @@ -3,6 +3,7 @@
22516 #include <asm/dwarf2.h>
22517 #include <asm/asm.h>
22518 #include <asm/msr.h>
22519 +#include <asm/alternative-asm.h>
22520
22521 #ifdef CONFIG_X86_64
22522 /*
22523 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22524 CFI_STARTPROC
22525 pushq_cfi %rbx
22526 pushq_cfi %rbp
22527 - movq %rdi, %r10 /* Save pointer */
22528 + movq %rdi, %r9 /* Save pointer */
22529 xorl %r11d, %r11d /* Return value */
22530 movl (%rdi), %eax
22531 movl 4(%rdi), %ecx
22532 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22533 movl 28(%rdi), %edi
22534 CFI_REMEMBER_STATE
22535 1: \op
22536 -2: movl %eax, (%r10)
22537 +2: movl %eax, (%r9)
22538 movl %r11d, %eax /* Return value */
22539 - movl %ecx, 4(%r10)
22540 - movl %edx, 8(%r10)
22541 - movl %ebx, 12(%r10)
22542 - movl %ebp, 20(%r10)
22543 - movl %esi, 24(%r10)
22544 - movl %edi, 28(%r10)
22545 + movl %ecx, 4(%r9)
22546 + movl %edx, 8(%r9)
22547 + movl %ebx, 12(%r9)
22548 + movl %ebp, 20(%r9)
22549 + movl %esi, 24(%r9)
22550 + movl %edi, 28(%r9)
22551 popq_cfi %rbp
22552 popq_cfi %rbx
22553 + pax_force_retaddr
22554 ret
22555 3:
22556 CFI_RESTORE_STATE
22557 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22558 index 36b0d15..d381858 100644
22559 --- a/arch/x86/lib/putuser.S
22560 +++ b/arch/x86/lib/putuser.S
22561 @@ -15,7 +15,9 @@
22562 #include <asm/thread_info.h>
22563 #include <asm/errno.h>
22564 #include <asm/asm.h>
22565 -
22566 +#include <asm/segment.h>
22567 +#include <asm/pgtable.h>
22568 +#include <asm/alternative-asm.h>
22569
22570 /*
22571 * __put_user_X
22572 @@ -29,52 +31,119 @@
22573 * as they get called from within inline assembly.
22574 */
22575
22576 -#define ENTER CFI_STARTPROC ; \
22577 - GET_THREAD_INFO(%_ASM_BX)
22578 -#define EXIT ret ; \
22579 +#define ENTER CFI_STARTPROC
22580 +#define EXIT pax_force_retaddr; ret ; \
22581 CFI_ENDPROC
22582
22583 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22584 +#define _DEST %_ASM_CX,%_ASM_BX
22585 +#else
22586 +#define _DEST %_ASM_CX
22587 +#endif
22588 +
22589 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22590 +#define __copyuser_seg gs;
22591 +#else
22592 +#define __copyuser_seg
22593 +#endif
22594 +
22595 .text
22596 ENTRY(__put_user_1)
22597 ENTER
22598 +
22599 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22600 + GET_THREAD_INFO(%_ASM_BX)
22601 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22602 jae bad_put_user
22603 -1: movb %al,(%_ASM_CX)
22604 +
22605 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22606 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22607 + cmp %_ASM_BX,%_ASM_CX
22608 + jb 1234f
22609 + xor %ebx,%ebx
22610 +1234:
22611 +#endif
22612 +
22613 +#endif
22614 +
22615 +1: __copyuser_seg movb %al,(_DEST)
22616 xor %eax,%eax
22617 EXIT
22618 ENDPROC(__put_user_1)
22619
22620 ENTRY(__put_user_2)
22621 ENTER
22622 +
22623 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22624 + GET_THREAD_INFO(%_ASM_BX)
22625 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22626 sub $1,%_ASM_BX
22627 cmp %_ASM_BX,%_ASM_CX
22628 jae bad_put_user
22629 -2: movw %ax,(%_ASM_CX)
22630 +
22631 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22632 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22633 + cmp %_ASM_BX,%_ASM_CX
22634 + jb 1234f
22635 + xor %ebx,%ebx
22636 +1234:
22637 +#endif
22638 +
22639 +#endif
22640 +
22641 +2: __copyuser_seg movw %ax,(_DEST)
22642 xor %eax,%eax
22643 EXIT
22644 ENDPROC(__put_user_2)
22645
22646 ENTRY(__put_user_4)
22647 ENTER
22648 +
22649 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22650 + GET_THREAD_INFO(%_ASM_BX)
22651 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22652 sub $3,%_ASM_BX
22653 cmp %_ASM_BX,%_ASM_CX
22654 jae bad_put_user
22655 -3: movl %eax,(%_ASM_CX)
22656 +
22657 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22658 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22659 + cmp %_ASM_BX,%_ASM_CX
22660 + jb 1234f
22661 + xor %ebx,%ebx
22662 +1234:
22663 +#endif
22664 +
22665 +#endif
22666 +
22667 +3: __copyuser_seg movl %eax,(_DEST)
22668 xor %eax,%eax
22669 EXIT
22670 ENDPROC(__put_user_4)
22671
22672 ENTRY(__put_user_8)
22673 ENTER
22674 +
22675 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22676 + GET_THREAD_INFO(%_ASM_BX)
22677 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22678 sub $7,%_ASM_BX
22679 cmp %_ASM_BX,%_ASM_CX
22680 jae bad_put_user
22681 -4: mov %_ASM_AX,(%_ASM_CX)
22682 +
22683 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22684 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22685 + cmp %_ASM_BX,%_ASM_CX
22686 + jb 1234f
22687 + xor %ebx,%ebx
22688 +1234:
22689 +#endif
22690 +
22691 +#endif
22692 +
22693 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22694 #ifdef CONFIG_X86_32
22695 -5: movl %edx,4(%_ASM_CX)
22696 +5: __copyuser_seg movl %edx,4(_DEST)
22697 #endif
22698 xor %eax,%eax
22699 EXIT
22700 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22701 index 1cad221..de671ee 100644
22702 --- a/arch/x86/lib/rwlock.S
22703 +++ b/arch/x86/lib/rwlock.S
22704 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22705 FRAME
22706 0: LOCK_PREFIX
22707 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22708 +
22709 +#ifdef CONFIG_PAX_REFCOUNT
22710 + jno 1234f
22711 + LOCK_PREFIX
22712 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22713 + int $4
22714 +1234:
22715 + _ASM_EXTABLE(1234b, 1234b)
22716 +#endif
22717 +
22718 1: rep; nop
22719 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22720 jne 1b
22721 LOCK_PREFIX
22722 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22723 +
22724 +#ifdef CONFIG_PAX_REFCOUNT
22725 + jno 1234f
22726 + LOCK_PREFIX
22727 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22728 + int $4
22729 +1234:
22730 + _ASM_EXTABLE(1234b, 1234b)
22731 +#endif
22732 +
22733 jnz 0b
22734 ENDFRAME
22735 + pax_force_retaddr
22736 ret
22737 CFI_ENDPROC
22738 END(__write_lock_failed)
22739 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22740 FRAME
22741 0: LOCK_PREFIX
22742 READ_LOCK_SIZE(inc) (%__lock_ptr)
22743 +
22744 +#ifdef CONFIG_PAX_REFCOUNT
22745 + jno 1234f
22746 + LOCK_PREFIX
22747 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22748 + int $4
22749 +1234:
22750 + _ASM_EXTABLE(1234b, 1234b)
22751 +#endif
22752 +
22753 1: rep; nop
22754 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22755 js 1b
22756 LOCK_PREFIX
22757 READ_LOCK_SIZE(dec) (%__lock_ptr)
22758 +
22759 +#ifdef CONFIG_PAX_REFCOUNT
22760 + jno 1234f
22761 + LOCK_PREFIX
22762 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22763 + int $4
22764 +1234:
22765 + _ASM_EXTABLE(1234b, 1234b)
22766 +#endif
22767 +
22768 js 0b
22769 ENDFRAME
22770 + pax_force_retaddr
22771 ret
22772 CFI_ENDPROC
22773 END(__read_lock_failed)
22774 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22775 index 5dff5f0..cadebf4 100644
22776 --- a/arch/x86/lib/rwsem.S
22777 +++ b/arch/x86/lib/rwsem.S
22778 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22779 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22780 CFI_RESTORE __ASM_REG(dx)
22781 restore_common_regs
22782 + pax_force_retaddr
22783 ret
22784 CFI_ENDPROC
22785 ENDPROC(call_rwsem_down_read_failed)
22786 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22787 movq %rax,%rdi
22788 call rwsem_down_write_failed
22789 restore_common_regs
22790 + pax_force_retaddr
22791 ret
22792 CFI_ENDPROC
22793 ENDPROC(call_rwsem_down_write_failed)
22794 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22795 movq %rax,%rdi
22796 call rwsem_wake
22797 restore_common_regs
22798 -1: ret
22799 +1: pax_force_retaddr
22800 + ret
22801 CFI_ENDPROC
22802 ENDPROC(call_rwsem_wake)
22803
22804 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22805 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22806 CFI_RESTORE __ASM_REG(dx)
22807 restore_common_regs
22808 + pax_force_retaddr
22809 ret
22810 CFI_ENDPROC
22811 ENDPROC(call_rwsem_downgrade_wake)
22812 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22813 index a63efd6..ccecad8 100644
22814 --- a/arch/x86/lib/thunk_64.S
22815 +++ b/arch/x86/lib/thunk_64.S
22816 @@ -8,6 +8,7 @@
22817 #include <linux/linkage.h>
22818 #include <asm/dwarf2.h>
22819 #include <asm/calling.h>
22820 +#include <asm/alternative-asm.h>
22821
22822 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22823 .macro THUNK name, func, put_ret_addr_in_rdi=0
22824 @@ -41,5 +42,6 @@
22825 SAVE_ARGS
22826 restore:
22827 RESTORE_ARGS
22828 + pax_force_retaddr
22829 ret
22830 CFI_ENDPROC
22831 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22832 index ef2a6a5..3b28862 100644
22833 --- a/arch/x86/lib/usercopy_32.c
22834 +++ b/arch/x86/lib/usercopy_32.c
22835 @@ -41,10 +41,12 @@ do { \
22836 int __d0; \
22837 might_fault(); \
22838 __asm__ __volatile__( \
22839 + __COPYUSER_SET_ES \
22840 "0: rep; stosl\n" \
22841 " movl %2,%0\n" \
22842 "1: rep; stosb\n" \
22843 "2:\n" \
22844 + __COPYUSER_RESTORE_ES \
22845 ".section .fixup,\"ax\"\n" \
22846 "3: lea 0(%2,%0,4),%0\n" \
22847 " jmp 2b\n" \
22848 @@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22849 might_fault();
22850
22851 __asm__ __volatile__(
22852 + __COPYUSER_SET_ES
22853 " testl %0, %0\n"
22854 " jz 3f\n"
22855 " andl %0,%%ecx\n"
22856 @@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22857 " subl %%ecx,%0\n"
22858 " addl %0,%%eax\n"
22859 "1:\n"
22860 + __COPYUSER_RESTORE_ES
22861 ".section .fixup,\"ax\"\n"
22862 "2: xorl %%eax,%%eax\n"
22863 " jmp 1b\n"
22864 @@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22865
22866 #ifdef CONFIG_X86_INTEL_USERCOPY
22867 static unsigned long
22868 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22869 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22870 {
22871 int d0, d1;
22872 __asm__ __volatile__(
22873 @@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22874 " .align 2,0x90\n"
22875 "3: movl 0(%4), %%eax\n"
22876 "4: movl 4(%4), %%edx\n"
22877 - "5: movl %%eax, 0(%3)\n"
22878 - "6: movl %%edx, 4(%3)\n"
22879 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22880 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22881 "7: movl 8(%4), %%eax\n"
22882 "8: movl 12(%4),%%edx\n"
22883 - "9: movl %%eax, 8(%3)\n"
22884 - "10: movl %%edx, 12(%3)\n"
22885 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22886 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22887 "11: movl 16(%4), %%eax\n"
22888 "12: movl 20(%4), %%edx\n"
22889 - "13: movl %%eax, 16(%3)\n"
22890 - "14: movl %%edx, 20(%3)\n"
22891 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22892 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22893 "15: movl 24(%4), %%eax\n"
22894 "16: movl 28(%4), %%edx\n"
22895 - "17: movl %%eax, 24(%3)\n"
22896 - "18: movl %%edx, 28(%3)\n"
22897 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22898 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22899 "19: movl 32(%4), %%eax\n"
22900 "20: movl 36(%4), %%edx\n"
22901 - "21: movl %%eax, 32(%3)\n"
22902 - "22: movl %%edx, 36(%3)\n"
22903 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22904 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22905 "23: movl 40(%4), %%eax\n"
22906 "24: movl 44(%4), %%edx\n"
22907 - "25: movl %%eax, 40(%3)\n"
22908 - "26: movl %%edx, 44(%3)\n"
22909 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22910 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22911 "27: movl 48(%4), %%eax\n"
22912 "28: movl 52(%4), %%edx\n"
22913 - "29: movl %%eax, 48(%3)\n"
22914 - "30: movl %%edx, 52(%3)\n"
22915 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22916 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22917 "31: movl 56(%4), %%eax\n"
22918 "32: movl 60(%4), %%edx\n"
22919 - "33: movl %%eax, 56(%3)\n"
22920 - "34: movl %%edx, 60(%3)\n"
22921 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22922 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22923 " addl $-64, %0\n"
22924 " addl $64, %4\n"
22925 " addl $64, %3\n"
22926 @@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22927 " shrl $2, %0\n"
22928 " andl $3, %%eax\n"
22929 " cld\n"
22930 + __COPYUSER_SET_ES
22931 "99: rep; movsl\n"
22932 "36: movl %%eax, %0\n"
22933 "37: rep; movsb\n"
22934 "100:\n"
22935 + __COPYUSER_RESTORE_ES
22936 ".section .fixup,\"ax\"\n"
22937 "101: lea 0(%%eax,%0,4),%0\n"
22938 " jmp 100b\n"
22939 @@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22940 }
22941
22942 static unsigned long
22943 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22944 +{
22945 + int d0, d1;
22946 + __asm__ __volatile__(
22947 + " .align 2,0x90\n"
22948 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22949 + " cmpl $67, %0\n"
22950 + " jbe 3f\n"
22951 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22952 + " .align 2,0x90\n"
22953 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22954 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22955 + "5: movl %%eax, 0(%3)\n"
22956 + "6: movl %%edx, 4(%3)\n"
22957 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22958 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22959 + "9: movl %%eax, 8(%3)\n"
22960 + "10: movl %%edx, 12(%3)\n"
22961 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22962 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22963 + "13: movl %%eax, 16(%3)\n"
22964 + "14: movl %%edx, 20(%3)\n"
22965 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22966 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22967 + "17: movl %%eax, 24(%3)\n"
22968 + "18: movl %%edx, 28(%3)\n"
22969 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22970 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22971 + "21: movl %%eax, 32(%3)\n"
22972 + "22: movl %%edx, 36(%3)\n"
22973 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22974 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22975 + "25: movl %%eax, 40(%3)\n"
22976 + "26: movl %%edx, 44(%3)\n"
22977 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22978 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22979 + "29: movl %%eax, 48(%3)\n"
22980 + "30: movl %%edx, 52(%3)\n"
22981 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22982 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22983 + "33: movl %%eax, 56(%3)\n"
22984 + "34: movl %%edx, 60(%3)\n"
22985 + " addl $-64, %0\n"
22986 + " addl $64, %4\n"
22987 + " addl $64, %3\n"
22988 + " cmpl $63, %0\n"
22989 + " ja 1b\n"
22990 + "35: movl %0, %%eax\n"
22991 + " shrl $2, %0\n"
22992 + " andl $3, %%eax\n"
22993 + " cld\n"
22994 + "99: rep; "__copyuser_seg" movsl\n"
22995 + "36: movl %%eax, %0\n"
22996 + "37: rep; "__copyuser_seg" movsb\n"
22997 + "100:\n"
22998 + ".section .fixup,\"ax\"\n"
22999 + "101: lea 0(%%eax,%0,4),%0\n"
23000 + " jmp 100b\n"
23001 + ".previous\n"
23002 + ".section __ex_table,\"a\"\n"
23003 + " .align 4\n"
23004 + " .long 1b,100b\n"
23005 + " .long 2b,100b\n"
23006 + " .long 3b,100b\n"
23007 + " .long 4b,100b\n"
23008 + " .long 5b,100b\n"
23009 + " .long 6b,100b\n"
23010 + " .long 7b,100b\n"
23011 + " .long 8b,100b\n"
23012 + " .long 9b,100b\n"
23013 + " .long 10b,100b\n"
23014 + " .long 11b,100b\n"
23015 + " .long 12b,100b\n"
23016 + " .long 13b,100b\n"
23017 + " .long 14b,100b\n"
23018 + " .long 15b,100b\n"
23019 + " .long 16b,100b\n"
23020 + " .long 17b,100b\n"
23021 + " .long 18b,100b\n"
23022 + " .long 19b,100b\n"
23023 + " .long 20b,100b\n"
23024 + " .long 21b,100b\n"
23025 + " .long 22b,100b\n"
23026 + " .long 23b,100b\n"
23027 + " .long 24b,100b\n"
23028 + " .long 25b,100b\n"
23029 + " .long 26b,100b\n"
23030 + " .long 27b,100b\n"
23031 + " .long 28b,100b\n"
23032 + " .long 29b,100b\n"
23033 + " .long 30b,100b\n"
23034 + " .long 31b,100b\n"
23035 + " .long 32b,100b\n"
23036 + " .long 33b,100b\n"
23037 + " .long 34b,100b\n"
23038 + " .long 35b,100b\n"
23039 + " .long 36b,100b\n"
23040 + " .long 37b,100b\n"
23041 + " .long 99b,101b\n"
23042 + ".previous"
23043 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23044 + : "1"(to), "2"(from), "0"(size)
23045 + : "eax", "edx", "memory");
23046 + return size;
23047 +}
23048 +
23049 +static unsigned long
23050 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23051 +static unsigned long
23052 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23053 {
23054 int d0, d1;
23055 __asm__ __volatile__(
23056 " .align 2,0x90\n"
23057 - "0: movl 32(%4), %%eax\n"
23058 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23059 " cmpl $67, %0\n"
23060 " jbe 2f\n"
23061 - "1: movl 64(%4), %%eax\n"
23062 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23063 " .align 2,0x90\n"
23064 - "2: movl 0(%4), %%eax\n"
23065 - "21: movl 4(%4), %%edx\n"
23066 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23067 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23068 " movl %%eax, 0(%3)\n"
23069 " movl %%edx, 4(%3)\n"
23070 - "3: movl 8(%4), %%eax\n"
23071 - "31: movl 12(%4),%%edx\n"
23072 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23073 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23074 " movl %%eax, 8(%3)\n"
23075 " movl %%edx, 12(%3)\n"
23076 - "4: movl 16(%4), %%eax\n"
23077 - "41: movl 20(%4), %%edx\n"
23078 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23079 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23080 " movl %%eax, 16(%3)\n"
23081 " movl %%edx, 20(%3)\n"
23082 - "10: movl 24(%4), %%eax\n"
23083 - "51: movl 28(%4), %%edx\n"
23084 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23085 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23086 " movl %%eax, 24(%3)\n"
23087 " movl %%edx, 28(%3)\n"
23088 - "11: movl 32(%4), %%eax\n"
23089 - "61: movl 36(%4), %%edx\n"
23090 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23091 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23092 " movl %%eax, 32(%3)\n"
23093 " movl %%edx, 36(%3)\n"
23094 - "12: movl 40(%4), %%eax\n"
23095 - "71: movl 44(%4), %%edx\n"
23096 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23097 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23098 " movl %%eax, 40(%3)\n"
23099 " movl %%edx, 44(%3)\n"
23100 - "13: movl 48(%4), %%eax\n"
23101 - "81: movl 52(%4), %%edx\n"
23102 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23103 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23104 " movl %%eax, 48(%3)\n"
23105 " movl %%edx, 52(%3)\n"
23106 - "14: movl 56(%4), %%eax\n"
23107 - "91: movl 60(%4), %%edx\n"
23108 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23109 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23110 " movl %%eax, 56(%3)\n"
23111 " movl %%edx, 60(%3)\n"
23112 " addl $-64, %0\n"
23113 @@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23114 " shrl $2, %0\n"
23115 " andl $3, %%eax\n"
23116 " cld\n"
23117 - "6: rep; movsl\n"
23118 + "6: rep; "__copyuser_seg" movsl\n"
23119 " movl %%eax,%0\n"
23120 - "7: rep; movsb\n"
23121 + "7: rep; "__copyuser_seg" movsb\n"
23122 "8:\n"
23123 ".section .fixup,\"ax\"\n"
23124 "9: lea 0(%%eax,%0,4),%0\n"
23125 @@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23126 */
23127
23128 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23129 + const void __user *from, unsigned long size) __size_overflow(3);
23130 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23131 const void __user *from, unsigned long size)
23132 {
23133 int d0, d1;
23134
23135 __asm__ __volatile__(
23136 " .align 2,0x90\n"
23137 - "0: movl 32(%4), %%eax\n"
23138 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23139 " cmpl $67, %0\n"
23140 " jbe 2f\n"
23141 - "1: movl 64(%4), %%eax\n"
23142 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23143 " .align 2,0x90\n"
23144 - "2: movl 0(%4), %%eax\n"
23145 - "21: movl 4(%4), %%edx\n"
23146 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23147 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23148 " movnti %%eax, 0(%3)\n"
23149 " movnti %%edx, 4(%3)\n"
23150 - "3: movl 8(%4), %%eax\n"
23151 - "31: movl 12(%4),%%edx\n"
23152 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23153 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23154 " movnti %%eax, 8(%3)\n"
23155 " movnti %%edx, 12(%3)\n"
23156 - "4: movl 16(%4), %%eax\n"
23157 - "41: movl 20(%4), %%edx\n"
23158 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23159 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23160 " movnti %%eax, 16(%3)\n"
23161 " movnti %%edx, 20(%3)\n"
23162 - "10: movl 24(%4), %%eax\n"
23163 - "51: movl 28(%4), %%edx\n"
23164 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23165 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23166 " movnti %%eax, 24(%3)\n"
23167 " movnti %%edx, 28(%3)\n"
23168 - "11: movl 32(%4), %%eax\n"
23169 - "61: movl 36(%4), %%edx\n"
23170 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23171 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23172 " movnti %%eax, 32(%3)\n"
23173 " movnti %%edx, 36(%3)\n"
23174 - "12: movl 40(%4), %%eax\n"
23175 - "71: movl 44(%4), %%edx\n"
23176 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23177 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23178 " movnti %%eax, 40(%3)\n"
23179 " movnti %%edx, 44(%3)\n"
23180 - "13: movl 48(%4), %%eax\n"
23181 - "81: movl 52(%4), %%edx\n"
23182 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23183 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23184 " movnti %%eax, 48(%3)\n"
23185 " movnti %%edx, 52(%3)\n"
23186 - "14: movl 56(%4), %%eax\n"
23187 - "91: movl 60(%4), %%edx\n"
23188 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23189 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23190 " movnti %%eax, 56(%3)\n"
23191 " movnti %%edx, 60(%3)\n"
23192 " addl $-64, %0\n"
23193 @@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23194 " shrl $2, %0\n"
23195 " andl $3, %%eax\n"
23196 " cld\n"
23197 - "6: rep; movsl\n"
23198 + "6: rep; "__copyuser_seg" movsl\n"
23199 " movl %%eax,%0\n"
23200 - "7: rep; movsb\n"
23201 + "7: rep; "__copyuser_seg" movsb\n"
23202 "8:\n"
23203 ".section .fixup,\"ax\"\n"
23204 "9: lea 0(%%eax,%0,4),%0\n"
23205 @@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23206 }
23207
23208 static unsigned long __copy_user_intel_nocache(void *to,
23209 + const void __user *from, unsigned long size) __size_overflow(3);
23210 +static unsigned long __copy_user_intel_nocache(void *to,
23211 const void __user *from, unsigned long size)
23212 {
23213 int d0, d1;
23214
23215 __asm__ __volatile__(
23216 " .align 2,0x90\n"
23217 - "0: movl 32(%4), %%eax\n"
23218 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23219 " cmpl $67, %0\n"
23220 " jbe 2f\n"
23221 - "1: movl 64(%4), %%eax\n"
23222 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23223 " .align 2,0x90\n"
23224 - "2: movl 0(%4), %%eax\n"
23225 - "21: movl 4(%4), %%edx\n"
23226 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23227 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23228 " movnti %%eax, 0(%3)\n"
23229 " movnti %%edx, 4(%3)\n"
23230 - "3: movl 8(%4), %%eax\n"
23231 - "31: movl 12(%4),%%edx\n"
23232 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23233 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23234 " movnti %%eax, 8(%3)\n"
23235 " movnti %%edx, 12(%3)\n"
23236 - "4: movl 16(%4), %%eax\n"
23237 - "41: movl 20(%4), %%edx\n"
23238 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23239 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23240 " movnti %%eax, 16(%3)\n"
23241 " movnti %%edx, 20(%3)\n"
23242 - "10: movl 24(%4), %%eax\n"
23243 - "51: movl 28(%4), %%edx\n"
23244 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23245 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23246 " movnti %%eax, 24(%3)\n"
23247 " movnti %%edx, 28(%3)\n"
23248 - "11: movl 32(%4), %%eax\n"
23249 - "61: movl 36(%4), %%edx\n"
23250 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23251 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23252 " movnti %%eax, 32(%3)\n"
23253 " movnti %%edx, 36(%3)\n"
23254 - "12: movl 40(%4), %%eax\n"
23255 - "71: movl 44(%4), %%edx\n"
23256 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23257 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23258 " movnti %%eax, 40(%3)\n"
23259 " movnti %%edx, 44(%3)\n"
23260 - "13: movl 48(%4), %%eax\n"
23261 - "81: movl 52(%4), %%edx\n"
23262 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23263 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23264 " movnti %%eax, 48(%3)\n"
23265 " movnti %%edx, 52(%3)\n"
23266 - "14: movl 56(%4), %%eax\n"
23267 - "91: movl 60(%4), %%edx\n"
23268 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23269 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23270 " movnti %%eax, 56(%3)\n"
23271 " movnti %%edx, 60(%3)\n"
23272 " addl $-64, %0\n"
23273 @@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23274 " shrl $2, %0\n"
23275 " andl $3, %%eax\n"
23276 " cld\n"
23277 - "6: rep; movsl\n"
23278 + "6: rep; "__copyuser_seg" movsl\n"
23279 " movl %%eax,%0\n"
23280 - "7: rep; movsb\n"
23281 + "7: rep; "__copyuser_seg" movsb\n"
23282 "8:\n"
23283 ".section .fixup,\"ax\"\n"
23284 "9: lea 0(%%eax,%0,4),%0\n"
23285 @@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23286 */
23287 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23288 unsigned long size);
23289 -unsigned long __copy_user_intel(void __user *to, const void *from,
23290 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23291 + unsigned long size);
23292 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23293 unsigned long size);
23294 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23295 const void __user *from, unsigned long size);
23296 #endif /* CONFIG_X86_INTEL_USERCOPY */
23297
23298 /* Generic arbitrary sized copy. */
23299 -#define __copy_user(to, from, size) \
23300 +#define __copy_user(to, from, size, prefix, set, restore) \
23301 do { \
23302 int __d0, __d1, __d2; \
23303 __asm__ __volatile__( \
23304 + set \
23305 " cmp $7,%0\n" \
23306 " jbe 1f\n" \
23307 " movl %1,%0\n" \
23308 " negl %0\n" \
23309 " andl $7,%0\n" \
23310 " subl %0,%3\n" \
23311 - "4: rep; movsb\n" \
23312 + "4: rep; "prefix"movsb\n" \
23313 " movl %3,%0\n" \
23314 " shrl $2,%0\n" \
23315 " andl $3,%3\n" \
23316 " .align 2,0x90\n" \
23317 - "0: rep; movsl\n" \
23318 + "0: rep; "prefix"movsl\n" \
23319 " movl %3,%0\n" \
23320 - "1: rep; movsb\n" \
23321 + "1: rep; "prefix"movsb\n" \
23322 "2:\n" \
23323 + restore \
23324 ".section .fixup,\"ax\"\n" \
23325 "5: addl %3,%0\n" \
23326 " jmp 2b\n" \
23327 @@ -595,14 +718,14 @@ do { \
23328 " negl %0\n" \
23329 " andl $7,%0\n" \
23330 " subl %0,%3\n" \
23331 - "4: rep; movsb\n" \
23332 + "4: rep; "__copyuser_seg"movsb\n" \
23333 " movl %3,%0\n" \
23334 " shrl $2,%0\n" \
23335 " andl $3,%3\n" \
23336 " .align 2,0x90\n" \
23337 - "0: rep; movsl\n" \
23338 + "0: rep; "__copyuser_seg"movsl\n" \
23339 " movl %3,%0\n" \
23340 - "1: rep; movsb\n" \
23341 + "1: rep; "__copyuser_seg"movsb\n" \
23342 "2:\n" \
23343 ".section .fixup,\"ax\"\n" \
23344 "5: addl %3,%0\n" \
23345 @@ -688,9 +811,9 @@ survive:
23346 }
23347 #endif
23348 if (movsl_is_ok(to, from, n))
23349 - __copy_user(to, from, n);
23350 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23351 else
23352 - n = __copy_user_intel(to, from, n);
23353 + n = __generic_copy_to_user_intel(to, from, n);
23354 return n;
23355 }
23356 EXPORT_SYMBOL(__copy_to_user_ll);
23357 @@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23358 unsigned long n)
23359 {
23360 if (movsl_is_ok(to, from, n))
23361 - __copy_user(to, from, n);
23362 + __copy_user(to, from, n, __copyuser_seg, "", "");
23363 else
23364 - n = __copy_user_intel((void __user *)to,
23365 - (const void *)from, n);
23366 + n = __generic_copy_from_user_intel(to, from, n);
23367 return n;
23368 }
23369 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23370 @@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23371 if (n > 64 && cpu_has_xmm2)
23372 n = __copy_user_intel_nocache(to, from, n);
23373 else
23374 - __copy_user(to, from, n);
23375 + __copy_user(to, from, n, __copyuser_seg, "", "");
23376 #else
23377 - __copy_user(to, from, n);
23378 + __copy_user(to, from, n, __copyuser_seg, "", "");
23379 #endif
23380 return n;
23381 }
23382 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23383
23384 -/**
23385 - * copy_to_user: - Copy a block of data into user space.
23386 - * @to: Destination address, in user space.
23387 - * @from: Source address, in kernel space.
23388 - * @n: Number of bytes to copy.
23389 - *
23390 - * Context: User context only. This function may sleep.
23391 - *
23392 - * Copy data from kernel space to user space.
23393 - *
23394 - * Returns number of bytes that could not be copied.
23395 - * On success, this will be zero.
23396 - */
23397 -unsigned long
23398 -copy_to_user(void __user *to, const void *from, unsigned long n)
23399 -{
23400 - if (access_ok(VERIFY_WRITE, to, n))
23401 - n = __copy_to_user(to, from, n);
23402 - return n;
23403 -}
23404 -EXPORT_SYMBOL(copy_to_user);
23405 -
23406 -/**
23407 - * copy_from_user: - Copy a block of data from user space.
23408 - * @to: Destination address, in kernel space.
23409 - * @from: Source address, in user space.
23410 - * @n: Number of bytes to copy.
23411 - *
23412 - * Context: User context only. This function may sleep.
23413 - *
23414 - * Copy data from user space to kernel space.
23415 - *
23416 - * Returns number of bytes that could not be copied.
23417 - * On success, this will be zero.
23418 - *
23419 - * If some data could not be copied, this function will pad the copied
23420 - * data to the requested size using zero bytes.
23421 - */
23422 -unsigned long
23423 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23424 -{
23425 - if (access_ok(VERIFY_READ, from, n))
23426 - n = __copy_from_user(to, from, n);
23427 - else
23428 - memset(to, 0, n);
23429 - return n;
23430 -}
23431 -EXPORT_SYMBOL(_copy_from_user);
23432 -
23433 void copy_from_user_overflow(void)
23434 {
23435 WARN(1, "Buffer overflow detected!\n");
23436 }
23437 EXPORT_SYMBOL(copy_from_user_overflow);
23438 +
23439 +void copy_to_user_overflow(void)
23440 +{
23441 + WARN(1, "Buffer overflow detected!\n");
23442 +}
23443 +EXPORT_SYMBOL(copy_to_user_overflow);
23444 +
23445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23446 +void __set_fs(mm_segment_t x)
23447 +{
23448 + switch (x.seg) {
23449 + case 0:
23450 + loadsegment(gs, 0);
23451 + break;
23452 + case TASK_SIZE_MAX:
23453 + loadsegment(gs, __USER_DS);
23454 + break;
23455 + case -1UL:
23456 + loadsegment(gs, __KERNEL_DS);
23457 + break;
23458 + default:
23459 + BUG();
23460 + }
23461 + return;
23462 +}
23463 +EXPORT_SYMBOL(__set_fs);
23464 +
23465 +void set_fs(mm_segment_t x)
23466 +{
23467 + current_thread_info()->addr_limit = x;
23468 + __set_fs(x);
23469 +}
23470 +EXPORT_SYMBOL(set_fs);
23471 +#endif
23472 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23473 index 0d0326f..6a6155b 100644
23474 --- a/arch/x86/lib/usercopy_64.c
23475 +++ b/arch/x86/lib/usercopy_64.c
23476 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23477 {
23478 long __d0;
23479 might_fault();
23480 +
23481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23482 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23483 + addr += PAX_USER_SHADOW_BASE;
23484 +#endif
23485 +
23486 /* no memory constraint because it doesn't change any memory gcc knows
23487 about */
23488 asm volatile(
23489 @@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23490 }
23491 EXPORT_SYMBOL(strlen_user);
23492
23493 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23494 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23495 {
23496 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23497 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23498 - }
23499 - return len;
23500 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23501 +
23502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23503 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23504 + to += PAX_USER_SHADOW_BASE;
23505 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23506 + from += PAX_USER_SHADOW_BASE;
23507 +#endif
23508 +
23509 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23510 + }
23511 + return len;
23512 }
23513 EXPORT_SYMBOL(copy_in_user);
23514
23515 @@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23516 * it is not necessary to optimize tail handling.
23517 */
23518 unsigned long
23519 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23520 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23521 {
23522 char c;
23523 unsigned zero_len;
23524 @@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23525 break;
23526 return len;
23527 }
23528 +
23529 +void copy_from_user_overflow(void)
23530 +{
23531 + WARN(1, "Buffer overflow detected!\n");
23532 +}
23533 +EXPORT_SYMBOL(copy_from_user_overflow);
23534 +
23535 +void copy_to_user_overflow(void)
23536 +{
23537 + WARN(1, "Buffer overflow detected!\n");
23538 +}
23539 +EXPORT_SYMBOL(copy_to_user_overflow);
23540 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23541 index 1fb85db..8b3540b 100644
23542 --- a/arch/x86/mm/extable.c
23543 +++ b/arch/x86/mm/extable.c
23544 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23545 const struct exception_table_entry *fixup;
23546
23547 #ifdef CONFIG_PNPBIOS
23548 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23549 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23550 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23551 extern u32 pnp_bios_is_utter_crap;
23552 pnp_bios_is_utter_crap = 1;
23553 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23554 index 3ecfd1a..304d554 100644
23555 --- a/arch/x86/mm/fault.c
23556 +++ b/arch/x86/mm/fault.c
23557 @@ -13,11 +13,18 @@
23558 #include <linux/perf_event.h> /* perf_sw_event */
23559 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23560 #include <linux/prefetch.h> /* prefetchw */
23561 +#include <linux/unistd.h>
23562 +#include <linux/compiler.h>
23563
23564 #include <asm/traps.h> /* dotraplinkage, ... */
23565 #include <asm/pgalloc.h> /* pgd_*(), ... */
23566 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23567 #include <asm/fixmap.h> /* VSYSCALL_START */
23568 +#include <asm/tlbflush.h>
23569 +
23570 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23571 +#include <asm/stacktrace.h>
23572 +#endif
23573
23574 /*
23575 * Page fault error code bits:
23576 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23577 int ret = 0;
23578
23579 /* kprobe_running() needs smp_processor_id() */
23580 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23581 + if (kprobes_built_in() && !user_mode(regs)) {
23582 preempt_disable();
23583 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23584 ret = 1;
23585 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23586 return !instr_lo || (instr_lo>>1) == 1;
23587 case 0x00:
23588 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23589 - if (probe_kernel_address(instr, opcode))
23590 + if (user_mode(regs)) {
23591 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23592 + return 0;
23593 + } else if (probe_kernel_address(instr, opcode))
23594 return 0;
23595
23596 *prefetch = (instr_lo == 0xF) &&
23597 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23598 while (instr < max_instr) {
23599 unsigned char opcode;
23600
23601 - if (probe_kernel_address(instr, opcode))
23602 + if (user_mode(regs)) {
23603 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23604 + break;
23605 + } else if (probe_kernel_address(instr, opcode))
23606 break;
23607
23608 instr++;
23609 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23610 force_sig_info(si_signo, &info, tsk);
23611 }
23612
23613 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23614 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23615 +#endif
23616 +
23617 +#ifdef CONFIG_PAX_EMUTRAMP
23618 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23619 +#endif
23620 +
23621 +#ifdef CONFIG_PAX_PAGEEXEC
23622 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23623 +{
23624 + pgd_t *pgd;
23625 + pud_t *pud;
23626 + pmd_t *pmd;
23627 +
23628 + pgd = pgd_offset(mm, address);
23629 + if (!pgd_present(*pgd))
23630 + return NULL;
23631 + pud = pud_offset(pgd, address);
23632 + if (!pud_present(*pud))
23633 + return NULL;
23634 + pmd = pmd_offset(pud, address);
23635 + if (!pmd_present(*pmd))
23636 + return NULL;
23637 + return pmd;
23638 +}
23639 +#endif
23640 +
23641 DEFINE_SPINLOCK(pgd_lock);
23642 LIST_HEAD(pgd_list);
23643
23644 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23645 for (address = VMALLOC_START & PMD_MASK;
23646 address >= TASK_SIZE && address < FIXADDR_TOP;
23647 address += PMD_SIZE) {
23648 +
23649 +#ifdef CONFIG_PAX_PER_CPU_PGD
23650 + unsigned long cpu;
23651 +#else
23652 struct page *page;
23653 +#endif
23654
23655 spin_lock(&pgd_lock);
23656 +
23657 +#ifdef CONFIG_PAX_PER_CPU_PGD
23658 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23659 + pgd_t *pgd = get_cpu_pgd(cpu);
23660 + pmd_t *ret;
23661 +#else
23662 list_for_each_entry(page, &pgd_list, lru) {
23663 + pgd_t *pgd = page_address(page);
23664 spinlock_t *pgt_lock;
23665 pmd_t *ret;
23666
23667 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23668 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23669
23670 spin_lock(pgt_lock);
23671 - ret = vmalloc_sync_one(page_address(page), address);
23672 +#endif
23673 +
23674 + ret = vmalloc_sync_one(pgd, address);
23675 +
23676 +#ifndef CONFIG_PAX_PER_CPU_PGD
23677 spin_unlock(pgt_lock);
23678 +#endif
23679
23680 if (!ret)
23681 break;
23682 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23683 * an interrupt in the middle of a task switch..
23684 */
23685 pgd_paddr = read_cr3();
23686 +
23687 +#ifdef CONFIG_PAX_PER_CPU_PGD
23688 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23689 +#endif
23690 +
23691 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23692 if (!pmd_k)
23693 return -1;
23694 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23695 * happen within a race in page table update. In the later
23696 * case just flush:
23697 */
23698 +
23699 +#ifdef CONFIG_PAX_PER_CPU_PGD
23700 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23701 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23702 +#else
23703 pgd = pgd_offset(current->active_mm, address);
23704 +#endif
23705 +
23706 pgd_ref = pgd_offset_k(address);
23707 if (pgd_none(*pgd_ref))
23708 return -1;
23709 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23710 static int is_errata100(struct pt_regs *regs, unsigned long address)
23711 {
23712 #ifdef CONFIG_X86_64
23713 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23714 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23715 return 1;
23716 #endif
23717 return 0;
23718 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23719 }
23720
23721 static const char nx_warning[] = KERN_CRIT
23722 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23723 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23724
23725 static void
23726 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23727 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23728 if (!oops_may_print())
23729 return;
23730
23731 - if (error_code & PF_INSTR) {
23732 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23733 unsigned int level;
23734
23735 pte_t *pte = lookup_address(address, &level);
23736
23737 if (pte && pte_present(*pte) && !pte_exec(*pte))
23738 - printk(nx_warning, current_uid());
23739 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23740 }
23741
23742 +#ifdef CONFIG_PAX_KERNEXEC
23743 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23744 + if (current->signal->curr_ip)
23745 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23746 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23747 + else
23748 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23749 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23750 + }
23751 +#endif
23752 +
23753 printk(KERN_ALERT "BUG: unable to handle kernel ");
23754 if (address < PAGE_SIZE)
23755 printk(KERN_CONT "NULL pointer dereference");
23756 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23757 }
23758 #endif
23759
23760 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23761 + if (pax_is_fetch_fault(regs, error_code, address)) {
23762 +
23763 +#ifdef CONFIG_PAX_EMUTRAMP
23764 + switch (pax_handle_fetch_fault(regs)) {
23765 + case 2:
23766 + return;
23767 + }
23768 +#endif
23769 +
23770 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23771 + do_group_exit(SIGKILL);
23772 + }
23773 +#endif
23774 +
23775 if (unlikely(show_unhandled_signals))
23776 show_signal_msg(regs, error_code, address, tsk);
23777
23778 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23779 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23780 printk(KERN_ERR
23781 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23782 - tsk->comm, tsk->pid, address);
23783 + tsk->comm, task_pid_nr(tsk), address);
23784 code = BUS_MCEERR_AR;
23785 }
23786 #endif
23787 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23788 return 1;
23789 }
23790
23791 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23792 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23793 +{
23794 + pte_t *pte;
23795 + pmd_t *pmd;
23796 + spinlock_t *ptl;
23797 + unsigned char pte_mask;
23798 +
23799 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23800 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23801 + return 0;
23802 +
23803 + /* PaX: it's our fault, let's handle it if we can */
23804 +
23805 + /* PaX: take a look at read faults before acquiring any locks */
23806 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23807 + /* instruction fetch attempt from a protected page in user mode */
23808 + up_read(&mm->mmap_sem);
23809 +
23810 +#ifdef CONFIG_PAX_EMUTRAMP
23811 + switch (pax_handle_fetch_fault(regs)) {
23812 + case 2:
23813 + return 1;
23814 + }
23815 +#endif
23816 +
23817 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23818 + do_group_exit(SIGKILL);
23819 + }
23820 +
23821 + pmd = pax_get_pmd(mm, address);
23822 + if (unlikely(!pmd))
23823 + return 0;
23824 +
23825 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23826 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23827 + pte_unmap_unlock(pte, ptl);
23828 + return 0;
23829 + }
23830 +
23831 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23832 + /* write attempt to a protected page in user mode */
23833 + pte_unmap_unlock(pte, ptl);
23834 + return 0;
23835 + }
23836 +
23837 +#ifdef CONFIG_SMP
23838 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23839 +#else
23840 + if (likely(address > get_limit(regs->cs)))
23841 +#endif
23842 + {
23843 + set_pte(pte, pte_mkread(*pte));
23844 + __flush_tlb_one(address);
23845 + pte_unmap_unlock(pte, ptl);
23846 + up_read(&mm->mmap_sem);
23847 + return 1;
23848 + }
23849 +
23850 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23851 +
23852 + /*
23853 + * PaX: fill DTLB with user rights and retry
23854 + */
23855 + __asm__ __volatile__ (
23856 + "orb %2,(%1)\n"
23857 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23858 +/*
23859 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23860 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23861 + * page fault when examined during a TLB load attempt. this is true not only
23862 + * for PTEs holding a non-present entry but also present entries that will
23863 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23864 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23865 + * for our target pages since their PTEs are simply not in the TLBs at all.
23866 +
23867 + * the best thing in omitting it is that we gain around 15-20% speed in the
23868 + * fast path of the page fault handler and can get rid of tracing since we
23869 + * can no longer flush unintended entries.
23870 + */
23871 + "invlpg (%0)\n"
23872 +#endif
23873 + __copyuser_seg"testb $0,(%0)\n"
23874 + "xorb %3,(%1)\n"
23875 + :
23876 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23877 + : "memory", "cc");
23878 + pte_unmap_unlock(pte, ptl);
23879 + up_read(&mm->mmap_sem);
23880 + return 1;
23881 +}
23882 +#endif
23883 +
23884 /*
23885 * Handle a spurious fault caused by a stale TLB entry.
23886 *
23887 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23888 static inline int
23889 access_error(unsigned long error_code, struct vm_area_struct *vma)
23890 {
23891 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23892 + return 1;
23893 +
23894 if (error_code & PF_WRITE) {
23895 /* write, present and write, not present: */
23896 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23897 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23898 {
23899 struct vm_area_struct *vma;
23900 struct task_struct *tsk;
23901 - unsigned long address;
23902 struct mm_struct *mm;
23903 int fault;
23904 int write = error_code & PF_WRITE;
23905 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23906 (write ? FAULT_FLAG_WRITE : 0);
23907
23908 - tsk = current;
23909 - mm = tsk->mm;
23910 -
23911 /* Get the faulting address: */
23912 - address = read_cr2();
23913 + unsigned long address = read_cr2();
23914 +
23915 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23916 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23917 + if (!search_exception_tables(regs->ip)) {
23918 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23919 + bad_area_nosemaphore(regs, error_code, address);
23920 + return;
23921 + }
23922 + if (address < PAX_USER_SHADOW_BASE) {
23923 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23924 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23925 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23926 + } else
23927 + address -= PAX_USER_SHADOW_BASE;
23928 + }
23929 +#endif
23930 +
23931 + tsk = current;
23932 + mm = tsk->mm;
23933
23934 /*
23935 * Detect and handle instructions that would cause a page fault for
23936 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23937 * User-mode registers count as a user access even for any
23938 * potential system fault or CPU buglet:
23939 */
23940 - if (user_mode_vm(regs)) {
23941 + if (user_mode(regs)) {
23942 local_irq_enable();
23943 error_code |= PF_USER;
23944 } else {
23945 @@ -1132,6 +1339,11 @@ retry:
23946 might_sleep();
23947 }
23948
23949 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23950 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23951 + return;
23952 +#endif
23953 +
23954 vma = find_vma(mm, address);
23955 if (unlikely(!vma)) {
23956 bad_area(regs, error_code, address);
23957 @@ -1143,18 +1355,24 @@ retry:
23958 bad_area(regs, error_code, address);
23959 return;
23960 }
23961 - if (error_code & PF_USER) {
23962 - /*
23963 - * Accessing the stack below %sp is always a bug.
23964 - * The large cushion allows instructions like enter
23965 - * and pusha to work. ("enter $65535, $31" pushes
23966 - * 32 pointers and then decrements %sp by 65535.)
23967 - */
23968 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23969 - bad_area(regs, error_code, address);
23970 - return;
23971 - }
23972 + /*
23973 + * Accessing the stack below %sp is always a bug.
23974 + * The large cushion allows instructions like enter
23975 + * and pusha to work. ("enter $65535, $31" pushes
23976 + * 32 pointers and then decrements %sp by 65535.)
23977 + */
23978 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23979 + bad_area(regs, error_code, address);
23980 + return;
23981 }
23982 +
23983 +#ifdef CONFIG_PAX_SEGMEXEC
23984 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23985 + bad_area(regs, error_code, address);
23986 + return;
23987 + }
23988 +#endif
23989 +
23990 if (unlikely(expand_stack(vma, address))) {
23991 bad_area(regs, error_code, address);
23992 return;
23993 @@ -1209,3 +1427,292 @@ good_area:
23994
23995 up_read(&mm->mmap_sem);
23996 }
23997 +
23998 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23999 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24000 +{
24001 + struct mm_struct *mm = current->mm;
24002 + unsigned long ip = regs->ip;
24003 +
24004 + if (v8086_mode(regs))
24005 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24006 +
24007 +#ifdef CONFIG_PAX_PAGEEXEC
24008 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24009 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24010 + return true;
24011 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24012 + return true;
24013 + return false;
24014 + }
24015 +#endif
24016 +
24017 +#ifdef CONFIG_PAX_SEGMEXEC
24018 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24019 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24020 + return true;
24021 + return false;
24022 + }
24023 +#endif
24024 +
24025 + return false;
24026 +}
24027 +#endif
24028 +
24029 +#ifdef CONFIG_PAX_EMUTRAMP
24030 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24031 +{
24032 + int err;
24033 +
24034 + do { /* PaX: libffi trampoline emulation */
24035 + unsigned char mov, jmp;
24036 + unsigned int addr1, addr2;
24037 +
24038 +#ifdef CONFIG_X86_64
24039 + if ((regs->ip + 9) >> 32)
24040 + break;
24041 +#endif
24042 +
24043 + err = get_user(mov, (unsigned char __user *)regs->ip);
24044 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24045 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24046 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24047 +
24048 + if (err)
24049 + break;
24050 +
24051 + if (mov == 0xB8 && jmp == 0xE9) {
24052 + regs->ax = addr1;
24053 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24054 + return 2;
24055 + }
24056 + } while (0);
24057 +
24058 + do { /* PaX: gcc trampoline emulation #1 */
24059 + unsigned char mov1, mov2;
24060 + unsigned short jmp;
24061 + unsigned int addr1, addr2;
24062 +
24063 +#ifdef CONFIG_X86_64
24064 + if ((regs->ip + 11) >> 32)
24065 + break;
24066 +#endif
24067 +
24068 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24069 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24070 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24071 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24072 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24073 +
24074 + if (err)
24075 + break;
24076 +
24077 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24078 + regs->cx = addr1;
24079 + regs->ax = addr2;
24080 + regs->ip = addr2;
24081 + return 2;
24082 + }
24083 + } while (0);
24084 +
24085 + do { /* PaX: gcc trampoline emulation #2 */
24086 + unsigned char mov, jmp;
24087 + unsigned int addr1, addr2;
24088 +
24089 +#ifdef CONFIG_X86_64
24090 + if ((regs->ip + 9) >> 32)
24091 + break;
24092 +#endif
24093 +
24094 + err = get_user(mov, (unsigned char __user *)regs->ip);
24095 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24096 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24097 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24098 +
24099 + if (err)
24100 + break;
24101 +
24102 + if (mov == 0xB9 && jmp == 0xE9) {
24103 + regs->cx = addr1;
24104 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24105 + return 2;
24106 + }
24107 + } while (0);
24108 +
24109 + return 1; /* PaX in action */
24110 +}
24111 +
24112 +#ifdef CONFIG_X86_64
24113 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24114 +{
24115 + int err;
24116 +
24117 + do { /* PaX: libffi trampoline emulation */
24118 + unsigned short mov1, mov2, jmp1;
24119 + unsigned char stcclc, jmp2;
24120 + unsigned long addr1, addr2;
24121 +
24122 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24123 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24124 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24125 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24126 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24127 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24128 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24129 +
24130 + if (err)
24131 + break;
24132 +
24133 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24134 + regs->r11 = addr1;
24135 + regs->r10 = addr2;
24136 + if (stcclc == 0xF8)
24137 + regs->flags &= ~X86_EFLAGS_CF;
24138 + else
24139 + regs->flags |= X86_EFLAGS_CF;
24140 + regs->ip = addr1;
24141 + return 2;
24142 + }
24143 + } while (0);
24144 +
24145 + do { /* PaX: gcc trampoline emulation #1 */
24146 + unsigned short mov1, mov2, jmp1;
24147 + unsigned char jmp2;
24148 + unsigned int addr1;
24149 + unsigned long addr2;
24150 +
24151 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24152 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24153 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24154 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24155 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24156 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24157 +
24158 + if (err)
24159 + break;
24160 +
24161 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24162 + regs->r11 = addr1;
24163 + regs->r10 = addr2;
24164 + regs->ip = addr1;
24165 + return 2;
24166 + }
24167 + } while (0);
24168 +
24169 + do { /* PaX: gcc trampoline emulation #2 */
24170 + unsigned short mov1, mov2, jmp1;
24171 + unsigned char jmp2;
24172 + unsigned long addr1, addr2;
24173 +
24174 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24175 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24176 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24177 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24178 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24179 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24180 +
24181 + if (err)
24182 + break;
24183 +
24184 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24185 + regs->r11 = addr1;
24186 + regs->r10 = addr2;
24187 + regs->ip = addr1;
24188 + return 2;
24189 + }
24190 + } while (0);
24191 +
24192 + return 1; /* PaX in action */
24193 +}
24194 +#endif
24195 +
24196 +/*
24197 + * PaX: decide what to do with offenders (regs->ip = fault address)
24198 + *
24199 + * returns 1 when task should be killed
24200 + * 2 when gcc trampoline was detected
24201 + */
24202 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24203 +{
24204 + if (v8086_mode(regs))
24205 + return 1;
24206 +
24207 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24208 + return 1;
24209 +
24210 +#ifdef CONFIG_X86_32
24211 + return pax_handle_fetch_fault_32(regs);
24212 +#else
24213 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24214 + return pax_handle_fetch_fault_32(regs);
24215 + else
24216 + return pax_handle_fetch_fault_64(regs);
24217 +#endif
24218 +}
24219 +#endif
24220 +
24221 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24222 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24223 +{
24224 + long i;
24225 +
24226 + printk(KERN_ERR "PAX: bytes at PC: ");
24227 + for (i = 0; i < 20; i++) {
24228 + unsigned char c;
24229 + if (get_user(c, (unsigned char __force_user *)pc+i))
24230 + printk(KERN_CONT "?? ");
24231 + else
24232 + printk(KERN_CONT "%02x ", c);
24233 + }
24234 + printk("\n");
24235 +
24236 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24237 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24238 + unsigned long c;
24239 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24240 +#ifdef CONFIG_X86_32
24241 + printk(KERN_CONT "???????? ");
24242 +#else
24243 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24244 + printk(KERN_CONT "???????? ???????? ");
24245 + else
24246 + printk(KERN_CONT "???????????????? ");
24247 +#endif
24248 + } else {
24249 +#ifdef CONFIG_X86_64
24250 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24251 + printk(KERN_CONT "%08x ", (unsigned int)c);
24252 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24253 + } else
24254 +#endif
24255 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24256 + }
24257 + }
24258 + printk("\n");
24259 +}
24260 +#endif
24261 +
24262 +/**
24263 + * probe_kernel_write(): safely attempt to write to a location
24264 + * @dst: address to write to
24265 + * @src: pointer to the data that shall be written
24266 + * @size: size of the data chunk
24267 + *
24268 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24269 + * happens, handle that and return -EFAULT.
24270 + */
24271 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24272 +{
24273 + long ret;
24274 + mm_segment_t old_fs = get_fs();
24275 +
24276 + set_fs(KERNEL_DS);
24277 + pagefault_disable();
24278 + pax_open_kernel();
24279 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24280 + pax_close_kernel();
24281 + pagefault_enable();
24282 + set_fs(old_fs);
24283 +
24284 + return ret ? -EFAULT : 0;
24285 +}
24286 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24287 index dd74e46..7d26398 100644
24288 --- a/arch/x86/mm/gup.c
24289 +++ b/arch/x86/mm/gup.c
24290 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24291 addr = start;
24292 len = (unsigned long) nr_pages << PAGE_SHIFT;
24293 end = start + len;
24294 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24295 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24296 (void __user *)start, len)))
24297 return 0;
24298
24299 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24300 index 6f31ee5..8ee4164 100644
24301 --- a/arch/x86/mm/highmem_32.c
24302 +++ b/arch/x86/mm/highmem_32.c
24303 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24304 idx = type + KM_TYPE_NR*smp_processor_id();
24305 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24306 BUG_ON(!pte_none(*(kmap_pte-idx)));
24307 +
24308 + pax_open_kernel();
24309 set_pte(kmap_pte-idx, mk_pte(page, prot));
24310 + pax_close_kernel();
24311 +
24312 arch_flush_lazy_mmu_mode();
24313
24314 return (void *)vaddr;
24315 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24316 index f6679a7..8f795a3 100644
24317 --- a/arch/x86/mm/hugetlbpage.c
24318 +++ b/arch/x86/mm/hugetlbpage.c
24319 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24320 struct hstate *h = hstate_file(file);
24321 struct mm_struct *mm = current->mm;
24322 struct vm_area_struct *vma;
24323 - unsigned long start_addr;
24324 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24325 +
24326 +#ifdef CONFIG_PAX_SEGMEXEC
24327 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24328 + pax_task_size = SEGMEXEC_TASK_SIZE;
24329 +#endif
24330 +
24331 + pax_task_size -= PAGE_SIZE;
24332
24333 if (len > mm->cached_hole_size) {
24334 - start_addr = mm->free_area_cache;
24335 + start_addr = mm->free_area_cache;
24336 } else {
24337 - start_addr = TASK_UNMAPPED_BASE;
24338 - mm->cached_hole_size = 0;
24339 + start_addr = mm->mmap_base;
24340 + mm->cached_hole_size = 0;
24341 }
24342
24343 full_search:
24344 @@ -280,26 +287,27 @@ full_search:
24345
24346 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24347 /* At this point: (!vma || addr < vma->vm_end). */
24348 - if (TASK_SIZE - len < addr) {
24349 + if (pax_task_size - len < addr) {
24350 /*
24351 * Start a new search - just in case we missed
24352 * some holes.
24353 */
24354 - if (start_addr != TASK_UNMAPPED_BASE) {
24355 - start_addr = TASK_UNMAPPED_BASE;
24356 + if (start_addr != mm->mmap_base) {
24357 + start_addr = mm->mmap_base;
24358 mm->cached_hole_size = 0;
24359 goto full_search;
24360 }
24361 return -ENOMEM;
24362 }
24363 - if (!vma || addr + len <= vma->vm_start) {
24364 - mm->free_area_cache = addr + len;
24365 - return addr;
24366 - }
24367 + if (check_heap_stack_gap(vma, addr, len))
24368 + break;
24369 if (addr + mm->cached_hole_size < vma->vm_start)
24370 mm->cached_hole_size = vma->vm_start - addr;
24371 addr = ALIGN(vma->vm_end, huge_page_size(h));
24372 }
24373 +
24374 + mm->free_area_cache = addr + len;
24375 + return addr;
24376 }
24377
24378 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24379 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24380 struct mm_struct *mm = current->mm;
24381 struct vm_area_struct *vma;
24382 unsigned long base = mm->mmap_base;
24383 - unsigned long addr = addr0;
24384 + unsigned long addr;
24385 unsigned long largest_hole = mm->cached_hole_size;
24386 - unsigned long start_addr;
24387
24388 /* don't allow allocations above current base */
24389 if (mm->free_area_cache > base)
24390 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24391 largest_hole = 0;
24392 mm->free_area_cache = base;
24393 }
24394 -try_again:
24395 - start_addr = mm->free_area_cache;
24396
24397 /* make sure it can fit in the remaining address space */
24398 if (mm->free_area_cache < len)
24399 goto fail;
24400
24401 /* either no address requested or can't fit in requested address hole */
24402 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24403 + addr = mm->free_area_cache - len;
24404 do {
24405 + addr &= huge_page_mask(h);
24406 /*
24407 * Lookup failure means no vma is above this address,
24408 * i.e. return with success:
24409 @@ -340,10 +346,10 @@ try_again:
24410 if (!vma)
24411 return addr;
24412
24413 - if (addr + len <= vma->vm_start) {
24414 + if (check_heap_stack_gap(vma, addr, len)) {
24415 /* remember the address as a hint for next time */
24416 - mm->cached_hole_size = largest_hole;
24417 - return (mm->free_area_cache = addr);
24418 + mm->cached_hole_size = largest_hole;
24419 + return (mm->free_area_cache = addr);
24420 } else if (mm->free_area_cache == vma->vm_end) {
24421 /* pull free_area_cache down to the first hole */
24422 mm->free_area_cache = vma->vm_start;
24423 @@ -352,29 +358,34 @@ try_again:
24424
24425 /* remember the largest hole we saw so far */
24426 if (addr + largest_hole < vma->vm_start)
24427 - largest_hole = vma->vm_start - addr;
24428 + largest_hole = vma->vm_start - addr;
24429
24430 /* try just below the current vma->vm_start */
24431 - addr = (vma->vm_start - len) & huge_page_mask(h);
24432 - } while (len <= vma->vm_start);
24433 + addr = skip_heap_stack_gap(vma, len);
24434 + } while (!IS_ERR_VALUE(addr));
24435
24436 fail:
24437 /*
24438 - * if hint left us with no space for the requested
24439 - * mapping then try again:
24440 - */
24441 - if (start_addr != base) {
24442 - mm->free_area_cache = base;
24443 - largest_hole = 0;
24444 - goto try_again;
24445 - }
24446 - /*
24447 * A failed mmap() very likely causes application failure,
24448 * so fall back to the bottom-up function here. This scenario
24449 * can happen with large stack limits and large mmap()
24450 * allocations.
24451 */
24452 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24453 +
24454 +#ifdef CONFIG_PAX_SEGMEXEC
24455 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24456 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24457 + else
24458 +#endif
24459 +
24460 + mm->mmap_base = TASK_UNMAPPED_BASE;
24461 +
24462 +#ifdef CONFIG_PAX_RANDMMAP
24463 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24464 + mm->mmap_base += mm->delta_mmap;
24465 +#endif
24466 +
24467 + mm->free_area_cache = mm->mmap_base;
24468 mm->cached_hole_size = ~0UL;
24469 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24470 len, pgoff, flags);
24471 @@ -382,6 +393,7 @@ fail:
24472 /*
24473 * Restore the topdown base:
24474 */
24475 + mm->mmap_base = base;
24476 mm->free_area_cache = base;
24477 mm->cached_hole_size = ~0UL;
24478
24479 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24480 struct hstate *h = hstate_file(file);
24481 struct mm_struct *mm = current->mm;
24482 struct vm_area_struct *vma;
24483 + unsigned long pax_task_size = TASK_SIZE;
24484
24485 if (len & ~huge_page_mask(h))
24486 return -EINVAL;
24487 - if (len > TASK_SIZE)
24488 +
24489 +#ifdef CONFIG_PAX_SEGMEXEC
24490 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24491 + pax_task_size = SEGMEXEC_TASK_SIZE;
24492 +#endif
24493 +
24494 + pax_task_size -= PAGE_SIZE;
24495 +
24496 + if (len > pax_task_size)
24497 return -ENOMEM;
24498
24499 if (flags & MAP_FIXED) {
24500 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24501 if (addr) {
24502 addr = ALIGN(addr, huge_page_size(h));
24503 vma = find_vma(mm, addr);
24504 - if (TASK_SIZE - len >= addr &&
24505 - (!vma || addr + len <= vma->vm_start))
24506 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24507 return addr;
24508 }
24509 if (mm->get_unmapped_area == arch_get_unmapped_area)
24510 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24511 index 4f0cec7..00976ce 100644
24512 --- a/arch/x86/mm/init.c
24513 +++ b/arch/x86/mm/init.c
24514 @@ -16,6 +16,8 @@
24515 #include <asm/tlb.h>
24516 #include <asm/proto.h>
24517 #include <asm/dma.h> /* for MAX_DMA_PFN */
24518 +#include <asm/desc.h>
24519 +#include <asm/bios_ebda.h>
24520
24521 unsigned long __initdata pgt_buf_start;
24522 unsigned long __meminitdata pgt_buf_end;
24523 @@ -32,7 +34,7 @@ int direct_gbpages
24524 static void __init find_early_table_space(unsigned long end, int use_pse,
24525 int use_gbpages)
24526 {
24527 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24528 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24529 phys_addr_t base;
24530
24531 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24532 @@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24533 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24534 * mmio resources as well as potential bios/acpi data regions.
24535 */
24536 +
24537 +#ifdef CONFIG_GRKERNSEC_KMEM
24538 +static unsigned int ebda_start __read_only;
24539 +static unsigned int ebda_end __read_only;
24540 +#endif
24541 +
24542 int devmem_is_allowed(unsigned long pagenr)
24543 {
24544 +#ifdef CONFIG_GRKERNSEC_KMEM
24545 + /* allow BDA */
24546 + if (!pagenr)
24547 + return 1;
24548 + /* allow EBDA */
24549 + if (pagenr >= ebda_start && pagenr < ebda_end)
24550 + return 1;
24551 +#else
24552 + if (!pagenr)
24553 + return 1;
24554 +#ifdef CONFIG_VM86
24555 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24556 + return 1;
24557 +#endif
24558 +#endif
24559 +
24560 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24561 + return 1;
24562 +#ifdef CONFIG_GRKERNSEC_KMEM
24563 + /* throw out everything else below 1MB */
24564 if (pagenr <= 256)
24565 - return 1;
24566 + return 0;
24567 +#endif
24568 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24569 return 0;
24570 if (!page_is_ram(pagenr))
24571 @@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24572 #endif
24573 }
24574
24575 +#ifdef CONFIG_GRKERNSEC_KMEM
24576 +static inline void gr_init_ebda(void)
24577 +{
24578 + unsigned int ebda_addr;
24579 + unsigned int ebda_size = 0;
24580 +
24581 + ebda_addr = get_bios_ebda();
24582 + if (ebda_addr) {
24583 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24584 + ebda_size <<= 10;
24585 + }
24586 + if (ebda_addr && ebda_size) {
24587 + ebda_start = ebda_addr >> PAGE_SHIFT;
24588 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24589 + } else {
24590 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24591 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24592 + }
24593 +}
24594 +#else
24595 +static inline void gr_init_ebda(void) { }
24596 +#endif
24597 +
24598 void free_initmem(void)
24599 {
24600 +#ifdef CONFIG_PAX_KERNEXEC
24601 +#ifdef CONFIG_X86_32
24602 + /* PaX: limit KERNEL_CS to actual size */
24603 + unsigned long addr, limit;
24604 + struct desc_struct d;
24605 + int cpu;
24606 +#else
24607 + pgd_t *pgd;
24608 + pud_t *pud;
24609 + pmd_t *pmd;
24610 + unsigned long addr, end;
24611 +#endif
24612 +#endif
24613 +
24614 + gr_init_ebda();
24615 +
24616 +#ifdef CONFIG_PAX_KERNEXEC
24617 +#ifdef CONFIG_X86_32
24618 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24619 + limit = (limit - 1UL) >> PAGE_SHIFT;
24620 +
24621 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24622 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24623 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24624 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24625 + }
24626 +
24627 + /* PaX: make KERNEL_CS read-only */
24628 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24629 + if (!paravirt_enabled())
24630 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24631 +/*
24632 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24633 + pgd = pgd_offset_k(addr);
24634 + pud = pud_offset(pgd, addr);
24635 + pmd = pmd_offset(pud, addr);
24636 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24637 + }
24638 +*/
24639 +#ifdef CONFIG_X86_PAE
24640 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24641 +/*
24642 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24643 + pgd = pgd_offset_k(addr);
24644 + pud = pud_offset(pgd, addr);
24645 + pmd = pmd_offset(pud, addr);
24646 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24647 + }
24648 +*/
24649 +#endif
24650 +
24651 +#ifdef CONFIG_MODULES
24652 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24653 +#endif
24654 +
24655 +#else
24656 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24657 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24658 + pgd = pgd_offset_k(addr);
24659 + pud = pud_offset(pgd, addr);
24660 + pmd = pmd_offset(pud, addr);
24661 + if (!pmd_present(*pmd))
24662 + continue;
24663 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24664 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24665 + else
24666 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24667 + }
24668 +
24669 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24670 + end = addr + KERNEL_IMAGE_SIZE;
24671 + for (; addr < end; addr += PMD_SIZE) {
24672 + pgd = pgd_offset_k(addr);
24673 + pud = pud_offset(pgd, addr);
24674 + pmd = pmd_offset(pud, addr);
24675 + if (!pmd_present(*pmd))
24676 + continue;
24677 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24678 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24679 + }
24680 +#endif
24681 +
24682 + flush_tlb_all();
24683 +#endif
24684 +
24685 free_init_pages("unused kernel memory",
24686 (unsigned long)(&__init_begin),
24687 (unsigned long)(&__init_end));
24688 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24689 index 575d86f..4987469 100644
24690 --- a/arch/x86/mm/init_32.c
24691 +++ b/arch/x86/mm/init_32.c
24692 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24693 }
24694
24695 /*
24696 - * Creates a middle page table and puts a pointer to it in the
24697 - * given global directory entry. This only returns the gd entry
24698 - * in non-PAE compilation mode, since the middle layer is folded.
24699 - */
24700 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24701 -{
24702 - pud_t *pud;
24703 - pmd_t *pmd_table;
24704 -
24705 -#ifdef CONFIG_X86_PAE
24706 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24707 - if (after_bootmem)
24708 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24709 - else
24710 - pmd_table = (pmd_t *)alloc_low_page();
24711 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24712 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24713 - pud = pud_offset(pgd, 0);
24714 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24715 -
24716 - return pmd_table;
24717 - }
24718 -#endif
24719 - pud = pud_offset(pgd, 0);
24720 - pmd_table = pmd_offset(pud, 0);
24721 -
24722 - return pmd_table;
24723 -}
24724 -
24725 -/*
24726 * Create a page table and place a pointer to it in a middle page
24727 * directory entry:
24728 */
24729 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24730 page_table = (pte_t *)alloc_low_page();
24731
24732 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24733 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24734 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24735 +#else
24736 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24737 +#endif
24738 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24739 }
24740
24741 return pte_offset_kernel(pmd, 0);
24742 }
24743
24744 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24745 +{
24746 + pud_t *pud;
24747 + pmd_t *pmd_table;
24748 +
24749 + pud = pud_offset(pgd, 0);
24750 + pmd_table = pmd_offset(pud, 0);
24751 +
24752 + return pmd_table;
24753 +}
24754 +
24755 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24756 {
24757 int pgd_idx = pgd_index(vaddr);
24758 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24759 int pgd_idx, pmd_idx;
24760 unsigned long vaddr;
24761 pgd_t *pgd;
24762 + pud_t *pud;
24763 pmd_t *pmd;
24764 pte_t *pte = NULL;
24765
24766 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24767 pgd = pgd_base + pgd_idx;
24768
24769 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24770 - pmd = one_md_table_init(pgd);
24771 - pmd = pmd + pmd_index(vaddr);
24772 + pud = pud_offset(pgd, vaddr);
24773 + pmd = pmd_offset(pud, vaddr);
24774 +
24775 +#ifdef CONFIG_X86_PAE
24776 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24777 +#endif
24778 +
24779 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24780 pmd++, pmd_idx++) {
24781 pte = page_table_kmap_check(one_page_table_init(pmd),
24782 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24783 }
24784 }
24785
24786 -static inline int is_kernel_text(unsigned long addr)
24787 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24788 {
24789 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24790 - return 1;
24791 - return 0;
24792 + if ((start > ktla_ktva((unsigned long)_etext) ||
24793 + end <= ktla_ktva((unsigned long)_stext)) &&
24794 + (start > ktla_ktva((unsigned long)_einittext) ||
24795 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24796 +
24797 +#ifdef CONFIG_ACPI_SLEEP
24798 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24799 +#endif
24800 +
24801 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24802 + return 0;
24803 + return 1;
24804 }
24805
24806 /*
24807 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24808 unsigned long last_map_addr = end;
24809 unsigned long start_pfn, end_pfn;
24810 pgd_t *pgd_base = swapper_pg_dir;
24811 - int pgd_idx, pmd_idx, pte_ofs;
24812 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24813 unsigned long pfn;
24814 pgd_t *pgd;
24815 + pud_t *pud;
24816 pmd_t *pmd;
24817 pte_t *pte;
24818 unsigned pages_2m, pages_4k;
24819 @@ -280,8 +281,13 @@ repeat:
24820 pfn = start_pfn;
24821 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24822 pgd = pgd_base + pgd_idx;
24823 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24824 - pmd = one_md_table_init(pgd);
24825 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24826 + pud = pud_offset(pgd, 0);
24827 + pmd = pmd_offset(pud, 0);
24828 +
24829 +#ifdef CONFIG_X86_PAE
24830 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24831 +#endif
24832
24833 if (pfn >= end_pfn)
24834 continue;
24835 @@ -293,14 +299,13 @@ repeat:
24836 #endif
24837 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24838 pmd++, pmd_idx++) {
24839 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24840 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24841
24842 /*
24843 * Map with big pages if possible, otherwise
24844 * create normal page tables:
24845 */
24846 if (use_pse) {
24847 - unsigned int addr2;
24848 pgprot_t prot = PAGE_KERNEL_LARGE;
24849 /*
24850 * first pass will use the same initial
24851 @@ -310,11 +315,7 @@ repeat:
24852 __pgprot(PTE_IDENT_ATTR |
24853 _PAGE_PSE);
24854
24855 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24856 - PAGE_OFFSET + PAGE_SIZE-1;
24857 -
24858 - if (is_kernel_text(addr) ||
24859 - is_kernel_text(addr2))
24860 + if (is_kernel_text(address, address + PMD_SIZE))
24861 prot = PAGE_KERNEL_LARGE_EXEC;
24862
24863 pages_2m++;
24864 @@ -331,7 +332,7 @@ repeat:
24865 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24866 pte += pte_ofs;
24867 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24868 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24869 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24870 pgprot_t prot = PAGE_KERNEL;
24871 /*
24872 * first pass will use the same initial
24873 @@ -339,7 +340,7 @@ repeat:
24874 */
24875 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24876
24877 - if (is_kernel_text(addr))
24878 + if (is_kernel_text(address, address + PAGE_SIZE))
24879 prot = PAGE_KERNEL_EXEC;
24880
24881 pages_4k++;
24882 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24883
24884 pud = pud_offset(pgd, va);
24885 pmd = pmd_offset(pud, va);
24886 - if (!pmd_present(*pmd))
24887 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24888 break;
24889
24890 pte = pte_offset_kernel(pmd, va);
24891 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24892
24893 static void __init pagetable_init(void)
24894 {
24895 - pgd_t *pgd_base = swapper_pg_dir;
24896 -
24897 - permanent_kmaps_init(pgd_base);
24898 + permanent_kmaps_init(swapper_pg_dir);
24899 }
24900
24901 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24902 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24903 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24904
24905 /* user-defined highmem size */
24906 @@ -734,6 +733,12 @@ void __init mem_init(void)
24907
24908 pci_iommu_alloc();
24909
24910 +#ifdef CONFIG_PAX_PER_CPU_PGD
24911 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24912 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24913 + KERNEL_PGD_PTRS);
24914 +#endif
24915 +
24916 #ifdef CONFIG_FLATMEM
24917 BUG_ON(!mem_map);
24918 #endif
24919 @@ -760,7 +765,7 @@ void __init mem_init(void)
24920 reservedpages++;
24921
24922 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24923 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24924 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24925 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24926
24927 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24928 @@ -801,10 +806,10 @@ void __init mem_init(void)
24929 ((unsigned long)&__init_end -
24930 (unsigned long)&__init_begin) >> 10,
24931
24932 - (unsigned long)&_etext, (unsigned long)&_edata,
24933 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24934 + (unsigned long)&_sdata, (unsigned long)&_edata,
24935 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24936
24937 - (unsigned long)&_text, (unsigned long)&_etext,
24938 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24939 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24940
24941 /*
24942 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24943 if (!kernel_set_to_readonly)
24944 return;
24945
24946 + start = ktla_ktva(start);
24947 pr_debug("Set kernel text: %lx - %lx for read write\n",
24948 start, start+size);
24949
24950 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24951 if (!kernel_set_to_readonly)
24952 return;
24953
24954 + start = ktla_ktva(start);
24955 pr_debug("Set kernel text: %lx - %lx for read only\n",
24956 start, start+size);
24957
24958 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24959 unsigned long start = PFN_ALIGN(_text);
24960 unsigned long size = PFN_ALIGN(_etext) - start;
24961
24962 + start = ktla_ktva(start);
24963 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24964 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24965 size >> 10);
24966 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24967 index fc18be0..e539653 100644
24968 --- a/arch/x86/mm/init_64.c
24969 +++ b/arch/x86/mm/init_64.c
24970 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24971 * around without checking the pgd every time.
24972 */
24973
24974 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24975 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24976 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24977
24978 int force_personality32;
24979 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24980
24981 for (address = start; address <= end; address += PGDIR_SIZE) {
24982 const pgd_t *pgd_ref = pgd_offset_k(address);
24983 +
24984 +#ifdef CONFIG_PAX_PER_CPU_PGD
24985 + unsigned long cpu;
24986 +#else
24987 struct page *page;
24988 +#endif
24989
24990 if (pgd_none(*pgd_ref))
24991 continue;
24992
24993 spin_lock(&pgd_lock);
24994 +
24995 +#ifdef CONFIG_PAX_PER_CPU_PGD
24996 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24997 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24998 +#else
24999 list_for_each_entry(page, &pgd_list, lru) {
25000 pgd_t *pgd;
25001 spinlock_t *pgt_lock;
25002 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25003 /* the pgt_lock only for Xen */
25004 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25005 spin_lock(pgt_lock);
25006 +#endif
25007
25008 if (pgd_none(*pgd))
25009 set_pgd(pgd, *pgd_ref);
25010 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25011 BUG_ON(pgd_page_vaddr(*pgd)
25012 != pgd_page_vaddr(*pgd_ref));
25013
25014 +#ifndef CONFIG_PAX_PER_CPU_PGD
25015 spin_unlock(pgt_lock);
25016 +#endif
25017 +
25018 }
25019 spin_unlock(&pgd_lock);
25020 }
25021 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25022 {
25023 if (pgd_none(*pgd)) {
25024 pud_t *pud = (pud_t *)spp_getpage();
25025 - pgd_populate(&init_mm, pgd, pud);
25026 + pgd_populate_kernel(&init_mm, pgd, pud);
25027 if (pud != pud_offset(pgd, 0))
25028 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25029 pud, pud_offset(pgd, 0));
25030 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25031 {
25032 if (pud_none(*pud)) {
25033 pmd_t *pmd = (pmd_t *) spp_getpage();
25034 - pud_populate(&init_mm, pud, pmd);
25035 + pud_populate_kernel(&init_mm, pud, pmd);
25036 if (pmd != pmd_offset(pud, 0))
25037 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25038 pmd, pmd_offset(pud, 0));
25039 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25040 pmd = fill_pmd(pud, vaddr);
25041 pte = fill_pte(pmd, vaddr);
25042
25043 + pax_open_kernel();
25044 set_pte(pte, new_pte);
25045 + pax_close_kernel();
25046
25047 /*
25048 * It's enough to flush this one mapping.
25049 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25050 pgd = pgd_offset_k((unsigned long)__va(phys));
25051 if (pgd_none(*pgd)) {
25052 pud = (pud_t *) spp_getpage();
25053 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25054 - _PAGE_USER));
25055 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25056 }
25057 pud = pud_offset(pgd, (unsigned long)__va(phys));
25058 if (pud_none(*pud)) {
25059 pmd = (pmd_t *) spp_getpage();
25060 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25061 - _PAGE_USER));
25062 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25063 }
25064 pmd = pmd_offset(pud, phys);
25065 BUG_ON(!pmd_none(*pmd));
25066 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25067 if (pfn >= pgt_buf_top)
25068 panic("alloc_low_page: ran out of memory");
25069
25070 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25071 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25072 clear_page(adr);
25073 *phys = pfn * PAGE_SIZE;
25074 return adr;
25075 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25076
25077 phys = __pa(virt);
25078 left = phys & (PAGE_SIZE - 1);
25079 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25080 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25081 adr = (void *)(((unsigned long)adr) | left);
25082
25083 return adr;
25084 @@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25085 unmap_low_page(pmd);
25086
25087 spin_lock(&init_mm.page_table_lock);
25088 - pud_populate(&init_mm, pud, __va(pmd_phys));
25089 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25090 spin_unlock(&init_mm.page_table_lock);
25091 }
25092 __flush_tlb_all();
25093 @@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25094 unmap_low_page(pud);
25095
25096 spin_lock(&init_mm.page_table_lock);
25097 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25098 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25099 spin_unlock(&init_mm.page_table_lock);
25100 pgd_changed = true;
25101 }
25102 @@ -683,6 +697,12 @@ void __init mem_init(void)
25103
25104 pci_iommu_alloc();
25105
25106 +#ifdef CONFIG_PAX_PER_CPU_PGD
25107 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25108 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25109 + KERNEL_PGD_PTRS);
25110 +#endif
25111 +
25112 /* clear_bss() already clear the empty_zero_page */
25113
25114 reservedpages = 0;
25115 @@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25116 static struct vm_area_struct gate_vma = {
25117 .vm_start = VSYSCALL_START,
25118 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25119 - .vm_page_prot = PAGE_READONLY_EXEC,
25120 - .vm_flags = VM_READ | VM_EXEC
25121 + .vm_page_prot = PAGE_READONLY,
25122 + .vm_flags = VM_READ
25123 };
25124
25125 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25126 @@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25127
25128 const char *arch_vma_name(struct vm_area_struct *vma)
25129 {
25130 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25131 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25132 return "[vdso]";
25133 if (vma == &gate_vma)
25134 return "[vsyscall]";
25135 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25136 index 7b179b4..6bd1777 100644
25137 --- a/arch/x86/mm/iomap_32.c
25138 +++ b/arch/x86/mm/iomap_32.c
25139 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25140 type = kmap_atomic_idx_push();
25141 idx = type + KM_TYPE_NR * smp_processor_id();
25142 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25143 +
25144 + pax_open_kernel();
25145 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25146 + pax_close_kernel();
25147 +
25148 arch_flush_lazy_mmu_mode();
25149
25150 return (void *)vaddr;
25151 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25152 index be1ef57..55f0160 100644
25153 --- a/arch/x86/mm/ioremap.c
25154 +++ b/arch/x86/mm/ioremap.c
25155 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25156 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25157 int is_ram = page_is_ram(pfn);
25158
25159 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25160 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25161 return NULL;
25162 WARN_ON_ONCE(is_ram);
25163 }
25164 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25165
25166 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25167 if (page_is_ram(start >> PAGE_SHIFT))
25168 +#ifdef CONFIG_HIGHMEM
25169 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25170 +#endif
25171 return __va(phys);
25172
25173 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25174 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25175 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25176
25177 static __initdata int after_paging_init;
25178 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25179 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25180
25181 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25182 {
25183 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25184 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25185
25186 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25187 - memset(bm_pte, 0, sizeof(bm_pte));
25188 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25189 + pmd_populate_user(&init_mm, pmd, bm_pte);
25190
25191 /*
25192 * The boot-ioremap range spans multiple pmds, for which
25193 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25194 index d87dd6d..bf3fa66 100644
25195 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25196 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25197 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25198 * memory (e.g. tracked pages)? For now, we need this to avoid
25199 * invoking kmemcheck for PnP BIOS calls.
25200 */
25201 - if (regs->flags & X86_VM_MASK)
25202 + if (v8086_mode(regs))
25203 return false;
25204 - if (regs->cs != __KERNEL_CS)
25205 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25206 return false;
25207
25208 pte = kmemcheck_pte_lookup(address);
25209 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25210 index 845df68..1d8d29f 100644
25211 --- a/arch/x86/mm/mmap.c
25212 +++ b/arch/x86/mm/mmap.c
25213 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25214 * Leave an at least ~128 MB hole with possible stack randomization.
25215 */
25216 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25217 -#define MAX_GAP (TASK_SIZE/6*5)
25218 +#define MAX_GAP (pax_task_size/6*5)
25219
25220 static int mmap_is_legacy(void)
25221 {
25222 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25223 return rnd << PAGE_SHIFT;
25224 }
25225
25226 -static unsigned long mmap_base(void)
25227 +static unsigned long mmap_base(struct mm_struct *mm)
25228 {
25229 unsigned long gap = rlimit(RLIMIT_STACK);
25230 + unsigned long pax_task_size = TASK_SIZE;
25231 +
25232 +#ifdef CONFIG_PAX_SEGMEXEC
25233 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25234 + pax_task_size = SEGMEXEC_TASK_SIZE;
25235 +#endif
25236
25237 if (gap < MIN_GAP)
25238 gap = MIN_GAP;
25239 else if (gap > MAX_GAP)
25240 gap = MAX_GAP;
25241
25242 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25243 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25244 }
25245
25246 /*
25247 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25248 * does, but not when emulating X86_32
25249 */
25250 -static unsigned long mmap_legacy_base(void)
25251 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25252 {
25253 - if (mmap_is_ia32())
25254 + if (mmap_is_ia32()) {
25255 +
25256 +#ifdef CONFIG_PAX_SEGMEXEC
25257 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25258 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25259 + else
25260 +#endif
25261 +
25262 return TASK_UNMAPPED_BASE;
25263 - else
25264 + } else
25265 return TASK_UNMAPPED_BASE + mmap_rnd();
25266 }
25267
25268 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25269 void arch_pick_mmap_layout(struct mm_struct *mm)
25270 {
25271 if (mmap_is_legacy()) {
25272 - mm->mmap_base = mmap_legacy_base();
25273 + mm->mmap_base = mmap_legacy_base(mm);
25274 +
25275 +#ifdef CONFIG_PAX_RANDMMAP
25276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25277 + mm->mmap_base += mm->delta_mmap;
25278 +#endif
25279 +
25280 mm->get_unmapped_area = arch_get_unmapped_area;
25281 mm->unmap_area = arch_unmap_area;
25282 } else {
25283 - mm->mmap_base = mmap_base();
25284 + mm->mmap_base = mmap_base(mm);
25285 +
25286 +#ifdef CONFIG_PAX_RANDMMAP
25287 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25288 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25289 +#endif
25290 +
25291 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25292 mm->unmap_area = arch_unmap_area_topdown;
25293 }
25294 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25295 index dc0b727..dc9d71a 100644
25296 --- a/arch/x86/mm/mmio-mod.c
25297 +++ b/arch/x86/mm/mmio-mod.c
25298 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25299 break;
25300 default:
25301 {
25302 - unsigned char *ip = (unsigned char *)instptr;
25303 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25304 my_trace->opcode = MMIO_UNKNOWN_OP;
25305 my_trace->width = 0;
25306 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25307 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25308 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25309 void __iomem *addr)
25310 {
25311 - static atomic_t next_id;
25312 + static atomic_unchecked_t next_id;
25313 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25314 /* These are page-unaligned. */
25315 struct mmiotrace_map map = {
25316 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25317 .private = trace
25318 },
25319 .phys = offset,
25320 - .id = atomic_inc_return(&next_id)
25321 + .id = atomic_inc_return_unchecked(&next_id)
25322 };
25323 map.map_id = trace->id;
25324
25325 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25326 index b008656..773eac2 100644
25327 --- a/arch/x86/mm/pageattr-test.c
25328 +++ b/arch/x86/mm/pageattr-test.c
25329 @@ -36,7 +36,7 @@ enum {
25330
25331 static int pte_testbit(pte_t pte)
25332 {
25333 - return pte_flags(pte) & _PAGE_UNUSED1;
25334 + return pte_flags(pte) & _PAGE_CPA_TEST;
25335 }
25336
25337 struct split_state {
25338 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25339 index e1ebde3..b1e1db38 100644
25340 --- a/arch/x86/mm/pageattr.c
25341 +++ b/arch/x86/mm/pageattr.c
25342 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25343 */
25344 #ifdef CONFIG_PCI_BIOS
25345 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25346 - pgprot_val(forbidden) |= _PAGE_NX;
25347 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25348 #endif
25349
25350 /*
25351 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25352 * Does not cover __inittext since that is gone later on. On
25353 * 64bit we do not enforce !NX on the low mapping
25354 */
25355 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25356 - pgprot_val(forbidden) |= _PAGE_NX;
25357 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25358 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25359
25360 +#ifdef CONFIG_DEBUG_RODATA
25361 /*
25362 * The .rodata section needs to be read-only. Using the pfn
25363 * catches all aliases.
25364 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25365 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25366 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25367 pgprot_val(forbidden) |= _PAGE_RW;
25368 +#endif
25369
25370 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25371 /*
25372 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25373 }
25374 #endif
25375
25376 +#ifdef CONFIG_PAX_KERNEXEC
25377 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25378 + pgprot_val(forbidden) |= _PAGE_RW;
25379 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25380 + }
25381 +#endif
25382 +
25383 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25384
25385 return prot;
25386 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25387 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25388 {
25389 /* change init_mm */
25390 + pax_open_kernel();
25391 set_pte_atomic(kpte, pte);
25392 +
25393 #ifdef CONFIG_X86_32
25394 if (!SHARED_KERNEL_PMD) {
25395 +
25396 +#ifdef CONFIG_PAX_PER_CPU_PGD
25397 + unsigned long cpu;
25398 +#else
25399 struct page *page;
25400 +#endif
25401
25402 +#ifdef CONFIG_PAX_PER_CPU_PGD
25403 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25404 + pgd_t *pgd = get_cpu_pgd(cpu);
25405 +#else
25406 list_for_each_entry(page, &pgd_list, lru) {
25407 - pgd_t *pgd;
25408 + pgd_t *pgd = (pgd_t *)page_address(page);
25409 +#endif
25410 +
25411 pud_t *pud;
25412 pmd_t *pmd;
25413
25414 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25415 + pgd += pgd_index(address);
25416 pud = pud_offset(pgd, address);
25417 pmd = pmd_offset(pud, address);
25418 set_pte_atomic((pte_t *)pmd, pte);
25419 }
25420 }
25421 #endif
25422 + pax_close_kernel();
25423 }
25424
25425 static int
25426 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25427 index f6ff57b..481690f 100644
25428 --- a/arch/x86/mm/pat.c
25429 +++ b/arch/x86/mm/pat.c
25430 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25431
25432 if (!entry) {
25433 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25434 - current->comm, current->pid, start, end);
25435 + current->comm, task_pid_nr(current), start, end);
25436 return -EINVAL;
25437 }
25438
25439 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25440 while (cursor < to) {
25441 if (!devmem_is_allowed(pfn)) {
25442 printk(KERN_INFO
25443 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25444 - current->comm, from, to);
25445 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25446 + current->comm, from, to, cursor);
25447 return 0;
25448 }
25449 cursor += PAGE_SIZE;
25450 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25451 printk(KERN_INFO
25452 "%s:%d ioremap_change_attr failed %s "
25453 "for %Lx-%Lx\n",
25454 - current->comm, current->pid,
25455 + current->comm, task_pid_nr(current),
25456 cattr_name(flags),
25457 base, (unsigned long long)(base + size));
25458 return -EINVAL;
25459 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25460 if (want_flags != flags) {
25461 printk(KERN_WARNING
25462 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25463 - current->comm, current->pid,
25464 + current->comm, task_pid_nr(current),
25465 cattr_name(want_flags),
25466 (unsigned long long)paddr,
25467 (unsigned long long)(paddr + size),
25468 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25469 free_memtype(paddr, paddr + size);
25470 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25471 " for %Lx-%Lx, got %s\n",
25472 - current->comm, current->pid,
25473 + current->comm, task_pid_nr(current),
25474 cattr_name(want_flags),
25475 (unsigned long long)paddr,
25476 (unsigned long long)(paddr + size),
25477 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25478 index 9f0614d..92ae64a 100644
25479 --- a/arch/x86/mm/pf_in.c
25480 +++ b/arch/x86/mm/pf_in.c
25481 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25482 int i;
25483 enum reason_type rv = OTHERS;
25484
25485 - p = (unsigned char *)ins_addr;
25486 + p = (unsigned char *)ktla_ktva(ins_addr);
25487 p += skip_prefix(p, &prf);
25488 p += get_opcode(p, &opcode);
25489
25490 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25491 struct prefix_bits prf;
25492 int i;
25493
25494 - p = (unsigned char *)ins_addr;
25495 + p = (unsigned char *)ktla_ktva(ins_addr);
25496 p += skip_prefix(p, &prf);
25497 p += get_opcode(p, &opcode);
25498
25499 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25500 struct prefix_bits prf;
25501 int i;
25502
25503 - p = (unsigned char *)ins_addr;
25504 + p = (unsigned char *)ktla_ktva(ins_addr);
25505 p += skip_prefix(p, &prf);
25506 p += get_opcode(p, &opcode);
25507
25508 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25509 struct prefix_bits prf;
25510 int i;
25511
25512 - p = (unsigned char *)ins_addr;
25513 + p = (unsigned char *)ktla_ktva(ins_addr);
25514 p += skip_prefix(p, &prf);
25515 p += get_opcode(p, &opcode);
25516 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25517 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25518 struct prefix_bits prf;
25519 int i;
25520
25521 - p = (unsigned char *)ins_addr;
25522 + p = (unsigned char *)ktla_ktva(ins_addr);
25523 p += skip_prefix(p, &prf);
25524 p += get_opcode(p, &opcode);
25525 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25526 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25527 index 8573b83..4f3ed7e 100644
25528 --- a/arch/x86/mm/pgtable.c
25529 +++ b/arch/x86/mm/pgtable.c
25530 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25531 list_del(&page->lru);
25532 }
25533
25534 -#define UNSHARED_PTRS_PER_PGD \
25535 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25536 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25537 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25538
25539 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25540 +{
25541 + unsigned int count = USER_PGD_PTRS;
25542
25543 + while (count--)
25544 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25545 +}
25546 +#endif
25547 +
25548 +#ifdef CONFIG_PAX_PER_CPU_PGD
25549 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25550 +{
25551 + unsigned int count = USER_PGD_PTRS;
25552 +
25553 + while (count--) {
25554 + pgd_t pgd;
25555 +
25556 +#ifdef CONFIG_X86_64
25557 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25558 +#else
25559 + pgd = *src++;
25560 +#endif
25561 +
25562 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25563 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25564 +#endif
25565 +
25566 + *dst++ = pgd;
25567 + }
25568 +
25569 +}
25570 +#endif
25571 +
25572 +#ifdef CONFIG_X86_64
25573 +#define pxd_t pud_t
25574 +#define pyd_t pgd_t
25575 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25576 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25577 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25578 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25579 +#define PYD_SIZE PGDIR_SIZE
25580 +#else
25581 +#define pxd_t pmd_t
25582 +#define pyd_t pud_t
25583 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25584 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25585 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25586 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25587 +#define PYD_SIZE PUD_SIZE
25588 +#endif
25589 +
25590 +#ifdef CONFIG_PAX_PER_CPU_PGD
25591 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25592 +static inline void pgd_dtor(pgd_t *pgd) {}
25593 +#else
25594 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25595 {
25596 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25597 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25598 pgd_list_del(pgd);
25599 spin_unlock(&pgd_lock);
25600 }
25601 +#endif
25602
25603 /*
25604 * List of all pgd's needed for non-PAE so it can invalidate entries
25605 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25606 * -- wli
25607 */
25608
25609 -#ifdef CONFIG_X86_PAE
25610 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25611 /*
25612 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25613 * updating the top-level pagetable entries to guarantee the
25614 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25615 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25616 * and initialize the kernel pmds here.
25617 */
25618 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25619 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25620
25621 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25622 {
25623 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25624 */
25625 flush_tlb_mm(mm);
25626 }
25627 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25628 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25629 #else /* !CONFIG_X86_PAE */
25630
25631 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25632 -#define PREALLOCATED_PMDS 0
25633 +#define PREALLOCATED_PXDS 0
25634
25635 #endif /* CONFIG_X86_PAE */
25636
25637 -static void free_pmds(pmd_t *pmds[])
25638 +static void free_pxds(pxd_t *pxds[])
25639 {
25640 int i;
25641
25642 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25643 - if (pmds[i])
25644 - free_page((unsigned long)pmds[i]);
25645 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25646 + if (pxds[i])
25647 + free_page((unsigned long)pxds[i]);
25648 }
25649
25650 -static int preallocate_pmds(pmd_t *pmds[])
25651 +static int preallocate_pxds(pxd_t *pxds[])
25652 {
25653 int i;
25654 bool failed = false;
25655
25656 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25657 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25658 - if (pmd == NULL)
25659 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25660 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25661 + if (pxd == NULL)
25662 failed = true;
25663 - pmds[i] = pmd;
25664 + pxds[i] = pxd;
25665 }
25666
25667 if (failed) {
25668 - free_pmds(pmds);
25669 + free_pxds(pxds);
25670 return -ENOMEM;
25671 }
25672
25673 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25674 * preallocate which never got a corresponding vma will need to be
25675 * freed manually.
25676 */
25677 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25678 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25679 {
25680 int i;
25681
25682 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25683 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25684 pgd_t pgd = pgdp[i];
25685
25686 if (pgd_val(pgd) != 0) {
25687 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25688 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25689
25690 - pgdp[i] = native_make_pgd(0);
25691 + set_pgd(pgdp + i, native_make_pgd(0));
25692
25693 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25694 - pmd_free(mm, pmd);
25695 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25696 + pxd_free(mm, pxd);
25697 }
25698 }
25699 }
25700
25701 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25702 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25703 {
25704 - pud_t *pud;
25705 + pyd_t *pyd;
25706 unsigned long addr;
25707 int i;
25708
25709 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25710 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25711 return;
25712
25713 - pud = pud_offset(pgd, 0);
25714 +#ifdef CONFIG_X86_64
25715 + pyd = pyd_offset(mm, 0L);
25716 +#else
25717 + pyd = pyd_offset(pgd, 0L);
25718 +#endif
25719
25720 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25721 - i++, pud++, addr += PUD_SIZE) {
25722 - pmd_t *pmd = pmds[i];
25723 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25724 + i++, pyd++, addr += PYD_SIZE) {
25725 + pxd_t *pxd = pxds[i];
25726
25727 if (i >= KERNEL_PGD_BOUNDARY)
25728 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25729 - sizeof(pmd_t) * PTRS_PER_PMD);
25730 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25731 + sizeof(pxd_t) * PTRS_PER_PMD);
25732
25733 - pud_populate(mm, pud, pmd);
25734 + pyd_populate(mm, pyd, pxd);
25735 }
25736 }
25737
25738 pgd_t *pgd_alloc(struct mm_struct *mm)
25739 {
25740 pgd_t *pgd;
25741 - pmd_t *pmds[PREALLOCATED_PMDS];
25742 + pxd_t *pxds[PREALLOCATED_PXDS];
25743
25744 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25745
25746 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25747
25748 mm->pgd = pgd;
25749
25750 - if (preallocate_pmds(pmds) != 0)
25751 + if (preallocate_pxds(pxds) != 0)
25752 goto out_free_pgd;
25753
25754 if (paravirt_pgd_alloc(mm) != 0)
25755 - goto out_free_pmds;
25756 + goto out_free_pxds;
25757
25758 /*
25759 * Make sure that pre-populating the pmds is atomic with
25760 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25761 spin_lock(&pgd_lock);
25762
25763 pgd_ctor(mm, pgd);
25764 - pgd_prepopulate_pmd(mm, pgd, pmds);
25765 + pgd_prepopulate_pxd(mm, pgd, pxds);
25766
25767 spin_unlock(&pgd_lock);
25768
25769 return pgd;
25770
25771 -out_free_pmds:
25772 - free_pmds(pmds);
25773 +out_free_pxds:
25774 + free_pxds(pxds);
25775 out_free_pgd:
25776 free_page((unsigned long)pgd);
25777 out:
25778 @@ -295,7 +356,7 @@ out:
25779
25780 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25781 {
25782 - pgd_mop_up_pmds(mm, pgd);
25783 + pgd_mop_up_pxds(mm, pgd);
25784 pgd_dtor(pgd);
25785 paravirt_pgd_free(mm, pgd);
25786 free_page((unsigned long)pgd);
25787 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25788 index a69bcb8..19068ab 100644
25789 --- a/arch/x86/mm/pgtable_32.c
25790 +++ b/arch/x86/mm/pgtable_32.c
25791 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25792 return;
25793 }
25794 pte = pte_offset_kernel(pmd, vaddr);
25795 +
25796 + pax_open_kernel();
25797 if (pte_val(pteval))
25798 set_pte_at(&init_mm, vaddr, pte, pteval);
25799 else
25800 pte_clear(&init_mm, vaddr, pte);
25801 + pax_close_kernel();
25802
25803 /*
25804 * It's enough to flush this one mapping.
25805 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25806 index 410531d..0f16030 100644
25807 --- a/arch/x86/mm/setup_nx.c
25808 +++ b/arch/x86/mm/setup_nx.c
25809 @@ -5,8 +5,10 @@
25810 #include <asm/pgtable.h>
25811 #include <asm/proto.h>
25812
25813 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25814 static int disable_nx __cpuinitdata;
25815
25816 +#ifndef CONFIG_PAX_PAGEEXEC
25817 /*
25818 * noexec = on|off
25819 *
25820 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25821 return 0;
25822 }
25823 early_param("noexec", noexec_setup);
25824 +#endif
25825 +
25826 +#endif
25827
25828 void __cpuinit x86_configure_nx(void)
25829 {
25830 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25831 if (cpu_has_nx && !disable_nx)
25832 __supported_pte_mask |= _PAGE_NX;
25833 else
25834 +#endif
25835 __supported_pte_mask &= ~_PAGE_NX;
25836 }
25837
25838 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25839 index d6c0418..06a0ad5 100644
25840 --- a/arch/x86/mm/tlb.c
25841 +++ b/arch/x86/mm/tlb.c
25842 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25843 BUG();
25844 cpumask_clear_cpu(cpu,
25845 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25846 +
25847 +#ifndef CONFIG_PAX_PER_CPU_PGD
25848 load_cr3(swapper_pg_dir);
25849 +#endif
25850 +
25851 }
25852 EXPORT_SYMBOL_GPL(leave_mm);
25853
25854 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25855 index 877b9a1..a8ecf42 100644
25856 --- a/arch/x86/net/bpf_jit.S
25857 +++ b/arch/x86/net/bpf_jit.S
25858 @@ -9,6 +9,7 @@
25859 */
25860 #include <linux/linkage.h>
25861 #include <asm/dwarf2.h>
25862 +#include <asm/alternative-asm.h>
25863
25864 /*
25865 * Calling convention :
25866 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25867 jle bpf_slow_path_word
25868 mov (SKBDATA,%rsi),%eax
25869 bswap %eax /* ntohl() */
25870 + pax_force_retaddr
25871 ret
25872
25873 sk_load_half:
25874 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25875 jle bpf_slow_path_half
25876 movzwl (SKBDATA,%rsi),%eax
25877 rol $8,%ax # ntohs()
25878 + pax_force_retaddr
25879 ret
25880
25881 sk_load_byte:
25882 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25883 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25884 jle bpf_slow_path_byte
25885 movzbl (SKBDATA,%rsi),%eax
25886 + pax_force_retaddr
25887 ret
25888
25889 /**
25890 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25891 movzbl (SKBDATA,%rsi),%ebx
25892 and $15,%bl
25893 shl $2,%bl
25894 + pax_force_retaddr
25895 ret
25896
25897 /* rsi contains offset and can be scratched */
25898 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25899 js bpf_error
25900 mov -12(%rbp),%eax
25901 bswap %eax
25902 + pax_force_retaddr
25903 ret
25904
25905 bpf_slow_path_half:
25906 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25907 mov -12(%rbp),%ax
25908 rol $8,%ax
25909 movzwl %ax,%eax
25910 + pax_force_retaddr
25911 ret
25912
25913 bpf_slow_path_byte:
25914 bpf_slow_path_common(1)
25915 js bpf_error
25916 movzbl -12(%rbp),%eax
25917 + pax_force_retaddr
25918 ret
25919
25920 bpf_slow_path_byte_msh:
25921 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25922 and $15,%al
25923 shl $2,%al
25924 xchg %eax,%ebx
25925 + pax_force_retaddr
25926 ret
25927
25928 #define sk_negative_common(SIZE) \
25929 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25930 sk_negative_common(4)
25931 mov (%rax), %eax
25932 bswap %eax
25933 + pax_force_retaddr
25934 ret
25935
25936 bpf_slow_path_half_neg:
25937 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25938 mov (%rax),%ax
25939 rol $8,%ax
25940 movzwl %ax,%eax
25941 + pax_force_retaddr
25942 ret
25943
25944 bpf_slow_path_byte_neg:
25945 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25946 .globl sk_load_byte_negative_offset
25947 sk_negative_common(1)
25948 movzbl (%rax), %eax
25949 + pax_force_retaddr
25950 ret
25951
25952 bpf_slow_path_byte_msh_neg:
25953 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25954 and $15,%al
25955 shl $2,%al
25956 xchg %eax,%ebx
25957 + pax_force_retaddr
25958 ret
25959
25960 bpf_error:
25961 @@ -197,4 +210,5 @@ bpf_error:
25962 xor %eax,%eax
25963 mov -8(%rbp),%rbx
25964 leaveq
25965 + pax_force_retaddr
25966 ret
25967 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25968 index 0597f95..a12c36e 100644
25969 --- a/arch/x86/net/bpf_jit_comp.c
25970 +++ b/arch/x86/net/bpf_jit_comp.c
25971 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25972 set_fs(old_fs);
25973 }
25974
25975 +struct bpf_jit_work {
25976 + struct work_struct work;
25977 + void *image;
25978 +};
25979 +
25980 #define CHOOSE_LOAD_FUNC(K, func) \
25981 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25982
25983 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25984 if (addrs == NULL)
25985 return;
25986
25987 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25988 + if (!fp->work)
25989 + goto out;
25990 +
25991 /* Before first pass, make a rough estimation of addrs[]
25992 * each bpf instruction is translated to less than 64 bytes
25993 */
25994 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25995 break;
25996 default:
25997 /* hmm, too complex filter, give up with jit compiler */
25998 - goto out;
25999 + goto error;
26000 }
26001 ilen = prog - temp;
26002 if (image) {
26003 if (unlikely(proglen + ilen > oldproglen)) {
26004 pr_err("bpb_jit_compile fatal error\n");
26005 - kfree(addrs);
26006 - module_free(NULL, image);
26007 - return;
26008 + module_free_exec(NULL, image);
26009 + goto error;
26010 }
26011 + pax_open_kernel();
26012 memcpy(image + proglen, temp, ilen);
26013 + pax_close_kernel();
26014 }
26015 proglen += ilen;
26016 addrs[i] = proglen;
26017 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26018 break;
26019 }
26020 if (proglen == oldproglen) {
26021 - image = module_alloc(max_t(unsigned int,
26022 - proglen,
26023 - sizeof(struct work_struct)));
26024 + image = module_alloc_exec(proglen);
26025 if (!image)
26026 - goto out;
26027 + goto error;
26028 }
26029 oldproglen = proglen;
26030 }
26031 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26032 bpf_flush_icache(image, image + proglen);
26033
26034 fp->bpf_func = (void *)image;
26035 - }
26036 + } else
26037 +error:
26038 + kfree(fp->work);
26039 +
26040 out:
26041 kfree(addrs);
26042 return;
26043 @@ -648,18 +659,20 @@ out:
26044
26045 static void jit_free_defer(struct work_struct *arg)
26046 {
26047 - module_free(NULL, arg);
26048 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26049 + kfree(arg);
26050 }
26051
26052 /* run from softirq, we must use a work_struct to call
26053 - * module_free() from process context
26054 + * module_free_exec() from process context
26055 */
26056 void bpf_jit_free(struct sk_filter *fp)
26057 {
26058 if (fp->bpf_func != sk_run_filter) {
26059 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26060 + struct work_struct *work = &fp->work->work;
26061
26062 INIT_WORK(work, jit_free_defer);
26063 + fp->work->image = fp->bpf_func;
26064 schedule_work(work);
26065 }
26066 }
26067 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26068 index d6aa6e8..266395a 100644
26069 --- a/arch/x86/oprofile/backtrace.c
26070 +++ b/arch/x86/oprofile/backtrace.c
26071 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26072 struct stack_frame_ia32 *fp;
26073 unsigned long bytes;
26074
26075 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26076 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26077 if (bytes != sizeof(bufhead))
26078 return NULL;
26079
26080 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26081 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26082
26083 oprofile_add_trace(bufhead[0].return_address);
26084
26085 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26086 struct stack_frame bufhead[2];
26087 unsigned long bytes;
26088
26089 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26090 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26091 if (bytes != sizeof(bufhead))
26092 return NULL;
26093
26094 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26095 {
26096 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26097
26098 - if (!user_mode_vm(regs)) {
26099 + if (!user_mode(regs)) {
26100 unsigned long stack = kernel_stack_pointer(regs);
26101 if (depth)
26102 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26103 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26104 index 140942f..8a5cc55 100644
26105 --- a/arch/x86/pci/mrst.c
26106 +++ b/arch/x86/pci/mrst.c
26107 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26108 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26109 pci_mmcfg_late_init();
26110 pcibios_enable_irq = mrst_pci_irq_enable;
26111 - pci_root_ops = pci_mrst_ops;
26112 + pax_open_kernel();
26113 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26114 + pax_close_kernel();
26115 pci_soc_mode = 1;
26116 /* Continue with standard init */
26117 return 1;
26118 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26119 index da8fe05..7ee6704 100644
26120 --- a/arch/x86/pci/pcbios.c
26121 +++ b/arch/x86/pci/pcbios.c
26122 @@ -79,50 +79,93 @@ union bios32 {
26123 static struct {
26124 unsigned long address;
26125 unsigned short segment;
26126 -} bios32_indirect = { 0, __KERNEL_CS };
26127 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26128
26129 /*
26130 * Returns the entry point for the given service, NULL on error
26131 */
26132
26133 -static unsigned long bios32_service(unsigned long service)
26134 +static unsigned long __devinit bios32_service(unsigned long service)
26135 {
26136 unsigned char return_code; /* %al */
26137 unsigned long address; /* %ebx */
26138 unsigned long length; /* %ecx */
26139 unsigned long entry; /* %edx */
26140 unsigned long flags;
26141 + struct desc_struct d, *gdt;
26142
26143 local_irq_save(flags);
26144 - __asm__("lcall *(%%edi); cld"
26145 +
26146 + gdt = get_cpu_gdt_table(smp_processor_id());
26147 +
26148 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26149 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26150 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26151 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26152 +
26153 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26154 : "=a" (return_code),
26155 "=b" (address),
26156 "=c" (length),
26157 "=d" (entry)
26158 : "0" (service),
26159 "1" (0),
26160 - "D" (&bios32_indirect));
26161 + "D" (&bios32_indirect),
26162 + "r"(__PCIBIOS_DS)
26163 + : "memory");
26164 +
26165 + pax_open_kernel();
26166 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26167 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26168 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26169 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26170 + pax_close_kernel();
26171 +
26172 local_irq_restore(flags);
26173
26174 switch (return_code) {
26175 - case 0:
26176 - return address + entry;
26177 - case 0x80: /* Not present */
26178 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26179 - return 0;
26180 - default: /* Shouldn't happen */
26181 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26182 - service, return_code);
26183 + case 0: {
26184 + int cpu;
26185 + unsigned char flags;
26186 +
26187 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26188 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26189 + printk(KERN_WARNING "bios32_service: not valid\n");
26190 return 0;
26191 + }
26192 + address = address + PAGE_OFFSET;
26193 + length += 16UL; /* some BIOSs underreport this... */
26194 + flags = 4;
26195 + if (length >= 64*1024*1024) {
26196 + length >>= PAGE_SHIFT;
26197 + flags |= 8;
26198 + }
26199 +
26200 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26201 + gdt = get_cpu_gdt_table(cpu);
26202 + pack_descriptor(&d, address, length, 0x9b, flags);
26203 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26204 + pack_descriptor(&d, address, length, 0x93, flags);
26205 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26206 + }
26207 + return entry;
26208 + }
26209 + case 0x80: /* Not present */
26210 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26211 + return 0;
26212 + default: /* Shouldn't happen */
26213 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26214 + service, return_code);
26215 + return 0;
26216 }
26217 }
26218
26219 static struct {
26220 unsigned long address;
26221 unsigned short segment;
26222 -} pci_indirect = { 0, __KERNEL_CS };
26223 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26224
26225 -static int pci_bios_present;
26226 +static int pci_bios_present __read_only;
26227
26228 static int __devinit check_pcibios(void)
26229 {
26230 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26231 unsigned long flags, pcibios_entry;
26232
26233 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26234 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26235 + pci_indirect.address = pcibios_entry;
26236
26237 local_irq_save(flags);
26238 - __asm__(
26239 - "lcall *(%%edi); cld\n\t"
26240 + __asm__("movw %w6, %%ds\n\t"
26241 + "lcall *%%ss:(%%edi); cld\n\t"
26242 + "push %%ss\n\t"
26243 + "pop %%ds\n\t"
26244 "jc 1f\n\t"
26245 "xor %%ah, %%ah\n"
26246 "1:"
26247 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26248 "=b" (ebx),
26249 "=c" (ecx)
26250 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26251 - "D" (&pci_indirect)
26252 + "D" (&pci_indirect),
26253 + "r" (__PCIBIOS_DS)
26254 : "memory");
26255 local_irq_restore(flags);
26256
26257 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26258
26259 switch (len) {
26260 case 1:
26261 - __asm__("lcall *(%%esi); cld\n\t"
26262 + __asm__("movw %w6, %%ds\n\t"
26263 + "lcall *%%ss:(%%esi); cld\n\t"
26264 + "push %%ss\n\t"
26265 + "pop %%ds\n\t"
26266 "jc 1f\n\t"
26267 "xor %%ah, %%ah\n"
26268 "1:"
26269 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26270 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26271 "b" (bx),
26272 "D" ((long)reg),
26273 - "S" (&pci_indirect));
26274 + "S" (&pci_indirect),
26275 + "r" (__PCIBIOS_DS));
26276 /*
26277 * Zero-extend the result beyond 8 bits, do not trust the
26278 * BIOS having done it:
26279 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26280 *value &= 0xff;
26281 break;
26282 case 2:
26283 - __asm__("lcall *(%%esi); cld\n\t"
26284 + __asm__("movw %w6, %%ds\n\t"
26285 + "lcall *%%ss:(%%esi); cld\n\t"
26286 + "push %%ss\n\t"
26287 + "pop %%ds\n\t"
26288 "jc 1f\n\t"
26289 "xor %%ah, %%ah\n"
26290 "1:"
26291 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26292 : "1" (PCIBIOS_READ_CONFIG_WORD),
26293 "b" (bx),
26294 "D" ((long)reg),
26295 - "S" (&pci_indirect));
26296 + "S" (&pci_indirect),
26297 + "r" (__PCIBIOS_DS));
26298 /*
26299 * Zero-extend the result beyond 16 bits, do not trust the
26300 * BIOS having done it:
26301 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26302 *value &= 0xffff;
26303 break;
26304 case 4:
26305 - __asm__("lcall *(%%esi); cld\n\t"
26306 + __asm__("movw %w6, %%ds\n\t"
26307 + "lcall *%%ss:(%%esi); cld\n\t"
26308 + "push %%ss\n\t"
26309 + "pop %%ds\n\t"
26310 "jc 1f\n\t"
26311 "xor %%ah, %%ah\n"
26312 "1:"
26313 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26314 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26315 "b" (bx),
26316 "D" ((long)reg),
26317 - "S" (&pci_indirect));
26318 + "S" (&pci_indirect),
26319 + "r" (__PCIBIOS_DS));
26320 break;
26321 }
26322
26323 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26324
26325 switch (len) {
26326 case 1:
26327 - __asm__("lcall *(%%esi); cld\n\t"
26328 + __asm__("movw %w6, %%ds\n\t"
26329 + "lcall *%%ss:(%%esi); cld\n\t"
26330 + "push %%ss\n\t"
26331 + "pop %%ds\n\t"
26332 "jc 1f\n\t"
26333 "xor %%ah, %%ah\n"
26334 "1:"
26335 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26336 "c" (value),
26337 "b" (bx),
26338 "D" ((long)reg),
26339 - "S" (&pci_indirect));
26340 + "S" (&pci_indirect),
26341 + "r" (__PCIBIOS_DS));
26342 break;
26343 case 2:
26344 - __asm__("lcall *(%%esi); cld\n\t"
26345 + __asm__("movw %w6, %%ds\n\t"
26346 + "lcall *%%ss:(%%esi); cld\n\t"
26347 + "push %%ss\n\t"
26348 + "pop %%ds\n\t"
26349 "jc 1f\n\t"
26350 "xor %%ah, %%ah\n"
26351 "1:"
26352 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26353 "c" (value),
26354 "b" (bx),
26355 "D" ((long)reg),
26356 - "S" (&pci_indirect));
26357 + "S" (&pci_indirect),
26358 + "r" (__PCIBIOS_DS));
26359 break;
26360 case 4:
26361 - __asm__("lcall *(%%esi); cld\n\t"
26362 + __asm__("movw %w6, %%ds\n\t"
26363 + "lcall *%%ss:(%%esi); cld\n\t"
26364 + "push %%ss\n\t"
26365 + "pop %%ds\n\t"
26366 "jc 1f\n\t"
26367 "xor %%ah, %%ah\n"
26368 "1:"
26369 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26370 "c" (value),
26371 "b" (bx),
26372 "D" ((long)reg),
26373 - "S" (&pci_indirect));
26374 + "S" (&pci_indirect),
26375 + "r" (__PCIBIOS_DS));
26376 break;
26377 }
26378
26379 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26380
26381 DBG("PCI: Fetching IRQ routing table... ");
26382 __asm__("push %%es\n\t"
26383 + "movw %w8, %%ds\n\t"
26384 "push %%ds\n\t"
26385 "pop %%es\n\t"
26386 - "lcall *(%%esi); cld\n\t"
26387 + "lcall *%%ss:(%%esi); cld\n\t"
26388 "pop %%es\n\t"
26389 + "push %%ss\n\t"
26390 + "pop %%ds\n"
26391 "jc 1f\n\t"
26392 "xor %%ah, %%ah\n"
26393 "1:"
26394 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26395 "1" (0),
26396 "D" ((long) &opt),
26397 "S" (&pci_indirect),
26398 - "m" (opt)
26399 + "m" (opt),
26400 + "r" (__PCIBIOS_DS)
26401 : "memory");
26402 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26403 if (ret & 0xff00)
26404 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26405 {
26406 int ret;
26407
26408 - __asm__("lcall *(%%esi); cld\n\t"
26409 + __asm__("movw %w5, %%ds\n\t"
26410 + "lcall *%%ss:(%%esi); cld\n\t"
26411 + "push %%ss\n\t"
26412 + "pop %%ds\n"
26413 "jc 1f\n\t"
26414 "xor %%ah, %%ah\n"
26415 "1:"
26416 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26417 : "0" (PCIBIOS_SET_PCI_HW_INT),
26418 "b" ((dev->bus->number << 8) | dev->devfn),
26419 "c" ((irq << 8) | (pin + 10)),
26420 - "S" (&pci_indirect));
26421 + "S" (&pci_indirect),
26422 + "r" (__PCIBIOS_DS));
26423 return !(ret & 0xff00);
26424 }
26425 EXPORT_SYMBOL(pcibios_set_irq_routing);
26426 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26427 index 40e4469..1ab536e 100644
26428 --- a/arch/x86/platform/efi/efi_32.c
26429 +++ b/arch/x86/platform/efi/efi_32.c
26430 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26431 {
26432 struct desc_ptr gdt_descr;
26433
26434 +#ifdef CONFIG_PAX_KERNEXEC
26435 + struct desc_struct d;
26436 +#endif
26437 +
26438 local_irq_save(efi_rt_eflags);
26439
26440 load_cr3(initial_page_table);
26441 __flush_tlb_all();
26442
26443 +#ifdef CONFIG_PAX_KERNEXEC
26444 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26445 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26446 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26447 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26448 +#endif
26449 +
26450 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26451 gdt_descr.size = GDT_SIZE - 1;
26452 load_gdt(&gdt_descr);
26453 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26454 {
26455 struct desc_ptr gdt_descr;
26456
26457 +#ifdef CONFIG_PAX_KERNEXEC
26458 + struct desc_struct d;
26459 +
26460 + memset(&d, 0, sizeof d);
26461 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26462 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26463 +#endif
26464 +
26465 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26466 gdt_descr.size = GDT_SIZE - 1;
26467 load_gdt(&gdt_descr);
26468 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26469 index fbe66e6..c5c0dd2 100644
26470 --- a/arch/x86/platform/efi/efi_stub_32.S
26471 +++ b/arch/x86/platform/efi/efi_stub_32.S
26472 @@ -6,7 +6,9 @@
26473 */
26474
26475 #include <linux/linkage.h>
26476 +#include <linux/init.h>
26477 #include <asm/page_types.h>
26478 +#include <asm/segment.h>
26479
26480 /*
26481 * efi_call_phys(void *, ...) is a function with variable parameters.
26482 @@ -20,7 +22,7 @@
26483 * service functions will comply with gcc calling convention, too.
26484 */
26485
26486 -.text
26487 +__INIT
26488 ENTRY(efi_call_phys)
26489 /*
26490 * 0. The function can only be called in Linux kernel. So CS has been
26491 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26492 * The mapping of lower virtual memory has been created in prelog and
26493 * epilog.
26494 */
26495 - movl $1f, %edx
26496 - subl $__PAGE_OFFSET, %edx
26497 - jmp *%edx
26498 + movl $(__KERNEXEC_EFI_DS), %edx
26499 + mov %edx, %ds
26500 + mov %edx, %es
26501 + mov %edx, %ss
26502 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26503 1:
26504
26505 /*
26506 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26507 * parameter 2, ..., param n. To make things easy, we save the return
26508 * address of efi_call_phys in a global variable.
26509 */
26510 - popl %edx
26511 - movl %edx, saved_return_addr
26512 - /* get the function pointer into ECX*/
26513 - popl %ecx
26514 - movl %ecx, efi_rt_function_ptr
26515 - movl $2f, %edx
26516 - subl $__PAGE_OFFSET, %edx
26517 - pushl %edx
26518 + popl (saved_return_addr)
26519 + popl (efi_rt_function_ptr)
26520
26521 /*
26522 * 3. Clear PG bit in %CR0.
26523 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26524 /*
26525 * 5. Call the physical function.
26526 */
26527 - jmp *%ecx
26528 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26529
26530 -2:
26531 /*
26532 * 6. After EFI runtime service returns, control will return to
26533 * following instruction. We'd better readjust stack pointer first.
26534 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26535 movl %cr0, %edx
26536 orl $0x80000000, %edx
26537 movl %edx, %cr0
26538 - jmp 1f
26539 -1:
26540 +
26541 /*
26542 * 8. Now restore the virtual mode from flat mode by
26543 * adding EIP with PAGE_OFFSET.
26544 */
26545 - movl $1f, %edx
26546 - jmp *%edx
26547 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26548 1:
26549 + movl $(__KERNEL_DS), %edx
26550 + mov %edx, %ds
26551 + mov %edx, %es
26552 + mov %edx, %ss
26553
26554 /*
26555 * 9. Balance the stack. And because EAX contain the return value,
26556 * we'd better not clobber it.
26557 */
26558 - leal efi_rt_function_ptr, %edx
26559 - movl (%edx), %ecx
26560 - pushl %ecx
26561 + pushl (efi_rt_function_ptr)
26562
26563 /*
26564 - * 10. Push the saved return address onto the stack and return.
26565 + * 10. Return to the saved return address.
26566 */
26567 - leal saved_return_addr, %edx
26568 - movl (%edx), %ecx
26569 - pushl %ecx
26570 - ret
26571 + jmpl *(saved_return_addr)
26572 ENDPROC(efi_call_phys)
26573 .previous
26574
26575 -.data
26576 +__INITDATA
26577 saved_return_addr:
26578 .long 0
26579 efi_rt_function_ptr:
26580 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26581 index 4c07cca..2c8427d 100644
26582 --- a/arch/x86/platform/efi/efi_stub_64.S
26583 +++ b/arch/x86/platform/efi/efi_stub_64.S
26584 @@ -7,6 +7,7 @@
26585 */
26586
26587 #include <linux/linkage.h>
26588 +#include <asm/alternative-asm.h>
26589
26590 #define SAVE_XMM \
26591 mov %rsp, %rax; \
26592 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26593 call *%rdi
26594 addq $32, %rsp
26595 RESTORE_XMM
26596 + pax_force_retaddr 0, 1
26597 ret
26598 ENDPROC(efi_call0)
26599
26600 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26601 call *%rdi
26602 addq $32, %rsp
26603 RESTORE_XMM
26604 + pax_force_retaddr 0, 1
26605 ret
26606 ENDPROC(efi_call1)
26607
26608 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26609 call *%rdi
26610 addq $32, %rsp
26611 RESTORE_XMM
26612 + pax_force_retaddr 0, 1
26613 ret
26614 ENDPROC(efi_call2)
26615
26616 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26617 call *%rdi
26618 addq $32, %rsp
26619 RESTORE_XMM
26620 + pax_force_retaddr 0, 1
26621 ret
26622 ENDPROC(efi_call3)
26623
26624 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26625 call *%rdi
26626 addq $32, %rsp
26627 RESTORE_XMM
26628 + pax_force_retaddr 0, 1
26629 ret
26630 ENDPROC(efi_call4)
26631
26632 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26633 call *%rdi
26634 addq $48, %rsp
26635 RESTORE_XMM
26636 + pax_force_retaddr 0, 1
26637 ret
26638 ENDPROC(efi_call5)
26639
26640 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26641 call *%rdi
26642 addq $48, %rsp
26643 RESTORE_XMM
26644 + pax_force_retaddr 0, 1
26645 ret
26646 ENDPROC(efi_call6)
26647 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26648 index e31bcd8..f12dc46 100644
26649 --- a/arch/x86/platform/mrst/mrst.c
26650 +++ b/arch/x86/platform/mrst/mrst.c
26651 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26652 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26653 int sfi_mrtc_num;
26654
26655 -static void mrst_power_off(void)
26656 +static __noreturn void mrst_power_off(void)
26657 {
26658 + BUG();
26659 }
26660
26661 -static void mrst_reboot(void)
26662 +static __noreturn void mrst_reboot(void)
26663 {
26664 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26665 + BUG();
26666 }
26667
26668 /* parse all the mtimer info to a static mtimer array */
26669 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26670 index 218cdb1..fd55c08 100644
26671 --- a/arch/x86/power/cpu.c
26672 +++ b/arch/x86/power/cpu.c
26673 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26674 static void fix_processor_context(void)
26675 {
26676 int cpu = smp_processor_id();
26677 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26678 + struct tss_struct *t = init_tss + cpu;
26679
26680 set_tss_desc(cpu, t); /*
26681 * This just modifies memory; should not be
26682 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26683 */
26684
26685 #ifdef CONFIG_X86_64
26686 + pax_open_kernel();
26687 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26688 + pax_close_kernel();
26689
26690 syscall_init(); /* This sets MSR_*STAR and related */
26691 #endif
26692 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26693 index b685296..e00eb65 100644
26694 --- a/arch/x86/tools/relocs.c
26695 +++ b/arch/x86/tools/relocs.c
26696 @@ -12,10 +12,13 @@
26697 #include <regex.h>
26698 #include <tools/le_byteshift.h>
26699
26700 +#include "../../../include/generated/autoconf.h"
26701 +
26702 static void die(char *fmt, ...);
26703
26704 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26705 static Elf32_Ehdr ehdr;
26706 +static Elf32_Phdr *phdr;
26707 static unsigned long reloc_count, reloc_idx;
26708 static unsigned long *relocs;
26709 static unsigned long reloc16_count, reloc16_idx;
26710 @@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26711 }
26712 }
26713
26714 +static void read_phdrs(FILE *fp)
26715 +{
26716 + unsigned int i;
26717 +
26718 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26719 + if (!phdr) {
26720 + die("Unable to allocate %d program headers\n",
26721 + ehdr.e_phnum);
26722 + }
26723 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26724 + die("Seek to %d failed: %s\n",
26725 + ehdr.e_phoff, strerror(errno));
26726 + }
26727 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26728 + die("Cannot read ELF program headers: %s\n",
26729 + strerror(errno));
26730 + }
26731 + for(i = 0; i < ehdr.e_phnum; i++) {
26732 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26733 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26734 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26735 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26736 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26737 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26738 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26739 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26740 + }
26741 +
26742 +}
26743 +
26744 static void read_shdrs(FILE *fp)
26745 {
26746 - int i;
26747 + unsigned int i;
26748 Elf32_Shdr shdr;
26749
26750 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26751 @@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26752
26753 static void read_strtabs(FILE *fp)
26754 {
26755 - int i;
26756 + unsigned int i;
26757 for (i = 0; i < ehdr.e_shnum; i++) {
26758 struct section *sec = &secs[i];
26759 if (sec->shdr.sh_type != SHT_STRTAB) {
26760 @@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26761
26762 static void read_symtabs(FILE *fp)
26763 {
26764 - int i,j;
26765 + unsigned int i,j;
26766 for (i = 0; i < ehdr.e_shnum; i++) {
26767 struct section *sec = &secs[i];
26768 if (sec->shdr.sh_type != SHT_SYMTAB) {
26769 @@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26770
26771 static void read_relocs(FILE *fp)
26772 {
26773 - int i,j;
26774 + unsigned int i,j;
26775 + uint32_t base;
26776 +
26777 for (i = 0; i < ehdr.e_shnum; i++) {
26778 struct section *sec = &secs[i];
26779 if (sec->shdr.sh_type != SHT_REL) {
26780 @@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26781 die("Cannot read symbol table: %s\n",
26782 strerror(errno));
26783 }
26784 + base = 0;
26785 +
26786 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26787 + for (j = 0; j < ehdr.e_phnum; j++) {
26788 + if (phdr[j].p_type != PT_LOAD )
26789 + continue;
26790 + 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)
26791 + continue;
26792 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26793 + break;
26794 + }
26795 +#endif
26796 +
26797 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26798 Elf32_Rel *rel = &sec->reltab[j];
26799 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26800 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26801 rel->r_info = elf32_to_cpu(rel->r_info);
26802 }
26803 }
26804 @@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26805
26806 static void print_absolute_symbols(void)
26807 {
26808 - int i;
26809 + unsigned int i;
26810 printf("Absolute symbols\n");
26811 printf(" Num: Value Size Type Bind Visibility Name\n");
26812 for (i = 0; i < ehdr.e_shnum; i++) {
26813 struct section *sec = &secs[i];
26814 char *sym_strtab;
26815 - int j;
26816 + unsigned int j;
26817
26818 if (sec->shdr.sh_type != SHT_SYMTAB) {
26819 continue;
26820 @@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26821
26822 static void print_absolute_relocs(void)
26823 {
26824 - int i, printed = 0;
26825 + unsigned int i, printed = 0;
26826
26827 for (i = 0; i < ehdr.e_shnum; i++) {
26828 struct section *sec = &secs[i];
26829 struct section *sec_applies, *sec_symtab;
26830 char *sym_strtab;
26831 Elf32_Sym *sh_symtab;
26832 - int j;
26833 + unsigned int j;
26834 if (sec->shdr.sh_type != SHT_REL) {
26835 continue;
26836 }
26837 @@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26838 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26839 int use_real_mode)
26840 {
26841 - int i;
26842 + unsigned int i;
26843 /* Walk through the relocations */
26844 for (i = 0; i < ehdr.e_shnum; i++) {
26845 char *sym_strtab;
26846 Elf32_Sym *sh_symtab;
26847 struct section *sec_applies, *sec_symtab;
26848 - int j;
26849 + unsigned int j;
26850 struct section *sec = &secs[i];
26851
26852 if (sec->shdr.sh_type != SHT_REL) {
26853 @@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26854 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26855 r_type = ELF32_R_TYPE(rel->r_info);
26856
26857 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26858 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26859 + continue;
26860 +
26861 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26862 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26863 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26864 + continue;
26865 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26866 + continue;
26867 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26868 + continue;
26869 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26870 + continue;
26871 +#endif
26872 +
26873 shn_abs = sym->st_shndx == SHN_ABS;
26874
26875 switch (r_type) {
26876 @@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26877
26878 static void emit_relocs(int as_text, int use_real_mode)
26879 {
26880 - int i;
26881 + unsigned int i;
26882 /* Count how many relocations I have and allocate space for them. */
26883 reloc_count = 0;
26884 walk_relocs(count_reloc, use_real_mode);
26885 @@ -801,6 +865,7 @@ int main(int argc, char **argv)
26886 fname, strerror(errno));
26887 }
26888 read_ehdr(fp);
26889 + read_phdrs(fp);
26890 read_shdrs(fp);
26891 read_strtabs(fp);
26892 read_symtabs(fp);
26893 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26894 index fd14be1..e3c79c0 100644
26895 --- a/arch/x86/vdso/Makefile
26896 +++ b/arch/x86/vdso/Makefile
26897 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26898 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26899 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26900
26901 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26902 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26903 GCOV_PROFILE := n
26904
26905 #
26906 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26907 index 66e6d93..587f435 100644
26908 --- a/arch/x86/vdso/vdso32-setup.c
26909 +++ b/arch/x86/vdso/vdso32-setup.c
26910 @@ -25,6 +25,7 @@
26911 #include <asm/tlbflush.h>
26912 #include <asm/vdso.h>
26913 #include <asm/proto.h>
26914 +#include <asm/mman.h>
26915
26916 enum {
26917 VDSO_DISABLED = 0,
26918 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26919 void enable_sep_cpu(void)
26920 {
26921 int cpu = get_cpu();
26922 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26923 + struct tss_struct *tss = init_tss + cpu;
26924
26925 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26926 put_cpu();
26927 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26928 gate_vma.vm_start = FIXADDR_USER_START;
26929 gate_vma.vm_end = FIXADDR_USER_END;
26930 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26931 - gate_vma.vm_page_prot = __P101;
26932 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26933
26934 return 0;
26935 }
26936 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26937 if (compat)
26938 addr = VDSO_HIGH_BASE;
26939 else {
26940 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26941 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26942 if (IS_ERR_VALUE(addr)) {
26943 ret = addr;
26944 goto up_fail;
26945 }
26946 }
26947
26948 - current->mm->context.vdso = (void *)addr;
26949 + current->mm->context.vdso = addr;
26950
26951 if (compat_uses_vma || !compat) {
26952 /*
26953 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26954 }
26955
26956 current_thread_info()->sysenter_return =
26957 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26958 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26959
26960 up_fail:
26961 if (ret)
26962 - current->mm->context.vdso = NULL;
26963 + current->mm->context.vdso = 0;
26964
26965 up_write(&mm->mmap_sem);
26966
26967 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26968
26969 const char *arch_vma_name(struct vm_area_struct *vma)
26970 {
26971 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26972 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26973 return "[vdso]";
26974 +
26975 +#ifdef CONFIG_PAX_SEGMEXEC
26976 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26977 + return "[vdso]";
26978 +#endif
26979 +
26980 return NULL;
26981 }
26982
26983 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26984 * Check to see if the corresponding task was created in compat vdso
26985 * mode.
26986 */
26987 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26988 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26989 return &gate_vma;
26990 return NULL;
26991 }
26992 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26993 index 00aaf04..4a26505 100644
26994 --- a/arch/x86/vdso/vma.c
26995 +++ b/arch/x86/vdso/vma.c
26996 @@ -16,8 +16,6 @@
26997 #include <asm/vdso.h>
26998 #include <asm/page.h>
26999
27000 -unsigned int __read_mostly vdso_enabled = 1;
27001 -
27002 extern char vdso_start[], vdso_end[];
27003 extern unsigned short vdso_sync_cpuid;
27004
27005 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27006 * unaligned here as a result of stack start randomization.
27007 */
27008 addr = PAGE_ALIGN(addr);
27009 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27010
27011 return addr;
27012 }
27013 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27014 unsigned size)
27015 {
27016 struct mm_struct *mm = current->mm;
27017 - unsigned long addr;
27018 + unsigned long addr = 0;
27019 int ret;
27020
27021 - if (!vdso_enabled)
27022 - return 0;
27023 -
27024 down_write(&mm->mmap_sem);
27025 +
27026 +#ifdef CONFIG_PAX_RANDMMAP
27027 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27028 +#endif
27029 +
27030 addr = vdso_addr(mm->start_stack, size);
27031 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27032 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27033 if (IS_ERR_VALUE(addr)) {
27034 ret = addr;
27035 goto up_fail;
27036 }
27037
27038 - current->mm->context.vdso = (void *)addr;
27039 + mm->context.vdso = addr;
27040
27041 ret = install_special_mapping(mm, addr, size,
27042 VM_READ|VM_EXEC|
27043 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27044 pages);
27045 - if (ret) {
27046 - current->mm->context.vdso = NULL;
27047 - goto up_fail;
27048 - }
27049 + if (ret)
27050 + mm->context.vdso = 0;
27051
27052 up_fail:
27053 up_write(&mm->mmap_sem);
27054 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27055 vdsox32_size);
27056 }
27057 #endif
27058 -
27059 -static __init int vdso_setup(char *s)
27060 -{
27061 - vdso_enabled = simple_strtoul(s, NULL, 0);
27062 - return 0;
27063 -}
27064 -__setup("vdso=", vdso_setup);
27065 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27066 index 40edfc3..b4d80ac 100644
27067 --- a/arch/x86/xen/enlighten.c
27068 +++ b/arch/x86/xen/enlighten.c
27069 @@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27070
27071 struct shared_info xen_dummy_shared_info;
27072
27073 -void *xen_initial_gdt;
27074 -
27075 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27076 __read_mostly int xen_have_vector_callback;
27077 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27078 @@ -1165,30 +1163,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27079 #endif
27080 };
27081
27082 -static void xen_reboot(int reason)
27083 +static __noreturn void xen_reboot(int reason)
27084 {
27085 struct sched_shutdown r = { .reason = reason };
27086
27087 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27088 - BUG();
27089 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27090 + BUG();
27091 }
27092
27093 -static void xen_restart(char *msg)
27094 +static __noreturn void xen_restart(char *msg)
27095 {
27096 xen_reboot(SHUTDOWN_reboot);
27097 }
27098
27099 -static void xen_emergency_restart(void)
27100 +static __noreturn void xen_emergency_restart(void)
27101 {
27102 xen_reboot(SHUTDOWN_reboot);
27103 }
27104
27105 -static void xen_machine_halt(void)
27106 +static __noreturn void xen_machine_halt(void)
27107 {
27108 xen_reboot(SHUTDOWN_poweroff);
27109 }
27110
27111 -static void xen_machine_power_off(void)
27112 +static __noreturn void xen_machine_power_off(void)
27113 {
27114 if (pm_power_off)
27115 pm_power_off();
27116 @@ -1291,7 +1289,17 @@ asmlinkage void __init xen_start_kernel(void)
27117 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27118
27119 /* Work out if we support NX */
27120 - x86_configure_nx();
27121 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27122 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27123 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27124 + unsigned l, h;
27125 +
27126 + __supported_pte_mask |= _PAGE_NX;
27127 + rdmsr(MSR_EFER, l, h);
27128 + l |= EFER_NX;
27129 + wrmsr(MSR_EFER, l, h);
27130 + }
27131 +#endif
27132
27133 xen_setup_features();
27134
27135 @@ -1322,13 +1330,6 @@ asmlinkage void __init xen_start_kernel(void)
27136
27137 machine_ops = xen_machine_ops;
27138
27139 - /*
27140 - * The only reliable way to retain the initial address of the
27141 - * percpu gdt_page is to remember it here, so we can go and
27142 - * mark it RW later, when the initial percpu area is freed.
27143 - */
27144 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27145 -
27146 xen_smp_init();
27147
27148 #ifdef CONFIG_ACPI_NUMA
27149 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27150 index 69f5857..0699dc5 100644
27151 --- a/arch/x86/xen/mmu.c
27152 +++ b/arch/x86/xen/mmu.c
27153 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27154 convert_pfn_mfn(init_level4_pgt);
27155 convert_pfn_mfn(level3_ident_pgt);
27156 convert_pfn_mfn(level3_kernel_pgt);
27157 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27158 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27159 + convert_pfn_mfn(level3_vmemmap_pgt);
27160
27161 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27162 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27163 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27164 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27165 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27166 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27167 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27168 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27169 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27170 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27171 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27172 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27173 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27174
27175 @@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27176 pv_mmu_ops.set_pud = xen_set_pud;
27177 #if PAGETABLE_LEVELS == 4
27178 pv_mmu_ops.set_pgd = xen_set_pgd;
27179 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27180 #endif
27181
27182 /* This will work as long as patching hasn't happened yet
27183 @@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27184 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27185 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27186 .set_pgd = xen_set_pgd_hyper,
27187 + .set_pgd_batched = xen_set_pgd_hyper,
27188
27189 .alloc_pud = xen_alloc_pmd_init,
27190 .release_pud = xen_release_pmd_init,
27191 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27192 index 0503c0c..ceb2d16 100644
27193 --- a/arch/x86/xen/smp.c
27194 +++ b/arch/x86/xen/smp.c
27195 @@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27196 {
27197 BUG_ON(smp_processor_id() != 0);
27198 native_smp_prepare_boot_cpu();
27199 -
27200 - /* We've switched to the "real" per-cpu gdt, so make sure the
27201 - old memory can be recycled */
27202 - make_lowmem_page_readwrite(xen_initial_gdt);
27203 -
27204 xen_filter_cpu_maps();
27205 xen_setup_vcpu_info_placement();
27206 }
27207 @@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27208 gdt = get_cpu_gdt_table(cpu);
27209
27210 ctxt->flags = VGCF_IN_KERNEL;
27211 - ctxt->user_regs.ds = __USER_DS;
27212 - ctxt->user_regs.es = __USER_DS;
27213 + ctxt->user_regs.ds = __KERNEL_DS;
27214 + ctxt->user_regs.es = __KERNEL_DS;
27215 ctxt->user_regs.ss = __KERNEL_DS;
27216 #ifdef CONFIG_X86_32
27217 ctxt->user_regs.fs = __KERNEL_PERCPU;
27218 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27219 + savesegment(gs, ctxt->user_regs.gs);
27220 #else
27221 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27222 #endif
27223 @@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27224 int rc;
27225
27226 per_cpu(current_task, cpu) = idle;
27227 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27228 #ifdef CONFIG_X86_32
27229 irq_ctx_init(cpu);
27230 #else
27231 clear_tsk_thread_flag(idle, TIF_FORK);
27232 - per_cpu(kernel_stack, cpu) =
27233 - (unsigned long)task_stack_page(idle) -
27234 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27235 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27236 #endif
27237 xen_setup_runstate_info(cpu);
27238 xen_setup_timer(cpu);
27239 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27240 index b040b0e..8cc4fe0 100644
27241 --- a/arch/x86/xen/xen-asm_32.S
27242 +++ b/arch/x86/xen/xen-asm_32.S
27243 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27244 ESP_OFFSET=4 # bytes pushed onto stack
27245
27246 /*
27247 - * Store vcpu_info pointer for easy access. Do it this way to
27248 - * avoid having to reload %fs
27249 + * Store vcpu_info pointer for easy access.
27250 */
27251 #ifdef CONFIG_SMP
27252 - GET_THREAD_INFO(%eax)
27253 - movl TI_cpu(%eax), %eax
27254 - movl __per_cpu_offset(,%eax,4), %eax
27255 - mov xen_vcpu(%eax), %eax
27256 + push %fs
27257 + mov $(__KERNEL_PERCPU), %eax
27258 + mov %eax, %fs
27259 + mov PER_CPU_VAR(xen_vcpu), %eax
27260 + pop %fs
27261 #else
27262 movl xen_vcpu, %eax
27263 #endif
27264 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27265 index aaa7291..3f77960 100644
27266 --- a/arch/x86/xen/xen-head.S
27267 +++ b/arch/x86/xen/xen-head.S
27268 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27269 #ifdef CONFIG_X86_32
27270 mov %esi,xen_start_info
27271 mov $init_thread_union+THREAD_SIZE,%esp
27272 +#ifdef CONFIG_SMP
27273 + movl $cpu_gdt_table,%edi
27274 + movl $__per_cpu_load,%eax
27275 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27276 + rorl $16,%eax
27277 + movb %al,__KERNEL_PERCPU + 4(%edi)
27278 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27279 + movl $__per_cpu_end - 1,%eax
27280 + subl $__per_cpu_start,%eax
27281 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27282 +#endif
27283 #else
27284 mov %rsi,xen_start_info
27285 mov $init_thread_union+THREAD_SIZE,%rsp
27286 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27287 index b095739..8c17bcd 100644
27288 --- a/arch/x86/xen/xen-ops.h
27289 +++ b/arch/x86/xen/xen-ops.h
27290 @@ -10,8 +10,6 @@
27291 extern const char xen_hypervisor_callback[];
27292 extern const char xen_failsafe_callback[];
27293
27294 -extern void *xen_initial_gdt;
27295 -
27296 struct trap_info;
27297 void xen_copy_trap_info(struct trap_info *traps);
27298
27299 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27300 index 525bd3d..ef888b1 100644
27301 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27302 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27303 @@ -119,9 +119,9 @@
27304 ----------------------------------------------------------------------*/
27305
27306 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27307 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27308 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27309 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27310 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27311
27312 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27313 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27314 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27315 index 2f33760..835e50a 100644
27316 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27317 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27318 @@ -11,6 +11,7 @@
27319 #ifndef _XTENSA_CORE_H
27320 #define _XTENSA_CORE_H
27321
27322 +#include <linux/const.h>
27323
27324 /****************************************************************************
27325 Parameters Useful for Any Code, USER or PRIVILEGED
27326 @@ -112,9 +113,9 @@
27327 ----------------------------------------------------------------------*/
27328
27329 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27330 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27331 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27332 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27333 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27334
27335 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27336 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27337 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27338 index af00795..2bb8105 100644
27339 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27340 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27341 @@ -11,6 +11,7 @@
27342 #ifndef _XTENSA_CORE_CONFIGURATION_H
27343 #define _XTENSA_CORE_CONFIGURATION_H
27344
27345 +#include <linux/const.h>
27346
27347 /****************************************************************************
27348 Parameters Useful for Any Code, USER or PRIVILEGED
27349 @@ -118,9 +119,9 @@
27350 ----------------------------------------------------------------------*/
27351
27352 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27353 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27354 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27355 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27356 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27357
27358 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27359 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27360 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27361 index 58916af..9cb880b 100644
27362 --- a/block/blk-iopoll.c
27363 +++ b/block/blk-iopoll.c
27364 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27365 }
27366 EXPORT_SYMBOL(blk_iopoll_complete);
27367
27368 -static void blk_iopoll_softirq(struct softirq_action *h)
27369 +static void blk_iopoll_softirq(void)
27370 {
27371 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27372 int rearm = 0, budget = blk_iopoll_budget;
27373 diff --git a/block/blk-map.c b/block/blk-map.c
27374 index 623e1cd..ca1e109 100644
27375 --- a/block/blk-map.c
27376 +++ b/block/blk-map.c
27377 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27378 if (!len || !kbuf)
27379 return -EINVAL;
27380
27381 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27382 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27383 if (do_copy)
27384 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27385 else
27386 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27387 index 467c8de..4bddc6d 100644
27388 --- a/block/blk-softirq.c
27389 +++ b/block/blk-softirq.c
27390 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27391 * Softirq action handler - move entries to local list and loop over them
27392 * while passing them to the queue registered handler.
27393 */
27394 -static void blk_done_softirq(struct softirq_action *h)
27395 +static void blk_done_softirq(void)
27396 {
27397 struct list_head *cpu_list, local_list;
27398
27399 diff --git a/block/bsg.c b/block/bsg.c
27400 index ff64ae3..593560c 100644
27401 --- a/block/bsg.c
27402 +++ b/block/bsg.c
27403 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27404 struct sg_io_v4 *hdr, struct bsg_device *bd,
27405 fmode_t has_write_perm)
27406 {
27407 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27408 + unsigned char *cmdptr;
27409 +
27410 if (hdr->request_len > BLK_MAX_CDB) {
27411 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27412 if (!rq->cmd)
27413 return -ENOMEM;
27414 - }
27415 + cmdptr = rq->cmd;
27416 + } else
27417 + cmdptr = tmpcmd;
27418
27419 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27420 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27421 hdr->request_len))
27422 return -EFAULT;
27423
27424 + if (cmdptr != rq->cmd)
27425 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27426 +
27427 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27428 if (blk_verify_command(rq->cmd, has_write_perm))
27429 return -EPERM;
27430 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27431 index 7c668c8..db3521c 100644
27432 --- a/block/compat_ioctl.c
27433 +++ b/block/compat_ioctl.c
27434 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27435 err |= __get_user(f->spec1, &uf->spec1);
27436 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27437 err |= __get_user(name, &uf->name);
27438 - f->name = compat_ptr(name);
27439 + f->name = (void __force_kernel *)compat_ptr(name);
27440 if (err) {
27441 err = -EFAULT;
27442 goto out;
27443 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27444 index 6296b40..417c00f 100644
27445 --- a/block/partitions/efi.c
27446 +++ b/block/partitions/efi.c
27447 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27448 if (!gpt)
27449 return NULL;
27450
27451 + if (!le32_to_cpu(gpt->num_partition_entries))
27452 + return NULL;
27453 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27454 + if (!pte)
27455 + return NULL;
27456 +
27457 count = le32_to_cpu(gpt->num_partition_entries) *
27458 le32_to_cpu(gpt->sizeof_partition_entry);
27459 - if (!count)
27460 - return NULL;
27461 - pte = kzalloc(count, GFP_KERNEL);
27462 - if (!pte)
27463 - return NULL;
27464 -
27465 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27466 (u8 *) pte,
27467 count) < count) {
27468 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27469 index 260fa80..e8f3caf 100644
27470 --- a/block/scsi_ioctl.c
27471 +++ b/block/scsi_ioctl.c
27472 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27473 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27474 struct sg_io_hdr *hdr, fmode_t mode)
27475 {
27476 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27477 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27478 + unsigned char *cmdptr;
27479 +
27480 + if (rq->cmd != rq->__cmd)
27481 + cmdptr = rq->cmd;
27482 + else
27483 + cmdptr = tmpcmd;
27484 +
27485 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27486 return -EFAULT;
27487 +
27488 + if (cmdptr != rq->cmd)
27489 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27490 +
27491 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27492 return -EPERM;
27493
27494 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27495 int err;
27496 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27497 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27498 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27499 + unsigned char *cmdptr;
27500
27501 if (!sic)
27502 return -EINVAL;
27503 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27504 */
27505 err = -EFAULT;
27506 rq->cmd_len = cmdlen;
27507 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27508 +
27509 + if (rq->cmd != rq->__cmd)
27510 + cmdptr = rq->cmd;
27511 + else
27512 + cmdptr = tmpcmd;
27513 +
27514 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27515 goto error;
27516
27517 + if (rq->cmd != cmdptr)
27518 + memcpy(rq->cmd, cmdptr, cmdlen);
27519 +
27520 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27521 goto error;
27522
27523 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27524 index 671d4d6..5f24030 100644
27525 --- a/crypto/cryptd.c
27526 +++ b/crypto/cryptd.c
27527 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27528
27529 struct cryptd_blkcipher_request_ctx {
27530 crypto_completion_t complete;
27531 -};
27532 +} __no_const;
27533
27534 struct cryptd_hash_ctx {
27535 struct crypto_shash *child;
27536 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27537
27538 struct cryptd_aead_request_ctx {
27539 crypto_completion_t complete;
27540 -};
27541 +} __no_const;
27542
27543 static void cryptd_queue_worker(struct work_struct *work);
27544
27545 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27546 index e6defd8..c26a225 100644
27547 --- a/drivers/acpi/apei/cper.c
27548 +++ b/drivers/acpi/apei/cper.c
27549 @@ -38,12 +38,12 @@
27550 */
27551 u64 cper_next_record_id(void)
27552 {
27553 - static atomic64_t seq;
27554 + static atomic64_unchecked_t seq;
27555
27556 - if (!atomic64_read(&seq))
27557 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27558 + if (!atomic64_read_unchecked(&seq))
27559 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27560
27561 - return atomic64_inc_return(&seq);
27562 + return atomic64_inc_return_unchecked(&seq);
27563 }
27564 EXPORT_SYMBOL_GPL(cper_next_record_id);
27565
27566 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27567 index 7586544..636a2f0 100644
27568 --- a/drivers/acpi/ec_sys.c
27569 +++ b/drivers/acpi/ec_sys.c
27570 @@ -12,6 +12,7 @@
27571 #include <linux/acpi.h>
27572 #include <linux/debugfs.h>
27573 #include <linux/module.h>
27574 +#include <linux/uaccess.h>
27575 #include "internal.h"
27576
27577 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27578 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27579 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27580 */
27581 unsigned int size = EC_SPACE_SIZE;
27582 - u8 *data = (u8 *) buf;
27583 + u8 data;
27584 loff_t init_off = *off;
27585 int err = 0;
27586
27587 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27588 size = count;
27589
27590 while (size) {
27591 - err = ec_read(*off, &data[*off - init_off]);
27592 + err = ec_read(*off, &data);
27593 if (err)
27594 return err;
27595 + if (put_user(data, &buf[*off - init_off]))
27596 + return -EFAULT;
27597 *off += 1;
27598 size--;
27599 }
27600 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27601
27602 unsigned int size = count;
27603 loff_t init_off = *off;
27604 - u8 *data = (u8 *) buf;
27605 int err = 0;
27606
27607 if (*off >= EC_SPACE_SIZE)
27608 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27609 }
27610
27611 while (size) {
27612 - u8 byte_write = data[*off - init_off];
27613 + u8 byte_write;
27614 + if (get_user(byte_write, &buf[*off - init_off]))
27615 + return -EFAULT;
27616 err = ec_write(*off, byte_write);
27617 if (err)
27618 return err;
27619 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27620 index 251c7b62..000462d 100644
27621 --- a/drivers/acpi/proc.c
27622 +++ b/drivers/acpi/proc.c
27623 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27624 size_t count, loff_t * ppos)
27625 {
27626 struct list_head *node, *next;
27627 - char strbuf[5];
27628 - char str[5] = "";
27629 - unsigned int len = count;
27630 + char strbuf[5] = {0};
27631
27632 - if (len > 4)
27633 - len = 4;
27634 - if (len < 0)
27635 + if (count > 4)
27636 + count = 4;
27637 + if (copy_from_user(strbuf, buffer, count))
27638 return -EFAULT;
27639 -
27640 - if (copy_from_user(strbuf, buffer, len))
27641 - return -EFAULT;
27642 - strbuf[len] = '\0';
27643 - sscanf(strbuf, "%s", str);
27644 + strbuf[count] = '\0';
27645
27646 mutex_lock(&acpi_device_lock);
27647 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27648 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27649 if (!dev->wakeup.flags.valid)
27650 continue;
27651
27652 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27653 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27654 if (device_can_wakeup(&dev->dev)) {
27655 bool enable = !device_may_wakeup(&dev->dev);
27656 device_set_wakeup_enable(&dev->dev, enable);
27657 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27658 index 0734086..3ad3e4c 100644
27659 --- a/drivers/acpi/processor_driver.c
27660 +++ b/drivers/acpi/processor_driver.c
27661 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27662 return 0;
27663 #endif
27664
27665 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27666 + BUG_ON(pr->id >= nr_cpu_ids);
27667
27668 /*
27669 * Buggy BIOS check
27670 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27671 index d31ee55..8363a8b 100644
27672 --- a/drivers/ata/libata-core.c
27673 +++ b/drivers/ata/libata-core.c
27674 @@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27675 struct ata_port *ap;
27676 unsigned int tag;
27677
27678 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27679 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27680 ap = qc->ap;
27681
27682 qc->flags = 0;
27683 @@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27684 struct ata_port *ap;
27685 struct ata_link *link;
27686
27687 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27688 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27689 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27690 ap = qc->ap;
27691 link = qc->dev->link;
27692 @@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27693 return;
27694
27695 spin_lock(&lock);
27696 + pax_open_kernel();
27697
27698 for (cur = ops->inherits; cur; cur = cur->inherits) {
27699 void **inherit = (void **)cur;
27700 @@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27701 if (IS_ERR(*pp))
27702 *pp = NULL;
27703
27704 - ops->inherits = NULL;
27705 + *(struct ata_port_operations **)&ops->inherits = NULL;
27706
27707 + pax_close_kernel();
27708 spin_unlock(&lock);
27709 }
27710
27711 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27712 index 3239517..343b5f6 100644
27713 --- a/drivers/ata/pata_arasan_cf.c
27714 +++ b/drivers/ata/pata_arasan_cf.c
27715 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27716 /* Handle platform specific quirks */
27717 if (pdata->quirk) {
27718 if (pdata->quirk & CF_BROKEN_PIO) {
27719 - ap->ops->set_piomode = NULL;
27720 + pax_open_kernel();
27721 + *(void **)&ap->ops->set_piomode = NULL;
27722 + pax_close_kernel();
27723 ap->pio_mask = 0;
27724 }
27725 if (pdata->quirk & CF_BROKEN_MWDMA)
27726 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27727 index f9b983a..887b9d8 100644
27728 --- a/drivers/atm/adummy.c
27729 +++ b/drivers/atm/adummy.c
27730 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27731 vcc->pop(vcc, skb);
27732 else
27733 dev_kfree_skb_any(skb);
27734 - atomic_inc(&vcc->stats->tx);
27735 + atomic_inc_unchecked(&vcc->stats->tx);
27736
27737 return 0;
27738 }
27739 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27740 index f8f41e0..1f987dd 100644
27741 --- a/drivers/atm/ambassador.c
27742 +++ b/drivers/atm/ambassador.c
27743 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27744 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27745
27746 // VC layer stats
27747 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27748 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27749
27750 // free the descriptor
27751 kfree (tx_descr);
27752 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27753 dump_skb ("<<<", vc, skb);
27754
27755 // VC layer stats
27756 - atomic_inc(&atm_vcc->stats->rx);
27757 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27758 __net_timestamp(skb);
27759 // end of our responsibility
27760 atm_vcc->push (atm_vcc, skb);
27761 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27762 } else {
27763 PRINTK (KERN_INFO, "dropped over-size frame");
27764 // should we count this?
27765 - atomic_inc(&atm_vcc->stats->rx_drop);
27766 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27767 }
27768
27769 } else {
27770 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27771 }
27772
27773 if (check_area (skb->data, skb->len)) {
27774 - atomic_inc(&atm_vcc->stats->tx_err);
27775 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27776 return -ENOMEM; // ?
27777 }
27778
27779 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27780 index b22d71c..d6e1049 100644
27781 --- a/drivers/atm/atmtcp.c
27782 +++ b/drivers/atm/atmtcp.c
27783 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27784 if (vcc->pop) vcc->pop(vcc,skb);
27785 else dev_kfree_skb(skb);
27786 if (dev_data) return 0;
27787 - atomic_inc(&vcc->stats->tx_err);
27788 + atomic_inc_unchecked(&vcc->stats->tx_err);
27789 return -ENOLINK;
27790 }
27791 size = skb->len+sizeof(struct atmtcp_hdr);
27792 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27793 if (!new_skb) {
27794 if (vcc->pop) vcc->pop(vcc,skb);
27795 else dev_kfree_skb(skb);
27796 - atomic_inc(&vcc->stats->tx_err);
27797 + atomic_inc_unchecked(&vcc->stats->tx_err);
27798 return -ENOBUFS;
27799 }
27800 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27801 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27802 if (vcc->pop) vcc->pop(vcc,skb);
27803 else dev_kfree_skb(skb);
27804 out_vcc->push(out_vcc,new_skb);
27805 - atomic_inc(&vcc->stats->tx);
27806 - atomic_inc(&out_vcc->stats->rx);
27807 + atomic_inc_unchecked(&vcc->stats->tx);
27808 + atomic_inc_unchecked(&out_vcc->stats->rx);
27809 return 0;
27810 }
27811
27812 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27813 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27814 read_unlock(&vcc_sklist_lock);
27815 if (!out_vcc) {
27816 - atomic_inc(&vcc->stats->tx_err);
27817 + atomic_inc_unchecked(&vcc->stats->tx_err);
27818 goto done;
27819 }
27820 skb_pull(skb,sizeof(struct atmtcp_hdr));
27821 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27822 __net_timestamp(new_skb);
27823 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27824 out_vcc->push(out_vcc,new_skb);
27825 - atomic_inc(&vcc->stats->tx);
27826 - atomic_inc(&out_vcc->stats->rx);
27827 + atomic_inc_unchecked(&vcc->stats->tx);
27828 + atomic_inc_unchecked(&out_vcc->stats->rx);
27829 done:
27830 if (vcc->pop) vcc->pop(vcc,skb);
27831 else dev_kfree_skb(skb);
27832 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27833 index 2059ee4..faf51c7 100644
27834 --- a/drivers/atm/eni.c
27835 +++ b/drivers/atm/eni.c
27836 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27837 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27838 vcc->dev->number);
27839 length = 0;
27840 - atomic_inc(&vcc->stats->rx_err);
27841 + atomic_inc_unchecked(&vcc->stats->rx_err);
27842 }
27843 else {
27844 length = ATM_CELL_SIZE-1; /* no HEC */
27845 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27846 size);
27847 }
27848 eff = length = 0;
27849 - atomic_inc(&vcc->stats->rx_err);
27850 + atomic_inc_unchecked(&vcc->stats->rx_err);
27851 }
27852 else {
27853 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27854 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27855 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27856 vcc->dev->number,vcc->vci,length,size << 2,descr);
27857 length = eff = 0;
27858 - atomic_inc(&vcc->stats->rx_err);
27859 + atomic_inc_unchecked(&vcc->stats->rx_err);
27860 }
27861 }
27862 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27863 @@ -767,7 +767,7 @@ rx_dequeued++;
27864 vcc->push(vcc,skb);
27865 pushed++;
27866 }
27867 - atomic_inc(&vcc->stats->rx);
27868 + atomic_inc_unchecked(&vcc->stats->rx);
27869 }
27870 wake_up(&eni_dev->rx_wait);
27871 }
27872 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27873 PCI_DMA_TODEVICE);
27874 if (vcc->pop) vcc->pop(vcc,skb);
27875 else dev_kfree_skb_irq(skb);
27876 - atomic_inc(&vcc->stats->tx);
27877 + atomic_inc_unchecked(&vcc->stats->tx);
27878 wake_up(&eni_dev->tx_wait);
27879 dma_complete++;
27880 }
27881 @@ -1567,7 +1567,7 @@ tx_complete++;
27882 /*--------------------------------- entries ---------------------------------*/
27883
27884
27885 -static const char *media_name[] __devinitdata = {
27886 +static const char *media_name[] __devinitconst = {
27887 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27888 "UTP", "05?", "06?", "07?", /* 4- 7 */
27889 "TAXI","09?", "10?", "11?", /* 8-11 */
27890 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27891 index 86fed1b..6dc4721 100644
27892 --- a/drivers/atm/firestream.c
27893 +++ b/drivers/atm/firestream.c
27894 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27895 }
27896 }
27897
27898 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27899 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27900
27901 fs_dprintk (FS_DEBUG_TXMEM, "i");
27902 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27903 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27904 #endif
27905 skb_put (skb, qe->p1 & 0xffff);
27906 ATM_SKB(skb)->vcc = atm_vcc;
27907 - atomic_inc(&atm_vcc->stats->rx);
27908 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27909 __net_timestamp(skb);
27910 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27911 atm_vcc->push (atm_vcc, skb);
27912 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27913 kfree (pe);
27914 }
27915 if (atm_vcc)
27916 - atomic_inc(&atm_vcc->stats->rx_drop);
27917 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27918 break;
27919 case 0x1f: /* Reassembly abort: no buffers. */
27920 /* Silently increment error counter. */
27921 if (atm_vcc)
27922 - atomic_inc(&atm_vcc->stats->rx_drop);
27923 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27924 break;
27925 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27926 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27927 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27928 index 361f5ae..7fc552d 100644
27929 --- a/drivers/atm/fore200e.c
27930 +++ b/drivers/atm/fore200e.c
27931 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27932 #endif
27933 /* check error condition */
27934 if (*entry->status & STATUS_ERROR)
27935 - atomic_inc(&vcc->stats->tx_err);
27936 + atomic_inc_unchecked(&vcc->stats->tx_err);
27937 else
27938 - atomic_inc(&vcc->stats->tx);
27939 + atomic_inc_unchecked(&vcc->stats->tx);
27940 }
27941 }
27942
27943 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27944 if (skb == NULL) {
27945 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27946
27947 - atomic_inc(&vcc->stats->rx_drop);
27948 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27949 return -ENOMEM;
27950 }
27951
27952 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27953
27954 dev_kfree_skb_any(skb);
27955
27956 - atomic_inc(&vcc->stats->rx_drop);
27957 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27958 return -ENOMEM;
27959 }
27960
27961 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27962
27963 vcc->push(vcc, skb);
27964 - atomic_inc(&vcc->stats->rx);
27965 + atomic_inc_unchecked(&vcc->stats->rx);
27966
27967 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27968
27969 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27970 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27971 fore200e->atm_dev->number,
27972 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27973 - atomic_inc(&vcc->stats->rx_err);
27974 + atomic_inc_unchecked(&vcc->stats->rx_err);
27975 }
27976 }
27977
27978 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27979 goto retry_here;
27980 }
27981
27982 - atomic_inc(&vcc->stats->tx_err);
27983 + atomic_inc_unchecked(&vcc->stats->tx_err);
27984
27985 fore200e->tx_sat++;
27986 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27987 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27988 index b182c2f..1c6fa8a 100644
27989 --- a/drivers/atm/he.c
27990 +++ b/drivers/atm/he.c
27991 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27992
27993 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27994 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27995 - atomic_inc(&vcc->stats->rx_drop);
27996 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27997 goto return_host_buffers;
27998 }
27999
28000 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28001 RBRQ_LEN_ERR(he_dev->rbrq_head)
28002 ? "LEN_ERR" : "",
28003 vcc->vpi, vcc->vci);
28004 - atomic_inc(&vcc->stats->rx_err);
28005 + atomic_inc_unchecked(&vcc->stats->rx_err);
28006 goto return_host_buffers;
28007 }
28008
28009 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28010 vcc->push(vcc, skb);
28011 spin_lock(&he_dev->global_lock);
28012
28013 - atomic_inc(&vcc->stats->rx);
28014 + atomic_inc_unchecked(&vcc->stats->rx);
28015
28016 return_host_buffers:
28017 ++pdus_assembled;
28018 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28019 tpd->vcc->pop(tpd->vcc, tpd->skb);
28020 else
28021 dev_kfree_skb_any(tpd->skb);
28022 - atomic_inc(&tpd->vcc->stats->tx_err);
28023 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28024 }
28025 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28026 return;
28027 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28028 vcc->pop(vcc, skb);
28029 else
28030 dev_kfree_skb_any(skb);
28031 - atomic_inc(&vcc->stats->tx_err);
28032 + atomic_inc_unchecked(&vcc->stats->tx_err);
28033 return -EINVAL;
28034 }
28035
28036 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28037 vcc->pop(vcc, skb);
28038 else
28039 dev_kfree_skb_any(skb);
28040 - atomic_inc(&vcc->stats->tx_err);
28041 + atomic_inc_unchecked(&vcc->stats->tx_err);
28042 return -EINVAL;
28043 }
28044 #endif
28045 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28046 vcc->pop(vcc, skb);
28047 else
28048 dev_kfree_skb_any(skb);
28049 - atomic_inc(&vcc->stats->tx_err);
28050 + atomic_inc_unchecked(&vcc->stats->tx_err);
28051 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28052 return -ENOMEM;
28053 }
28054 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28055 vcc->pop(vcc, skb);
28056 else
28057 dev_kfree_skb_any(skb);
28058 - atomic_inc(&vcc->stats->tx_err);
28059 + atomic_inc_unchecked(&vcc->stats->tx_err);
28060 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28061 return -ENOMEM;
28062 }
28063 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28064 __enqueue_tpd(he_dev, tpd, cid);
28065 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28066
28067 - atomic_inc(&vcc->stats->tx);
28068 + atomic_inc_unchecked(&vcc->stats->tx);
28069
28070 return 0;
28071 }
28072 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28073 index 75fd691..2d20b14 100644
28074 --- a/drivers/atm/horizon.c
28075 +++ b/drivers/atm/horizon.c
28076 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28077 {
28078 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28079 // VC layer stats
28080 - atomic_inc(&vcc->stats->rx);
28081 + atomic_inc_unchecked(&vcc->stats->rx);
28082 __net_timestamp(skb);
28083 // end of our responsibility
28084 vcc->push (vcc, skb);
28085 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28086 dev->tx_iovec = NULL;
28087
28088 // VC layer stats
28089 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28090 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28091
28092 // free the skb
28093 hrz_kfree_skb (skb);
28094 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28095 index 1c05212..c28e200 100644
28096 --- a/drivers/atm/idt77252.c
28097 +++ b/drivers/atm/idt77252.c
28098 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28099 else
28100 dev_kfree_skb(skb);
28101
28102 - atomic_inc(&vcc->stats->tx);
28103 + atomic_inc_unchecked(&vcc->stats->tx);
28104 }
28105
28106 atomic_dec(&scq->used);
28107 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28108 if ((sb = dev_alloc_skb(64)) == NULL) {
28109 printk("%s: Can't allocate buffers for aal0.\n",
28110 card->name);
28111 - atomic_add(i, &vcc->stats->rx_drop);
28112 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28113 break;
28114 }
28115 if (!atm_charge(vcc, sb->truesize)) {
28116 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28117 card->name);
28118 - atomic_add(i - 1, &vcc->stats->rx_drop);
28119 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28120 dev_kfree_skb(sb);
28121 break;
28122 }
28123 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28124 ATM_SKB(sb)->vcc = vcc;
28125 __net_timestamp(sb);
28126 vcc->push(vcc, sb);
28127 - atomic_inc(&vcc->stats->rx);
28128 + atomic_inc_unchecked(&vcc->stats->rx);
28129
28130 cell += ATM_CELL_PAYLOAD;
28131 }
28132 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28133 "(CDC: %08x)\n",
28134 card->name, len, rpp->len, readl(SAR_REG_CDC));
28135 recycle_rx_pool_skb(card, rpp);
28136 - atomic_inc(&vcc->stats->rx_err);
28137 + atomic_inc_unchecked(&vcc->stats->rx_err);
28138 return;
28139 }
28140 if (stat & SAR_RSQE_CRC) {
28141 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28142 recycle_rx_pool_skb(card, rpp);
28143 - atomic_inc(&vcc->stats->rx_err);
28144 + atomic_inc_unchecked(&vcc->stats->rx_err);
28145 return;
28146 }
28147 if (skb_queue_len(&rpp->queue) > 1) {
28148 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28149 RXPRINTK("%s: Can't alloc RX skb.\n",
28150 card->name);
28151 recycle_rx_pool_skb(card, rpp);
28152 - atomic_inc(&vcc->stats->rx_err);
28153 + atomic_inc_unchecked(&vcc->stats->rx_err);
28154 return;
28155 }
28156 if (!atm_charge(vcc, skb->truesize)) {
28157 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28158 __net_timestamp(skb);
28159
28160 vcc->push(vcc, skb);
28161 - atomic_inc(&vcc->stats->rx);
28162 + atomic_inc_unchecked(&vcc->stats->rx);
28163
28164 return;
28165 }
28166 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28167 __net_timestamp(skb);
28168
28169 vcc->push(vcc, skb);
28170 - atomic_inc(&vcc->stats->rx);
28171 + atomic_inc_unchecked(&vcc->stats->rx);
28172
28173 if (skb->truesize > SAR_FB_SIZE_3)
28174 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28175 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28176 if (vcc->qos.aal != ATM_AAL0) {
28177 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28178 card->name, vpi, vci);
28179 - atomic_inc(&vcc->stats->rx_drop);
28180 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28181 goto drop;
28182 }
28183
28184 if ((sb = dev_alloc_skb(64)) == NULL) {
28185 printk("%s: Can't allocate buffers for AAL0.\n",
28186 card->name);
28187 - atomic_inc(&vcc->stats->rx_err);
28188 + atomic_inc_unchecked(&vcc->stats->rx_err);
28189 goto drop;
28190 }
28191
28192 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28193 ATM_SKB(sb)->vcc = vcc;
28194 __net_timestamp(sb);
28195 vcc->push(vcc, sb);
28196 - atomic_inc(&vcc->stats->rx);
28197 + atomic_inc_unchecked(&vcc->stats->rx);
28198
28199 drop:
28200 skb_pull(queue, 64);
28201 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28202
28203 if (vc == NULL) {
28204 printk("%s: NULL connection in send().\n", card->name);
28205 - atomic_inc(&vcc->stats->tx_err);
28206 + atomic_inc_unchecked(&vcc->stats->tx_err);
28207 dev_kfree_skb(skb);
28208 return -EINVAL;
28209 }
28210 if (!test_bit(VCF_TX, &vc->flags)) {
28211 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28212 - atomic_inc(&vcc->stats->tx_err);
28213 + atomic_inc_unchecked(&vcc->stats->tx_err);
28214 dev_kfree_skb(skb);
28215 return -EINVAL;
28216 }
28217 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28218 break;
28219 default:
28220 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28221 - atomic_inc(&vcc->stats->tx_err);
28222 + atomic_inc_unchecked(&vcc->stats->tx_err);
28223 dev_kfree_skb(skb);
28224 return -EINVAL;
28225 }
28226
28227 if (skb_shinfo(skb)->nr_frags != 0) {
28228 printk("%s: No scatter-gather yet.\n", card->name);
28229 - atomic_inc(&vcc->stats->tx_err);
28230 + atomic_inc_unchecked(&vcc->stats->tx_err);
28231 dev_kfree_skb(skb);
28232 return -EINVAL;
28233 }
28234 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28235
28236 err = queue_skb(card, vc, skb, oam);
28237 if (err) {
28238 - atomic_inc(&vcc->stats->tx_err);
28239 + atomic_inc_unchecked(&vcc->stats->tx_err);
28240 dev_kfree_skb(skb);
28241 return err;
28242 }
28243 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28244 skb = dev_alloc_skb(64);
28245 if (!skb) {
28246 printk("%s: Out of memory in send_oam().\n", card->name);
28247 - atomic_inc(&vcc->stats->tx_err);
28248 + atomic_inc_unchecked(&vcc->stats->tx_err);
28249 return -ENOMEM;
28250 }
28251 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28252 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28253 index d438601..8b98495 100644
28254 --- a/drivers/atm/iphase.c
28255 +++ b/drivers/atm/iphase.c
28256 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28257 status = (u_short) (buf_desc_ptr->desc_mode);
28258 if (status & (RX_CER | RX_PTE | RX_OFL))
28259 {
28260 - atomic_inc(&vcc->stats->rx_err);
28261 + atomic_inc_unchecked(&vcc->stats->rx_err);
28262 IF_ERR(printk("IA: bad packet, dropping it");)
28263 if (status & RX_CER) {
28264 IF_ERR(printk(" cause: packet CRC error\n");)
28265 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28266 len = dma_addr - buf_addr;
28267 if (len > iadev->rx_buf_sz) {
28268 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28269 - atomic_inc(&vcc->stats->rx_err);
28270 + atomic_inc_unchecked(&vcc->stats->rx_err);
28271 goto out_free_desc;
28272 }
28273
28274 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28275 ia_vcc = INPH_IA_VCC(vcc);
28276 if (ia_vcc == NULL)
28277 {
28278 - atomic_inc(&vcc->stats->rx_err);
28279 + atomic_inc_unchecked(&vcc->stats->rx_err);
28280 atm_return(vcc, skb->truesize);
28281 dev_kfree_skb_any(skb);
28282 goto INCR_DLE;
28283 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28284 if ((length > iadev->rx_buf_sz) || (length >
28285 (skb->len - sizeof(struct cpcs_trailer))))
28286 {
28287 - atomic_inc(&vcc->stats->rx_err);
28288 + atomic_inc_unchecked(&vcc->stats->rx_err);
28289 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28290 length, skb->len);)
28291 atm_return(vcc, skb->truesize);
28292 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28293
28294 IF_RX(printk("rx_dle_intr: skb push");)
28295 vcc->push(vcc,skb);
28296 - atomic_inc(&vcc->stats->rx);
28297 + atomic_inc_unchecked(&vcc->stats->rx);
28298 iadev->rx_pkt_cnt++;
28299 }
28300 INCR_DLE:
28301 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28302 {
28303 struct k_sonet_stats *stats;
28304 stats = &PRIV(_ia_dev[board])->sonet_stats;
28305 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28306 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28307 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28308 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28309 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28310 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28311 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28312 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28313 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28314 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28315 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28316 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28317 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28318 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28319 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28320 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28321 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28322 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28323 }
28324 ia_cmds.status = 0;
28325 break;
28326 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28327 if ((desc == 0) || (desc > iadev->num_tx_desc))
28328 {
28329 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28330 - atomic_inc(&vcc->stats->tx);
28331 + atomic_inc_unchecked(&vcc->stats->tx);
28332 if (vcc->pop)
28333 vcc->pop(vcc, skb);
28334 else
28335 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28336 ATM_DESC(skb) = vcc->vci;
28337 skb_queue_tail(&iadev->tx_dma_q, skb);
28338
28339 - atomic_inc(&vcc->stats->tx);
28340 + atomic_inc_unchecked(&vcc->stats->tx);
28341 iadev->tx_pkt_cnt++;
28342 /* Increment transaction counter */
28343 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28344
28345 #if 0
28346 /* add flow control logic */
28347 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28348 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28349 if (iavcc->vc_desc_cnt > 10) {
28350 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28351 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28352 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28353 index 68c7588..7036683 100644
28354 --- a/drivers/atm/lanai.c
28355 +++ b/drivers/atm/lanai.c
28356 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28357 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28358 lanai_endtx(lanai, lvcc);
28359 lanai_free_skb(lvcc->tx.atmvcc, skb);
28360 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28361 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28362 }
28363
28364 /* Try to fill the buffer - don't call unless there is backlog */
28365 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28366 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28367 __net_timestamp(skb);
28368 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28369 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28370 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28371 out:
28372 lvcc->rx.buf.ptr = end;
28373 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28374 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28375 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28376 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28377 lanai->stats.service_rxnotaal5++;
28378 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28379 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28380 return 0;
28381 }
28382 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28383 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28384 int bytes;
28385 read_unlock(&vcc_sklist_lock);
28386 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28387 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28388 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28389 lvcc->stats.x.aal5.service_trash++;
28390 bytes = (SERVICE_GET_END(s) * 16) -
28391 (((unsigned long) lvcc->rx.buf.ptr) -
28392 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28393 }
28394 if (s & SERVICE_STREAM) {
28395 read_unlock(&vcc_sklist_lock);
28396 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28397 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28398 lvcc->stats.x.aal5.service_stream++;
28399 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28400 "PDU on VCI %d!\n", lanai->number, vci);
28401 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28402 return 0;
28403 }
28404 DPRINTK("got rx crc error on vci %d\n", vci);
28405 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28406 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28407 lvcc->stats.x.aal5.service_rxcrc++;
28408 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28409 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28410 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28411 index 1c70c45..300718d 100644
28412 --- a/drivers/atm/nicstar.c
28413 +++ b/drivers/atm/nicstar.c
28414 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28415 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28416 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28417 card->index);
28418 - atomic_inc(&vcc->stats->tx_err);
28419 + atomic_inc_unchecked(&vcc->stats->tx_err);
28420 dev_kfree_skb_any(skb);
28421 return -EINVAL;
28422 }
28423 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28424 if (!vc->tx) {
28425 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28426 card->index);
28427 - atomic_inc(&vcc->stats->tx_err);
28428 + atomic_inc_unchecked(&vcc->stats->tx_err);
28429 dev_kfree_skb_any(skb);
28430 return -EINVAL;
28431 }
28432 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28433 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28434 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28435 card->index);
28436 - atomic_inc(&vcc->stats->tx_err);
28437 + atomic_inc_unchecked(&vcc->stats->tx_err);
28438 dev_kfree_skb_any(skb);
28439 return -EINVAL;
28440 }
28441
28442 if (skb_shinfo(skb)->nr_frags != 0) {
28443 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28444 - atomic_inc(&vcc->stats->tx_err);
28445 + atomic_inc_unchecked(&vcc->stats->tx_err);
28446 dev_kfree_skb_any(skb);
28447 return -EINVAL;
28448 }
28449 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28450 }
28451
28452 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28453 - atomic_inc(&vcc->stats->tx_err);
28454 + atomic_inc_unchecked(&vcc->stats->tx_err);
28455 dev_kfree_skb_any(skb);
28456 return -EIO;
28457 }
28458 - atomic_inc(&vcc->stats->tx);
28459 + atomic_inc_unchecked(&vcc->stats->tx);
28460
28461 return 0;
28462 }
28463 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28464 printk
28465 ("nicstar%d: Can't allocate buffers for aal0.\n",
28466 card->index);
28467 - atomic_add(i, &vcc->stats->rx_drop);
28468 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28469 break;
28470 }
28471 if (!atm_charge(vcc, sb->truesize)) {
28472 RXPRINTK
28473 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28474 card->index);
28475 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28476 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28477 dev_kfree_skb_any(sb);
28478 break;
28479 }
28480 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28481 ATM_SKB(sb)->vcc = vcc;
28482 __net_timestamp(sb);
28483 vcc->push(vcc, sb);
28484 - atomic_inc(&vcc->stats->rx);
28485 + atomic_inc_unchecked(&vcc->stats->rx);
28486 cell += ATM_CELL_PAYLOAD;
28487 }
28488
28489 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28490 if (iovb == NULL) {
28491 printk("nicstar%d: Out of iovec buffers.\n",
28492 card->index);
28493 - atomic_inc(&vcc->stats->rx_drop);
28494 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28495 recycle_rx_buf(card, skb);
28496 return;
28497 }
28498 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28499 small or large buffer itself. */
28500 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28501 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28502 - atomic_inc(&vcc->stats->rx_err);
28503 + atomic_inc_unchecked(&vcc->stats->rx_err);
28504 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28505 NS_MAX_IOVECS);
28506 NS_PRV_IOVCNT(iovb) = 0;
28507 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28508 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28509 card->index);
28510 which_list(card, skb);
28511 - atomic_inc(&vcc->stats->rx_err);
28512 + atomic_inc_unchecked(&vcc->stats->rx_err);
28513 recycle_rx_buf(card, skb);
28514 vc->rx_iov = NULL;
28515 recycle_iov_buf(card, iovb);
28516 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28517 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28518 card->index);
28519 which_list(card, skb);
28520 - atomic_inc(&vcc->stats->rx_err);
28521 + atomic_inc_unchecked(&vcc->stats->rx_err);
28522 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28523 NS_PRV_IOVCNT(iovb));
28524 vc->rx_iov = NULL;
28525 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28526 printk(" - PDU size mismatch.\n");
28527 else
28528 printk(".\n");
28529 - atomic_inc(&vcc->stats->rx_err);
28530 + atomic_inc_unchecked(&vcc->stats->rx_err);
28531 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28532 NS_PRV_IOVCNT(iovb));
28533 vc->rx_iov = NULL;
28534 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28535 /* skb points to a small buffer */
28536 if (!atm_charge(vcc, skb->truesize)) {
28537 push_rxbufs(card, skb);
28538 - atomic_inc(&vcc->stats->rx_drop);
28539 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28540 } else {
28541 skb_put(skb, len);
28542 dequeue_sm_buf(card, skb);
28543 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28544 ATM_SKB(skb)->vcc = vcc;
28545 __net_timestamp(skb);
28546 vcc->push(vcc, skb);
28547 - atomic_inc(&vcc->stats->rx);
28548 + atomic_inc_unchecked(&vcc->stats->rx);
28549 }
28550 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28551 struct sk_buff *sb;
28552 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28553 if (len <= NS_SMBUFSIZE) {
28554 if (!atm_charge(vcc, sb->truesize)) {
28555 push_rxbufs(card, sb);
28556 - atomic_inc(&vcc->stats->rx_drop);
28557 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28558 } else {
28559 skb_put(sb, len);
28560 dequeue_sm_buf(card, sb);
28561 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28562 ATM_SKB(sb)->vcc = vcc;
28563 __net_timestamp(sb);
28564 vcc->push(vcc, sb);
28565 - atomic_inc(&vcc->stats->rx);
28566 + atomic_inc_unchecked(&vcc->stats->rx);
28567 }
28568
28569 push_rxbufs(card, skb);
28570 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28571
28572 if (!atm_charge(vcc, skb->truesize)) {
28573 push_rxbufs(card, skb);
28574 - atomic_inc(&vcc->stats->rx_drop);
28575 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28576 } else {
28577 dequeue_lg_buf(card, skb);
28578 #ifdef NS_USE_DESTRUCTORS
28579 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28580 ATM_SKB(skb)->vcc = vcc;
28581 __net_timestamp(skb);
28582 vcc->push(vcc, skb);
28583 - atomic_inc(&vcc->stats->rx);
28584 + atomic_inc_unchecked(&vcc->stats->rx);
28585 }
28586
28587 push_rxbufs(card, sb);
28588 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28589 printk
28590 ("nicstar%d: Out of huge buffers.\n",
28591 card->index);
28592 - atomic_inc(&vcc->stats->rx_drop);
28593 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28594 recycle_iovec_rx_bufs(card,
28595 (struct iovec *)
28596 iovb->data,
28597 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28598 card->hbpool.count++;
28599 } else
28600 dev_kfree_skb_any(hb);
28601 - atomic_inc(&vcc->stats->rx_drop);
28602 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28603 } else {
28604 /* Copy the small buffer to the huge buffer */
28605 sb = (struct sk_buff *)iov->iov_base;
28606 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28607 #endif /* NS_USE_DESTRUCTORS */
28608 __net_timestamp(hb);
28609 vcc->push(vcc, hb);
28610 - atomic_inc(&vcc->stats->rx);
28611 + atomic_inc_unchecked(&vcc->stats->rx);
28612 }
28613 }
28614
28615 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28616 index 9851093..adb2b1e 100644
28617 --- a/drivers/atm/solos-pci.c
28618 +++ b/drivers/atm/solos-pci.c
28619 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28620 }
28621 atm_charge(vcc, skb->truesize);
28622 vcc->push(vcc, skb);
28623 - atomic_inc(&vcc->stats->rx);
28624 + atomic_inc_unchecked(&vcc->stats->rx);
28625 break;
28626
28627 case PKT_STATUS:
28628 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28629 vcc = SKB_CB(oldskb)->vcc;
28630
28631 if (vcc) {
28632 - atomic_inc(&vcc->stats->tx);
28633 + atomic_inc_unchecked(&vcc->stats->tx);
28634 solos_pop(vcc, oldskb);
28635 } else
28636 dev_kfree_skb_irq(oldskb);
28637 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28638 index 0215934..ce9f5b1 100644
28639 --- a/drivers/atm/suni.c
28640 +++ b/drivers/atm/suni.c
28641 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28642
28643
28644 #define ADD_LIMITED(s,v) \
28645 - atomic_add((v),&stats->s); \
28646 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28647 + atomic_add_unchecked((v),&stats->s); \
28648 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28649
28650
28651 static void suni_hz(unsigned long from_timer)
28652 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28653 index 5120a96..e2572bd 100644
28654 --- a/drivers/atm/uPD98402.c
28655 +++ b/drivers/atm/uPD98402.c
28656 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28657 struct sonet_stats tmp;
28658 int error = 0;
28659
28660 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28661 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28662 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28663 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28664 if (zero && !error) {
28665 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28666
28667
28668 #define ADD_LIMITED(s,v) \
28669 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28670 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28671 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28672 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28673 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28674 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28675
28676
28677 static void stat_event(struct atm_dev *dev)
28678 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28679 if (reason & uPD98402_INT_PFM) stat_event(dev);
28680 if (reason & uPD98402_INT_PCO) {
28681 (void) GET(PCOCR); /* clear interrupt cause */
28682 - atomic_add(GET(HECCT),
28683 + atomic_add_unchecked(GET(HECCT),
28684 &PRIV(dev)->sonet_stats.uncorr_hcs);
28685 }
28686 if ((reason & uPD98402_INT_RFO) &&
28687 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28688 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28689 uPD98402_INT_LOS),PIMR); /* enable them */
28690 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28691 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28692 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28693 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28694 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28695 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28696 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28697 return 0;
28698 }
28699
28700 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28701 index abe4e20..83c4727 100644
28702 --- a/drivers/atm/zatm.c
28703 +++ b/drivers/atm/zatm.c
28704 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28705 }
28706 if (!size) {
28707 dev_kfree_skb_irq(skb);
28708 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28709 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28710 continue;
28711 }
28712 if (!atm_charge(vcc,skb->truesize)) {
28713 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28714 skb->len = size;
28715 ATM_SKB(skb)->vcc = vcc;
28716 vcc->push(vcc,skb);
28717 - atomic_inc(&vcc->stats->rx);
28718 + atomic_inc_unchecked(&vcc->stats->rx);
28719 }
28720 zout(pos & 0xffff,MTA(mbx));
28721 #if 0 /* probably a stupid idea */
28722 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28723 skb_queue_head(&zatm_vcc->backlog,skb);
28724 break;
28725 }
28726 - atomic_inc(&vcc->stats->tx);
28727 + atomic_inc_unchecked(&vcc->stats->tx);
28728 wake_up(&zatm_vcc->tx_wait);
28729 }
28730
28731 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28732 index 8493536..31adee0 100644
28733 --- a/drivers/base/devtmpfs.c
28734 +++ b/drivers/base/devtmpfs.c
28735 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28736 if (!thread)
28737 return 0;
28738
28739 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28740 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28741 if (err)
28742 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28743 else
28744 diff --git a/drivers/base/node.c b/drivers/base/node.c
28745 index 90aa2a1..af1a177 100644
28746 --- a/drivers/base/node.c
28747 +++ b/drivers/base/node.c
28748 @@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28749 {
28750 int n;
28751
28752 - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28753 - if (n > 0 && PAGE_SIZE > n + 1) {
28754 - *(buf + n++) = '\n';
28755 - *(buf + n++) = '\0';
28756 - }
28757 + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28758 + buf[n++] = '\n';
28759 + buf[n] = '\0';
28760 return n;
28761 }
28762
28763 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28764 index 2a3e581..3d6a73f 100644
28765 --- a/drivers/base/power/wakeup.c
28766 +++ b/drivers/base/power/wakeup.c
28767 @@ -30,14 +30,14 @@ bool events_check_enabled;
28768 * They need to be modified together atomically, so it's better to use one
28769 * atomic variable to hold them both.
28770 */
28771 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28772 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28773
28774 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28775 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28776
28777 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28778 {
28779 - unsigned int comb = atomic_read(&combined_event_count);
28780 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28781
28782 *cnt = (comb >> IN_PROGRESS_BITS);
28783 *inpr = comb & MAX_IN_PROGRESS;
28784 @@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28785 ws->last_time = ktime_get();
28786
28787 /* Increment the counter of events in progress. */
28788 - atomic_inc(&combined_event_count);
28789 + atomic_inc_unchecked(&combined_event_count);
28790 }
28791
28792 /**
28793 @@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28794 * Increment the counter of registered wakeup events and decrement the
28795 * couter of wakeup events in progress simultaneously.
28796 */
28797 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28798 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28799 }
28800
28801 /**
28802 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28803 index b0f553b..77b928b 100644
28804 --- a/drivers/block/cciss.c
28805 +++ b/drivers/block/cciss.c
28806 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28807 int err;
28808 u32 cp;
28809
28810 + memset(&arg64, 0, sizeof(arg64));
28811 +
28812 err = 0;
28813 err |=
28814 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28815 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28816 while (!list_empty(&h->reqQ)) {
28817 c = list_entry(h->reqQ.next, CommandList_struct, list);
28818 /* can't do anything if fifo is full */
28819 - if ((h->access.fifo_full(h))) {
28820 + if ((h->access->fifo_full(h))) {
28821 dev_warn(&h->pdev->dev, "fifo full\n");
28822 break;
28823 }
28824 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28825 h->Qdepth--;
28826
28827 /* Tell the controller execute command */
28828 - h->access.submit_command(h, c);
28829 + h->access->submit_command(h, c);
28830
28831 /* Put job onto the completed Q */
28832 addQ(&h->cmpQ, c);
28833 @@ -3443,17 +3445,17 @@ startio:
28834
28835 static inline unsigned long get_next_completion(ctlr_info_t *h)
28836 {
28837 - return h->access.command_completed(h);
28838 + return h->access->command_completed(h);
28839 }
28840
28841 static inline int interrupt_pending(ctlr_info_t *h)
28842 {
28843 - return h->access.intr_pending(h);
28844 + return h->access->intr_pending(h);
28845 }
28846
28847 static inline long interrupt_not_for_us(ctlr_info_t *h)
28848 {
28849 - return ((h->access.intr_pending(h) == 0) ||
28850 + return ((h->access->intr_pending(h) == 0) ||
28851 (h->interrupts_enabled == 0));
28852 }
28853
28854 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28855 u32 a;
28856
28857 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28858 - return h->access.command_completed(h);
28859 + return h->access->command_completed(h);
28860
28861 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28862 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28863 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28864 trans_support & CFGTBL_Trans_use_short_tags);
28865
28866 /* Change the access methods to the performant access methods */
28867 - h->access = SA5_performant_access;
28868 + h->access = &SA5_performant_access;
28869 h->transMethod = CFGTBL_Trans_Performant;
28870
28871 return;
28872 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28873 if (prod_index < 0)
28874 return -ENODEV;
28875 h->product_name = products[prod_index].product_name;
28876 - h->access = *(products[prod_index].access);
28877 + h->access = products[prod_index].access;
28878
28879 if (cciss_board_disabled(h)) {
28880 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28881 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28882 }
28883
28884 /* make sure the board interrupts are off */
28885 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28886 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28887 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28888 if (rc)
28889 goto clean2;
28890 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28891 * fake ones to scoop up any residual completions.
28892 */
28893 spin_lock_irqsave(&h->lock, flags);
28894 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28895 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28896 spin_unlock_irqrestore(&h->lock, flags);
28897 free_irq(h->intr[h->intr_mode], h);
28898 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28899 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28900 dev_info(&h->pdev->dev, "Board READY.\n");
28901 dev_info(&h->pdev->dev,
28902 "Waiting for stale completions to drain.\n");
28903 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28904 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28905 msleep(10000);
28906 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28907 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28908
28909 rc = controller_reset_failed(h->cfgtable);
28910 if (rc)
28911 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28912 cciss_scsi_setup(h);
28913
28914 /* Turn the interrupts on so we can service requests */
28915 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28916 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28917
28918 /* Get the firmware version */
28919 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28920 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28921 kfree(flush_buf);
28922 if (return_code != IO_OK)
28923 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28924 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28925 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28926 free_irq(h->intr[h->intr_mode], h);
28927 }
28928
28929 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28930 index 7fda30e..eb5dfe0 100644
28931 --- a/drivers/block/cciss.h
28932 +++ b/drivers/block/cciss.h
28933 @@ -101,7 +101,7 @@ struct ctlr_info
28934 /* information about each logical volume */
28935 drive_info_struct *drv[CISS_MAX_LUN];
28936
28937 - struct access_method access;
28938 + struct access_method *access;
28939
28940 /* queue and queue Info */
28941 struct list_head reqQ;
28942 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28943 index 9125bbe..eede5c8 100644
28944 --- a/drivers/block/cpqarray.c
28945 +++ b/drivers/block/cpqarray.c
28946 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28947 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28948 goto Enomem4;
28949 }
28950 - hba[i]->access.set_intr_mask(hba[i], 0);
28951 + hba[i]->access->set_intr_mask(hba[i], 0);
28952 if (request_irq(hba[i]->intr, do_ida_intr,
28953 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28954 {
28955 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28956 add_timer(&hba[i]->timer);
28957
28958 /* Enable IRQ now that spinlock and rate limit timer are set up */
28959 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28960 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28961
28962 for(j=0; j<NWD; j++) {
28963 struct gendisk *disk = ida_gendisk[i][j];
28964 @@ -694,7 +694,7 @@ DBGINFO(
28965 for(i=0; i<NR_PRODUCTS; i++) {
28966 if (board_id == products[i].board_id) {
28967 c->product_name = products[i].product_name;
28968 - c->access = *(products[i].access);
28969 + c->access = products[i].access;
28970 break;
28971 }
28972 }
28973 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28974 hba[ctlr]->intr = intr;
28975 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28976 hba[ctlr]->product_name = products[j].product_name;
28977 - hba[ctlr]->access = *(products[j].access);
28978 + hba[ctlr]->access = products[j].access;
28979 hba[ctlr]->ctlr = ctlr;
28980 hba[ctlr]->board_id = board_id;
28981 hba[ctlr]->pci_dev = NULL; /* not PCI */
28982 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28983
28984 while((c = h->reqQ) != NULL) {
28985 /* Can't do anything if we're busy */
28986 - if (h->access.fifo_full(h) == 0)
28987 + if (h->access->fifo_full(h) == 0)
28988 return;
28989
28990 /* Get the first entry from the request Q */
28991 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28992 h->Qdepth--;
28993
28994 /* Tell the controller to do our bidding */
28995 - h->access.submit_command(h, c);
28996 + h->access->submit_command(h, c);
28997
28998 /* Get onto the completion Q */
28999 addQ(&h->cmpQ, c);
29000 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29001 unsigned long flags;
29002 __u32 a,a1;
29003
29004 - istat = h->access.intr_pending(h);
29005 + istat = h->access->intr_pending(h);
29006 /* Is this interrupt for us? */
29007 if (istat == 0)
29008 return IRQ_NONE;
29009 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29010 */
29011 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29012 if (istat & FIFO_NOT_EMPTY) {
29013 - while((a = h->access.command_completed(h))) {
29014 + while((a = h->access->command_completed(h))) {
29015 a1 = a; a &= ~3;
29016 if ((c = h->cmpQ) == NULL)
29017 {
29018 @@ -1449,11 +1449,11 @@ static int sendcmd(
29019 /*
29020 * Disable interrupt
29021 */
29022 - info_p->access.set_intr_mask(info_p, 0);
29023 + info_p->access->set_intr_mask(info_p, 0);
29024 /* Make sure there is room in the command FIFO */
29025 /* Actually it should be completely empty at this time. */
29026 for (i = 200000; i > 0; i--) {
29027 - temp = info_p->access.fifo_full(info_p);
29028 + temp = info_p->access->fifo_full(info_p);
29029 if (temp != 0) {
29030 break;
29031 }
29032 @@ -1466,7 +1466,7 @@ DBG(
29033 /*
29034 * Send the cmd
29035 */
29036 - info_p->access.submit_command(info_p, c);
29037 + info_p->access->submit_command(info_p, c);
29038 complete = pollcomplete(ctlr);
29039
29040 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29041 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29042 * we check the new geometry. Then turn interrupts back on when
29043 * we're done.
29044 */
29045 - host->access.set_intr_mask(host, 0);
29046 + host->access->set_intr_mask(host, 0);
29047 getgeometry(ctlr);
29048 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29049 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29050
29051 for(i=0; i<NWD; i++) {
29052 struct gendisk *disk = ida_gendisk[ctlr][i];
29053 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29054 /* Wait (up to 2 seconds) for a command to complete */
29055
29056 for (i = 200000; i > 0; i--) {
29057 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29058 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29059 if (done == 0) {
29060 udelay(10); /* a short fixed delay */
29061 } else
29062 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29063 index be73e9d..7fbf140 100644
29064 --- a/drivers/block/cpqarray.h
29065 +++ b/drivers/block/cpqarray.h
29066 @@ -99,7 +99,7 @@ struct ctlr_info {
29067 drv_info_t drv[NWD];
29068 struct proc_dir_entry *proc;
29069
29070 - struct access_method access;
29071 + struct access_method *access;
29072
29073 cmdlist_t *reqQ;
29074 cmdlist_t *cmpQ;
29075 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29076 index 8d68056..e67050f 100644
29077 --- a/drivers/block/drbd/drbd_int.h
29078 +++ b/drivers/block/drbd/drbd_int.h
29079 @@ -736,7 +736,7 @@ struct drbd_request;
29080 struct drbd_epoch {
29081 struct list_head list;
29082 unsigned int barrier_nr;
29083 - atomic_t epoch_size; /* increased on every request added. */
29084 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29085 atomic_t active; /* increased on every req. added, and dec on every finished. */
29086 unsigned long flags;
29087 };
29088 @@ -1108,7 +1108,7 @@ struct drbd_conf {
29089 void *int_dig_in;
29090 void *int_dig_vv;
29091 wait_queue_head_t seq_wait;
29092 - atomic_t packet_seq;
29093 + atomic_unchecked_t packet_seq;
29094 unsigned int peer_seq;
29095 spinlock_t peer_seq_lock;
29096 unsigned int minor;
29097 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29098
29099 static inline void drbd_tcp_cork(struct socket *sock)
29100 {
29101 - int __user val = 1;
29102 + int val = 1;
29103 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29104 - (char __user *)&val, sizeof(val));
29105 + (char __force_user *)&val, sizeof(val));
29106 }
29107
29108 static inline void drbd_tcp_uncork(struct socket *sock)
29109 {
29110 - int __user val = 0;
29111 + int val = 0;
29112 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29113 - (char __user *)&val, sizeof(val));
29114 + (char __force_user *)&val, sizeof(val));
29115 }
29116
29117 static inline void drbd_tcp_nodelay(struct socket *sock)
29118 {
29119 - int __user val = 1;
29120 + int val = 1;
29121 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29122 - (char __user *)&val, sizeof(val));
29123 + (char __force_user *)&val, sizeof(val));
29124 }
29125
29126 static inline void drbd_tcp_quickack(struct socket *sock)
29127 {
29128 - int __user val = 2;
29129 + int val = 2;
29130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29131 - (char __user *)&val, sizeof(val));
29132 + (char __force_user *)&val, sizeof(val));
29133 }
29134
29135 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29136 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29137 index 211fc44..c5116f1 100644
29138 --- a/drivers/block/drbd/drbd_main.c
29139 +++ b/drivers/block/drbd/drbd_main.c
29140 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29141 p.sector = sector;
29142 p.block_id = block_id;
29143 p.blksize = blksize;
29144 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29145 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29146
29147 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29148 return false;
29149 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29150 p.sector = cpu_to_be64(req->sector);
29151 p.block_id = (unsigned long)req;
29152 p.seq_num = cpu_to_be32(req->seq_num =
29153 - atomic_add_return(1, &mdev->packet_seq));
29154 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29155
29156 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29157
29158 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29159 atomic_set(&mdev->unacked_cnt, 0);
29160 atomic_set(&mdev->local_cnt, 0);
29161 atomic_set(&mdev->net_cnt, 0);
29162 - atomic_set(&mdev->packet_seq, 0);
29163 + atomic_set_unchecked(&mdev->packet_seq, 0);
29164 atomic_set(&mdev->pp_in_use, 0);
29165 atomic_set(&mdev->pp_in_use_by_net, 0);
29166 atomic_set(&mdev->rs_sect_in, 0);
29167 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29168 mdev->receiver.t_state);
29169
29170 /* no need to lock it, I'm the only thread alive */
29171 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29172 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29173 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29174 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29175 mdev->al_writ_cnt =
29176 mdev->bm_writ_cnt =
29177 mdev->read_cnt =
29178 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29179 index 946166e..356b39a 100644
29180 --- a/drivers/block/drbd/drbd_nl.c
29181 +++ b/drivers/block/drbd/drbd_nl.c
29182 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29183 module_put(THIS_MODULE);
29184 }
29185
29186 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29187 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29188
29189 static unsigned short *
29190 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29191 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29192 cn_reply->id.idx = CN_IDX_DRBD;
29193 cn_reply->id.val = CN_VAL_DRBD;
29194
29195 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29196 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29197 cn_reply->ack = 0; /* not used here. */
29198 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29199 (int)((char *)tl - (char *)reply->tag_list);
29200 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29201 cn_reply->id.idx = CN_IDX_DRBD;
29202 cn_reply->id.val = CN_VAL_DRBD;
29203
29204 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29205 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29206 cn_reply->ack = 0; /* not used here. */
29207 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29208 (int)((char *)tl - (char *)reply->tag_list);
29209 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29210 cn_reply->id.idx = CN_IDX_DRBD;
29211 cn_reply->id.val = CN_VAL_DRBD;
29212
29213 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29214 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29215 cn_reply->ack = 0; // not used here.
29216 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29217 (int)((char*)tl - (char*)reply->tag_list);
29218 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29219 cn_reply->id.idx = CN_IDX_DRBD;
29220 cn_reply->id.val = CN_VAL_DRBD;
29221
29222 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29223 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29224 cn_reply->ack = 0; /* not used here. */
29225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29226 (int)((char *)tl - (char *)reply->tag_list);
29227 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29228 index 43beaca..4a5b1dd 100644
29229 --- a/drivers/block/drbd/drbd_receiver.c
29230 +++ b/drivers/block/drbd/drbd_receiver.c
29231 @@ -894,7 +894,7 @@ retry:
29232 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29233 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29234
29235 - atomic_set(&mdev->packet_seq, 0);
29236 + atomic_set_unchecked(&mdev->packet_seq, 0);
29237 mdev->peer_seq = 0;
29238
29239 drbd_thread_start(&mdev->asender);
29240 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29241 do {
29242 next_epoch = NULL;
29243
29244 - epoch_size = atomic_read(&epoch->epoch_size);
29245 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29246
29247 switch (ev & ~EV_CLEANUP) {
29248 case EV_PUT:
29249 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29250 rv = FE_DESTROYED;
29251 } else {
29252 epoch->flags = 0;
29253 - atomic_set(&epoch->epoch_size, 0);
29254 + atomic_set_unchecked(&epoch->epoch_size, 0);
29255 /* atomic_set(&epoch->active, 0); is already zero */
29256 if (rv == FE_STILL_LIVE)
29257 rv = FE_RECYCLED;
29258 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29259 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29260 drbd_flush(mdev);
29261
29262 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29263 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29264 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29265 if (epoch)
29266 break;
29267 }
29268
29269 epoch = mdev->current_epoch;
29270 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29271 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29272
29273 D_ASSERT(atomic_read(&epoch->active) == 0);
29274 D_ASSERT(epoch->flags == 0);
29275 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29276 }
29277
29278 epoch->flags = 0;
29279 - atomic_set(&epoch->epoch_size, 0);
29280 + atomic_set_unchecked(&epoch->epoch_size, 0);
29281 atomic_set(&epoch->active, 0);
29282
29283 spin_lock(&mdev->epoch_lock);
29284 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29285 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29286 list_add(&epoch->list, &mdev->current_epoch->list);
29287 mdev->current_epoch = epoch;
29288 mdev->epochs++;
29289 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29290 spin_unlock(&mdev->peer_seq_lock);
29291
29292 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29293 - atomic_inc(&mdev->current_epoch->epoch_size);
29294 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29295 return drbd_drain_block(mdev, data_size);
29296 }
29297
29298 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29299
29300 spin_lock(&mdev->epoch_lock);
29301 e->epoch = mdev->current_epoch;
29302 - atomic_inc(&e->epoch->epoch_size);
29303 + atomic_inc_unchecked(&e->epoch->epoch_size);
29304 atomic_inc(&e->epoch->active);
29305 spin_unlock(&mdev->epoch_lock);
29306
29307 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29308 D_ASSERT(list_empty(&mdev->done_ee));
29309
29310 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29311 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29312 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29313 D_ASSERT(list_empty(&mdev->current_epoch->list));
29314 }
29315
29316 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29317 index bbca966..65e37dd 100644
29318 --- a/drivers/block/loop.c
29319 +++ b/drivers/block/loop.c
29320 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29321 mm_segment_t old_fs = get_fs();
29322
29323 set_fs(get_ds());
29324 - bw = file->f_op->write(file, buf, len, &pos);
29325 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29326 set_fs(old_fs);
29327 if (likely(bw == len))
29328 return 0;
29329 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29330 index ee94686..3e09ad3 100644
29331 --- a/drivers/char/Kconfig
29332 +++ b/drivers/char/Kconfig
29333 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29334
29335 config DEVKMEM
29336 bool "/dev/kmem virtual device support"
29337 - default y
29338 + default n
29339 + depends on !GRKERNSEC_KMEM
29340 help
29341 Say Y here if you want to support the /dev/kmem device. The
29342 /dev/kmem device is rarely used, but can be used for certain
29343 @@ -581,6 +582,7 @@ config DEVPORT
29344 bool
29345 depends on !M68K
29346 depends on ISA || PCI
29347 + depends on !GRKERNSEC_KMEM
29348 default y
29349
29350 source "drivers/s390/char/Kconfig"
29351 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29352 index 2e04433..22afc64 100644
29353 --- a/drivers/char/agp/frontend.c
29354 +++ b/drivers/char/agp/frontend.c
29355 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29356 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29357 return -EFAULT;
29358
29359 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29360 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29361 return -EFAULT;
29362
29363 client = agp_find_client_by_pid(reserve.pid);
29364 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29365 index 21cb980..f15107c 100644
29366 --- a/drivers/char/genrtc.c
29367 +++ b/drivers/char/genrtc.c
29368 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29369 switch (cmd) {
29370
29371 case RTC_PLL_GET:
29372 + memset(&pll, 0, sizeof(pll));
29373 if (get_rtc_pll(&pll))
29374 return -EINVAL;
29375 else
29376 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29377 index dfd7876..c0b0885 100644
29378 --- a/drivers/char/hpet.c
29379 +++ b/drivers/char/hpet.c
29380 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29381 }
29382
29383 static int
29384 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29385 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29386 struct hpet_info *info)
29387 {
29388 struct hpet_timer __iomem *timer;
29389 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29390 index 2c29942..604c5ba 100644
29391 --- a/drivers/char/ipmi/ipmi_msghandler.c
29392 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29393 @@ -420,7 +420,7 @@ struct ipmi_smi {
29394 struct proc_dir_entry *proc_dir;
29395 char proc_dir_name[10];
29396
29397 - atomic_t stats[IPMI_NUM_STATS];
29398 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29399
29400 /*
29401 * run_to_completion duplicate of smb_info, smi_info
29402 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29403
29404
29405 #define ipmi_inc_stat(intf, stat) \
29406 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29407 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29408 #define ipmi_get_stat(intf, stat) \
29409 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29410 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29411
29412 static int is_lan_addr(struct ipmi_addr *addr)
29413 {
29414 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29415 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29416 init_waitqueue_head(&intf->waitq);
29417 for (i = 0; i < IPMI_NUM_STATS; i++)
29418 - atomic_set(&intf->stats[i], 0);
29419 + atomic_set_unchecked(&intf->stats[i], 0);
29420
29421 intf->proc_dir = NULL;
29422
29423 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29424 index 1e638ff..a869ef5 100644
29425 --- a/drivers/char/ipmi/ipmi_si_intf.c
29426 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29427 @@ -275,7 +275,7 @@ struct smi_info {
29428 unsigned char slave_addr;
29429
29430 /* Counters and things for the proc filesystem. */
29431 - atomic_t stats[SI_NUM_STATS];
29432 + atomic_unchecked_t stats[SI_NUM_STATS];
29433
29434 struct task_struct *thread;
29435
29436 @@ -284,9 +284,9 @@ struct smi_info {
29437 };
29438
29439 #define smi_inc_stat(smi, stat) \
29440 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29441 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29442 #define smi_get_stat(smi, stat) \
29443 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29444 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29445
29446 #define SI_MAX_PARMS 4
29447
29448 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29449 atomic_set(&new_smi->req_events, 0);
29450 new_smi->run_to_completion = 0;
29451 for (i = 0; i < SI_NUM_STATS; i++)
29452 - atomic_set(&new_smi->stats[i], 0);
29453 + atomic_set_unchecked(&new_smi->stats[i], 0);
29454
29455 new_smi->interrupt_disabled = 1;
29456 atomic_set(&new_smi->stop_operation, 0);
29457 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29458 index 47ff7e4..0c7d340 100644
29459 --- a/drivers/char/mbcs.c
29460 +++ b/drivers/char/mbcs.c
29461 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29462 return 0;
29463 }
29464
29465 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29466 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29467 {
29468 .part_num = MBCS_PART_NUM,
29469 .mfg_num = MBCS_MFG_NUM,
29470 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29471 index d6e9d08..4493e89 100644
29472 --- a/drivers/char/mem.c
29473 +++ b/drivers/char/mem.c
29474 @@ -18,6 +18,7 @@
29475 #include <linux/raw.h>
29476 #include <linux/tty.h>
29477 #include <linux/capability.h>
29478 +#include <linux/security.h>
29479 #include <linux/ptrace.h>
29480 #include <linux/device.h>
29481 #include <linux/highmem.h>
29482 @@ -35,6 +36,10 @@
29483 # include <linux/efi.h>
29484 #endif
29485
29486 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29487 +extern const struct file_operations grsec_fops;
29488 +#endif
29489 +
29490 static inline unsigned long size_inside_page(unsigned long start,
29491 unsigned long size)
29492 {
29493 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29494
29495 while (cursor < to) {
29496 if (!devmem_is_allowed(pfn)) {
29497 +#ifdef CONFIG_GRKERNSEC_KMEM
29498 + gr_handle_mem_readwrite(from, to);
29499 +#else
29500 printk(KERN_INFO
29501 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29502 current->comm, from, to);
29503 +#endif
29504 return 0;
29505 }
29506 cursor += PAGE_SIZE;
29507 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29508 }
29509 return 1;
29510 }
29511 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29512 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29513 +{
29514 + return 0;
29515 +}
29516 #else
29517 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29518 {
29519 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29520
29521 while (count > 0) {
29522 unsigned long remaining;
29523 + char *temp;
29524
29525 sz = size_inside_page(p, count);
29526
29527 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29528 if (!ptr)
29529 return -EFAULT;
29530
29531 - remaining = copy_to_user(buf, ptr, sz);
29532 +#ifdef CONFIG_PAX_USERCOPY
29533 + temp = kmalloc(sz, GFP_KERNEL);
29534 + if (!temp) {
29535 + unxlate_dev_mem_ptr(p, ptr);
29536 + return -ENOMEM;
29537 + }
29538 + memcpy(temp, ptr, sz);
29539 +#else
29540 + temp = ptr;
29541 +#endif
29542 +
29543 + remaining = copy_to_user(buf, temp, sz);
29544 +
29545 +#ifdef CONFIG_PAX_USERCOPY
29546 + kfree(temp);
29547 +#endif
29548 +
29549 unxlate_dev_mem_ptr(p, ptr);
29550 if (remaining)
29551 return -EFAULT;
29552 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29553 size_t count, loff_t *ppos)
29554 {
29555 unsigned long p = *ppos;
29556 - ssize_t low_count, read, sz;
29557 + ssize_t low_count, read, sz, err = 0;
29558 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29559 - int err = 0;
29560
29561 read = 0;
29562 if (p < (unsigned long) high_memory) {
29563 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29564 }
29565 #endif
29566 while (low_count > 0) {
29567 + char *temp;
29568 +
29569 sz = size_inside_page(p, low_count);
29570
29571 /*
29572 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29573 */
29574 kbuf = xlate_dev_kmem_ptr((char *)p);
29575
29576 - if (copy_to_user(buf, kbuf, sz))
29577 +#ifdef CONFIG_PAX_USERCOPY
29578 + temp = kmalloc(sz, GFP_KERNEL);
29579 + if (!temp)
29580 + return -ENOMEM;
29581 + memcpy(temp, kbuf, sz);
29582 +#else
29583 + temp = kbuf;
29584 +#endif
29585 +
29586 + err = copy_to_user(buf, temp, sz);
29587 +
29588 +#ifdef CONFIG_PAX_USERCOPY
29589 + kfree(temp);
29590 +#endif
29591 +
29592 + if (err)
29593 return -EFAULT;
29594 buf += sz;
29595 p += sz;
29596 @@ -867,6 +914,9 @@ static const struct memdev {
29597 #ifdef CONFIG_CRASH_DUMP
29598 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29599 #endif
29600 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29601 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29602 +#endif
29603 };
29604
29605 static int memory_open(struct inode *inode, struct file *filp)
29606 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29607 index 9df78e2..01ba9ae 100644
29608 --- a/drivers/char/nvram.c
29609 +++ b/drivers/char/nvram.c
29610 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29611
29612 spin_unlock_irq(&rtc_lock);
29613
29614 - if (copy_to_user(buf, contents, tmp - contents))
29615 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29616 return -EFAULT;
29617
29618 *ppos = i;
29619 diff --git a/drivers/char/random.c b/drivers/char/random.c
29620 index 4ec04a7..4a092ed 100644
29621 --- a/drivers/char/random.c
29622 +++ b/drivers/char/random.c
29623 @@ -261,8 +261,13 @@
29624 /*
29625 * Configuration information
29626 */
29627 +#ifdef CONFIG_GRKERNSEC_RANDNET
29628 +#define INPUT_POOL_WORDS 512
29629 +#define OUTPUT_POOL_WORDS 128
29630 +#else
29631 #define INPUT_POOL_WORDS 128
29632 #define OUTPUT_POOL_WORDS 32
29633 +#endif
29634 #define SEC_XFER_SIZE 512
29635 #define EXTRACT_SIZE 10
29636
29637 @@ -300,10 +305,17 @@ static struct poolinfo {
29638 int poolwords;
29639 int tap1, tap2, tap3, tap4, tap5;
29640 } poolinfo_table[] = {
29641 +#ifdef CONFIG_GRKERNSEC_RANDNET
29642 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29643 + { 512, 411, 308, 208, 104, 1 },
29644 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29645 + { 128, 103, 76, 51, 25, 1 },
29646 +#else
29647 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29648 { 128, 103, 76, 51, 25, 1 },
29649 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29650 { 32, 26, 20, 14, 7, 1 },
29651 +#endif
29652 #if 0
29653 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29654 { 2048, 1638, 1231, 819, 411, 1 },
29655 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29656
29657 extract_buf(r, tmp);
29658 i = min_t(int, nbytes, EXTRACT_SIZE);
29659 - if (copy_to_user(buf, tmp, i)) {
29660 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29661 ret = -EFAULT;
29662 break;
29663 }
29664 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29665 #include <linux/sysctl.h>
29666
29667 static int min_read_thresh = 8, min_write_thresh;
29668 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29669 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29670 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29671 static char sysctl_bootid[16];
29672
29673 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29674 index 45713f0..8286d21 100644
29675 --- a/drivers/char/sonypi.c
29676 +++ b/drivers/char/sonypi.c
29677 @@ -54,6 +54,7 @@
29678
29679 #include <asm/uaccess.h>
29680 #include <asm/io.h>
29681 +#include <asm/local.h>
29682
29683 #include <linux/sonypi.h>
29684
29685 @@ -490,7 +491,7 @@ static struct sonypi_device {
29686 spinlock_t fifo_lock;
29687 wait_queue_head_t fifo_proc_list;
29688 struct fasync_struct *fifo_async;
29689 - int open_count;
29690 + local_t open_count;
29691 int model;
29692 struct input_dev *input_jog_dev;
29693 struct input_dev *input_key_dev;
29694 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29695 static int sonypi_misc_release(struct inode *inode, struct file *file)
29696 {
29697 mutex_lock(&sonypi_device.lock);
29698 - sonypi_device.open_count--;
29699 + local_dec(&sonypi_device.open_count);
29700 mutex_unlock(&sonypi_device.lock);
29701 return 0;
29702 }
29703 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29704 {
29705 mutex_lock(&sonypi_device.lock);
29706 /* Flush input queue on first open */
29707 - if (!sonypi_device.open_count)
29708 + if (!local_read(&sonypi_device.open_count))
29709 kfifo_reset(&sonypi_device.fifo);
29710 - sonypi_device.open_count++;
29711 + local_inc(&sonypi_device.open_count);
29712 mutex_unlock(&sonypi_device.lock);
29713
29714 return 0;
29715 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29716 index ad7c732..5aa8054 100644
29717 --- a/drivers/char/tpm/tpm.c
29718 +++ b/drivers/char/tpm/tpm.c
29719 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29720 chip->vendor.req_complete_val)
29721 goto out_recv;
29722
29723 - if ((status == chip->vendor.req_canceled)) {
29724 + if (status == chip->vendor.req_canceled) {
29725 dev_err(chip->dev, "Operation Canceled\n");
29726 rc = -ECANCELED;
29727 goto out;
29728 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29729 index 0636520..169c1d0 100644
29730 --- a/drivers/char/tpm/tpm_bios.c
29731 +++ b/drivers/char/tpm/tpm_bios.c
29732 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29733 event = addr;
29734
29735 if ((event->event_type == 0 && event->event_size == 0) ||
29736 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29737 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29738 return NULL;
29739
29740 return addr;
29741 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29742 return NULL;
29743
29744 if ((event->event_type == 0 && event->event_size == 0) ||
29745 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29746 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29747 return NULL;
29748
29749 (*pos)++;
29750 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29751 int i;
29752
29753 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29754 - seq_putc(m, data[i]);
29755 + if (!seq_putc(m, data[i]))
29756 + return -EFAULT;
29757
29758 return 0;
29759 }
29760 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29761 log->bios_event_log_end = log->bios_event_log + len;
29762
29763 virt = acpi_os_map_memory(start, len);
29764 + if (!virt) {
29765 + kfree(log->bios_event_log);
29766 + log->bios_event_log = NULL;
29767 + return -EFAULT;
29768 + }
29769
29770 - memcpy(log->bios_event_log, virt, len);
29771 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29772
29773 acpi_os_unmap_memory(virt, len);
29774 return 0;
29775 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29776 index cdf2f54..e55c197 100644
29777 --- a/drivers/char/virtio_console.c
29778 +++ b/drivers/char/virtio_console.c
29779 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29780 if (to_user) {
29781 ssize_t ret;
29782
29783 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29784 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29785 if (ret)
29786 return -EFAULT;
29787 } else {
29788 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29789 if (!port_has_data(port) && !port->host_connected)
29790 return 0;
29791
29792 - return fill_readbuf(port, ubuf, count, true);
29793 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29794 }
29795
29796 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29797 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29798 index 97f5064..202b6e6 100644
29799 --- a/drivers/edac/edac_pci_sysfs.c
29800 +++ b/drivers/edac/edac_pci_sysfs.c
29801 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29802 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29803 static int edac_pci_poll_msec = 1000; /* one second workq period */
29804
29805 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29806 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29807 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29808 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29809
29810 static struct kobject *edac_pci_top_main_kobj;
29811 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29812 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29813 edac_printk(KERN_CRIT, EDAC_PCI,
29814 "Signaled System Error on %s\n",
29815 pci_name(dev));
29816 - atomic_inc(&pci_nonparity_count);
29817 + atomic_inc_unchecked(&pci_nonparity_count);
29818 }
29819
29820 if (status & (PCI_STATUS_PARITY)) {
29821 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29822 "Master Data Parity Error on %s\n",
29823 pci_name(dev));
29824
29825 - atomic_inc(&pci_parity_count);
29826 + atomic_inc_unchecked(&pci_parity_count);
29827 }
29828
29829 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29830 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29831 "Detected Parity Error on %s\n",
29832 pci_name(dev));
29833
29834 - atomic_inc(&pci_parity_count);
29835 + atomic_inc_unchecked(&pci_parity_count);
29836 }
29837 }
29838
29839 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29840 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29841 "Signaled System Error on %s\n",
29842 pci_name(dev));
29843 - atomic_inc(&pci_nonparity_count);
29844 + atomic_inc_unchecked(&pci_nonparity_count);
29845 }
29846
29847 if (status & (PCI_STATUS_PARITY)) {
29848 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29849 "Master Data Parity Error on "
29850 "%s\n", pci_name(dev));
29851
29852 - atomic_inc(&pci_parity_count);
29853 + atomic_inc_unchecked(&pci_parity_count);
29854 }
29855
29856 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29857 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29858 "Detected Parity Error on %s\n",
29859 pci_name(dev));
29860
29861 - atomic_inc(&pci_parity_count);
29862 + atomic_inc_unchecked(&pci_parity_count);
29863 }
29864 }
29865 }
29866 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29867 if (!check_pci_errors)
29868 return;
29869
29870 - before_count = atomic_read(&pci_parity_count);
29871 + before_count = atomic_read_unchecked(&pci_parity_count);
29872
29873 /* scan all PCI devices looking for a Parity Error on devices and
29874 * bridges.
29875 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29876 /* Only if operator has selected panic on PCI Error */
29877 if (edac_pci_get_panic_on_pe()) {
29878 /* If the count is different 'after' from 'before' */
29879 - if (before_count != atomic_read(&pci_parity_count))
29880 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29881 panic("EDAC: PCI Parity Error");
29882 }
29883 }
29884 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29885 index c6074c5..88a9e2e 100644
29886 --- a/drivers/edac/mce_amd.h
29887 +++ b/drivers/edac/mce_amd.h
29888 @@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
29889 struct amd_decoder_ops {
29890 bool (*dc_mce)(u16, u8);
29891 bool (*ic_mce)(u16, u8);
29892 -};
29893 +} __no_const;
29894
29895 void amd_report_gart_errors(bool);
29896 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29897 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29898 index cc595eb..4ec702a 100644
29899 --- a/drivers/firewire/core-card.c
29900 +++ b/drivers/firewire/core-card.c
29901 @@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
29902
29903 void fw_core_remove_card(struct fw_card *card)
29904 {
29905 - struct fw_card_driver dummy_driver = dummy_driver_template;
29906 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29907
29908 card->driver->update_phy_reg(card, 4,
29909 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29910 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29911 index 2e6b245..c3857d9 100644
29912 --- a/drivers/firewire/core-cdev.c
29913 +++ b/drivers/firewire/core-cdev.c
29914 @@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
29915 int ret;
29916
29917 if ((request->channels == 0 && request->bandwidth == 0) ||
29918 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29919 - request->bandwidth < 0)
29920 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29921 return -EINVAL;
29922
29923 r = kmalloc(sizeof(*r), GFP_KERNEL);
29924 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29925 index dea2dcc..a4fb978 100644
29926 --- a/drivers/firewire/core-transaction.c
29927 +++ b/drivers/firewire/core-transaction.c
29928 @@ -37,6 +37,7 @@
29929 #include <linux/timer.h>
29930 #include <linux/types.h>
29931 #include <linux/workqueue.h>
29932 +#include <linux/sched.h>
29933
29934 #include <asm/byteorder.h>
29935
29936 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29937 index 9047f55..e47c7ff 100644
29938 --- a/drivers/firewire/core.h
29939 +++ b/drivers/firewire/core.h
29940 @@ -110,6 +110,7 @@ struct fw_card_driver {
29941
29942 int (*stop_iso)(struct fw_iso_context *ctx);
29943 };
29944 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29945
29946 void fw_card_initialize(struct fw_card *card,
29947 const struct fw_card_driver *driver, struct device *device);
29948 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29949 index 153980b..4b4d046 100644
29950 --- a/drivers/firmware/dmi_scan.c
29951 +++ b/drivers/firmware/dmi_scan.c
29952 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29953 }
29954 }
29955 else {
29956 - /*
29957 - * no iounmap() for that ioremap(); it would be a no-op, but
29958 - * it's so early in setup that sucker gets confused into doing
29959 - * what it shouldn't if we actually call it.
29960 - */
29961 p = dmi_ioremap(0xF0000, 0x10000);
29962 if (p == NULL)
29963 goto error;
29964 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29965 if (buf == NULL)
29966 return -1;
29967
29968 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29969 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29970
29971 iounmap(buf);
29972 return 0;
29973 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29974 index 82d5c20..44a7177 100644
29975 --- a/drivers/gpio/gpio-vr41xx.c
29976 +++ b/drivers/gpio/gpio-vr41xx.c
29977 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29978 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29979 maskl, pendl, maskh, pendh);
29980
29981 - atomic_inc(&irq_err_count);
29982 + atomic_inc_unchecked(&irq_err_count);
29983
29984 return -EINVAL;
29985 }
29986 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29987 index 8111889..367b253 100644
29988 --- a/drivers/gpu/drm/drm_crtc_helper.c
29989 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29990 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29991 struct drm_crtc *tmp;
29992 int crtc_mask = 1;
29993
29994 - WARN(!crtc, "checking null crtc?\n");
29995 + BUG_ON(!crtc);
29996
29997 dev = crtc->dev;
29998
29999 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30000 index 6116e3b..c29dd16 100644
30001 --- a/drivers/gpu/drm/drm_drv.c
30002 +++ b/drivers/gpu/drm/drm_drv.c
30003 @@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30004 /**
30005 * Copy and IOCTL return string to user space
30006 */
30007 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30008 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30009 {
30010 int len;
30011
30012 @@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30013 return -ENODEV;
30014
30015 atomic_inc(&dev->ioctl_count);
30016 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30017 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30018 ++file_priv->ioctl_count;
30019
30020 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30021 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30022 index 123de28..43a0897 100644
30023 --- a/drivers/gpu/drm/drm_fops.c
30024 +++ b/drivers/gpu/drm/drm_fops.c
30025 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30026 }
30027
30028 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30029 - atomic_set(&dev->counts[i], 0);
30030 + atomic_set_unchecked(&dev->counts[i], 0);
30031
30032 dev->sigdata.lock = NULL;
30033
30034 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30035
30036 retcode = drm_open_helper(inode, filp, dev);
30037 if (!retcode) {
30038 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30039 - if (!dev->open_count++)
30040 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30041 + if (local_inc_return(&dev->open_count) == 1)
30042 retcode = drm_setup(dev);
30043 }
30044 if (!retcode) {
30045 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30046
30047 mutex_lock(&drm_global_mutex);
30048
30049 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30050 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30051
30052 if (dev->driver->preclose)
30053 dev->driver->preclose(dev, file_priv);
30054 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30055 * Begin inline drm_release
30056 */
30057
30058 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30059 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30060 task_pid_nr(current),
30061 (long)old_encode_dev(file_priv->minor->device),
30062 - dev->open_count);
30063 + local_read(&dev->open_count));
30064
30065 /* Release any auth tokens that might point to this file_priv,
30066 (do that under the drm_global_mutex) */
30067 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30068 * End inline drm_release
30069 */
30070
30071 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30072 - if (!--dev->open_count) {
30073 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30074 + if (local_dec_and_test(&dev->open_count)) {
30075 if (atomic_read(&dev->ioctl_count)) {
30076 DRM_ERROR("Device busy: %d\n",
30077 atomic_read(&dev->ioctl_count));
30078 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30079 index c87dc96..326055d 100644
30080 --- a/drivers/gpu/drm/drm_global.c
30081 +++ b/drivers/gpu/drm/drm_global.c
30082 @@ -36,7 +36,7 @@
30083 struct drm_global_item {
30084 struct mutex mutex;
30085 void *object;
30086 - int refcount;
30087 + atomic_t refcount;
30088 };
30089
30090 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30091 @@ -49,7 +49,7 @@ void drm_global_init(void)
30092 struct drm_global_item *item = &glob[i];
30093 mutex_init(&item->mutex);
30094 item->object = NULL;
30095 - item->refcount = 0;
30096 + atomic_set(&item->refcount, 0);
30097 }
30098 }
30099
30100 @@ -59,7 +59,7 @@ void drm_global_release(void)
30101 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30102 struct drm_global_item *item = &glob[i];
30103 BUG_ON(item->object != NULL);
30104 - BUG_ON(item->refcount != 0);
30105 + BUG_ON(atomic_read(&item->refcount) != 0);
30106 }
30107 }
30108
30109 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30110 void *object;
30111
30112 mutex_lock(&item->mutex);
30113 - if (item->refcount == 0) {
30114 + if (atomic_read(&item->refcount) == 0) {
30115 item->object = kzalloc(ref->size, GFP_KERNEL);
30116 if (unlikely(item->object == NULL)) {
30117 ret = -ENOMEM;
30118 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30119 goto out_err;
30120
30121 }
30122 - ++item->refcount;
30123 + atomic_inc(&item->refcount);
30124 ref->object = item->object;
30125 object = item->object;
30126 mutex_unlock(&item->mutex);
30127 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30128 struct drm_global_item *item = &glob[ref->global_type];
30129
30130 mutex_lock(&item->mutex);
30131 - BUG_ON(item->refcount == 0);
30132 + BUG_ON(atomic_read(&item->refcount) == 0);
30133 BUG_ON(ref->object != item->object);
30134 - if (--item->refcount == 0) {
30135 + if (atomic_dec_and_test(&item->refcount)) {
30136 ref->release(ref);
30137 item->object = NULL;
30138 }
30139 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30140 index ab1162d..42587b2 100644
30141 --- a/drivers/gpu/drm/drm_info.c
30142 +++ b/drivers/gpu/drm/drm_info.c
30143 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30144 struct drm_local_map *map;
30145 struct drm_map_list *r_list;
30146
30147 - /* Hardcoded from _DRM_FRAME_BUFFER,
30148 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30149 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30150 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30151 + static const char * const types[] = {
30152 + [_DRM_FRAME_BUFFER] = "FB",
30153 + [_DRM_REGISTERS] = "REG",
30154 + [_DRM_SHM] = "SHM",
30155 + [_DRM_AGP] = "AGP",
30156 + [_DRM_SCATTER_GATHER] = "SG",
30157 + [_DRM_CONSISTENT] = "PCI",
30158 + [_DRM_GEM] = "GEM" };
30159 const char *type;
30160 int i;
30161
30162 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30163 map = r_list->map;
30164 if (!map)
30165 continue;
30166 - if (map->type < 0 || map->type > 5)
30167 + if (map->type >= ARRAY_SIZE(types))
30168 type = "??";
30169 else
30170 type = types[map->type];
30171 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30172 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30173 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30174 vma->vm_flags & VM_IO ? 'i' : '-',
30175 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30176 + 0);
30177 +#else
30178 vma->vm_pgoff);
30179 +#endif
30180
30181 #if defined(__i386__)
30182 pgprot = pgprot_val(vma->vm_page_prot);
30183 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30184 index 637fcc3..e890b33 100644
30185 --- a/drivers/gpu/drm/drm_ioc32.c
30186 +++ b/drivers/gpu/drm/drm_ioc32.c
30187 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30188 request = compat_alloc_user_space(nbytes);
30189 if (!access_ok(VERIFY_WRITE, request, nbytes))
30190 return -EFAULT;
30191 - list = (struct drm_buf_desc *) (request + 1);
30192 + list = (struct drm_buf_desc __user *) (request + 1);
30193
30194 if (__put_user(count, &request->count)
30195 || __put_user(list, &request->list))
30196 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30197 request = compat_alloc_user_space(nbytes);
30198 if (!access_ok(VERIFY_WRITE, request, nbytes))
30199 return -EFAULT;
30200 - list = (struct drm_buf_pub *) (request + 1);
30201 + list = (struct drm_buf_pub __user *) (request + 1);
30202
30203 if (__put_user(count, &request->count)
30204 || __put_user(list, &request->list))
30205 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30206 index cf85155..f2665cb 100644
30207 --- a/drivers/gpu/drm/drm_ioctl.c
30208 +++ b/drivers/gpu/drm/drm_ioctl.c
30209 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30210 stats->data[i].value =
30211 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30212 else
30213 - stats->data[i].value = atomic_read(&dev->counts[i]);
30214 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30215 stats->data[i].type = dev->types[i];
30216 }
30217
30218 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30219 index c79c713..2048588 100644
30220 --- a/drivers/gpu/drm/drm_lock.c
30221 +++ b/drivers/gpu/drm/drm_lock.c
30222 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30223 if (drm_lock_take(&master->lock, lock->context)) {
30224 master->lock.file_priv = file_priv;
30225 master->lock.lock_time = jiffies;
30226 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30227 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30228 break; /* Got lock */
30229 }
30230
30231 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30232 return -EINVAL;
30233 }
30234
30235 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30236 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30237
30238 if (drm_lock_free(&master->lock, lock->context)) {
30239 /* FIXME: Should really bail out here. */
30240 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30241 index aa454f8..6d38580 100644
30242 --- a/drivers/gpu/drm/drm_stub.c
30243 +++ b/drivers/gpu/drm/drm_stub.c
30244 @@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30245
30246 drm_device_set_unplugged(dev);
30247
30248 - if (dev->open_count == 0) {
30249 + if (local_read(&dev->open_count) == 0) {
30250 drm_put_dev(dev);
30251 }
30252 mutex_unlock(&drm_global_mutex);
30253 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30254 index f920fb5..001c52d 100644
30255 --- a/drivers/gpu/drm/i810/i810_dma.c
30256 +++ b/drivers/gpu/drm/i810/i810_dma.c
30257 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30258 dma->buflist[vertex->idx],
30259 vertex->discard, vertex->used);
30260
30261 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30262 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30263 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30264 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30265 sarea_priv->last_enqueue = dev_priv->counter - 1;
30266 sarea_priv->last_dispatch = (int)hw_status[5];
30267
30268 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30269 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30270 mc->last_render);
30271
30272 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30273 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30274 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30275 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30276 sarea_priv->last_enqueue = dev_priv->counter - 1;
30277 sarea_priv->last_dispatch = (int)hw_status[5];
30278
30279 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30280 index c9339f4..f5e1b9d 100644
30281 --- a/drivers/gpu/drm/i810/i810_drv.h
30282 +++ b/drivers/gpu/drm/i810/i810_drv.h
30283 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30284 int page_flipping;
30285
30286 wait_queue_head_t irq_queue;
30287 - atomic_t irq_received;
30288 - atomic_t irq_emitted;
30289 + atomic_unchecked_t irq_received;
30290 + atomic_unchecked_t irq_emitted;
30291
30292 int front_offset;
30293 } drm_i810_private_t;
30294 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30295 index e6162a1..b2ff486 100644
30296 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30297 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30298 @@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30299 I915_READ(GTIMR));
30300 }
30301 seq_printf(m, "Interrupts received: %d\n",
30302 - atomic_read(&dev_priv->irq_received));
30303 + atomic_read_unchecked(&dev_priv->irq_received));
30304 for (i = 0; i < I915_NUM_RINGS; i++) {
30305 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30306 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30307 @@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30308 return ret;
30309
30310 if (opregion->header)
30311 - seq_write(m, opregion->header, OPREGION_SIZE);
30312 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30313
30314 mutex_unlock(&dev->struct_mutex);
30315
30316 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30317 index ba60f3c..e2dff7f 100644
30318 --- a/drivers/gpu/drm/i915/i915_dma.c
30319 +++ b/drivers/gpu/drm/i915/i915_dma.c
30320 @@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30321 bool can_switch;
30322
30323 spin_lock(&dev->count_lock);
30324 - can_switch = (dev->open_count == 0);
30325 + can_switch = (local_read(&dev->open_count) == 0);
30326 spin_unlock(&dev->count_lock);
30327 return can_switch;
30328 }
30329 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30330 index 5fabc6c..0b08aa1 100644
30331 --- a/drivers/gpu/drm/i915/i915_drv.h
30332 +++ b/drivers/gpu/drm/i915/i915_drv.h
30333 @@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30334 /* render clock increase/decrease */
30335 /* display clock increase/decrease */
30336 /* pll clock increase/decrease */
30337 -};
30338 +} __no_const;
30339
30340 struct intel_device_info {
30341 u8 gen;
30342 @@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30343 int current_page;
30344 int page_flipping;
30345
30346 - atomic_t irq_received;
30347 + atomic_unchecked_t irq_received;
30348
30349 /* protects the irq masks */
30350 spinlock_t irq_lock;
30351 @@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30352 * will be page flipped away on the next vblank. When it
30353 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30354 */
30355 - atomic_t pending_flip;
30356 + atomic_unchecked_t pending_flip;
30357 };
30358
30359 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30360 @@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30361 extern void intel_teardown_gmbus(struct drm_device *dev);
30362 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30363 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30364 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30365 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30366 {
30367 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30368 }
30369 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30370 index de43194..a14c4cc 100644
30371 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30372 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30373 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30374 i915_gem_clflush_object(obj);
30375
30376 if (obj->base.pending_write_domain)
30377 - cd->flips |= atomic_read(&obj->pending_flip);
30378 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30379
30380 /* The actual obj->write_domain will be updated with
30381 * pending_write_domain after we emit the accumulated flush for all
30382 @@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30383
30384 static int
30385 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30386 - int count)
30387 + unsigned int count)
30388 {
30389 - int i;
30390 + unsigned int i;
30391
30392 for (i = 0; i < count; i++) {
30393 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30394 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30395 index 26c67a7..8d4cbcb 100644
30396 --- a/drivers/gpu/drm/i915/i915_irq.c
30397 +++ b/drivers/gpu/drm/i915/i915_irq.c
30398 @@ -496,7 +496,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30399 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30400 struct drm_i915_master_private *master_priv;
30401
30402 - atomic_inc(&dev_priv->irq_received);
30403 + atomic_inc_unchecked(&dev_priv->irq_received);
30404
30405 /* disable master interrupt before clearing iir */
30406 de_ier = I915_READ(DEIER);
30407 @@ -579,7 +579,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30408 struct drm_i915_master_private *master_priv;
30409 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30410
30411 - atomic_inc(&dev_priv->irq_received);
30412 + atomic_inc_unchecked(&dev_priv->irq_received);
30413
30414 if (IS_GEN6(dev))
30415 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30416 @@ -1291,7 +1291,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30417 int ret = IRQ_NONE, pipe;
30418 bool blc_event = false;
30419
30420 - atomic_inc(&dev_priv->irq_received);
30421 + atomic_inc_unchecked(&dev_priv->irq_received);
30422
30423 iir = I915_READ(IIR);
30424
30425 @@ -1802,7 +1802,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30426 {
30427 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30428
30429 - atomic_set(&dev_priv->irq_received, 0);
30430 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30431
30432 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30433 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30434 @@ -1979,7 +1979,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30435 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30436 int pipe;
30437
30438 - atomic_set(&dev_priv->irq_received, 0);
30439 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30440
30441 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30442 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30443 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30444 index d4d162f..e80037c 100644
30445 --- a/drivers/gpu/drm/i915/intel_display.c
30446 +++ b/drivers/gpu/drm/i915/intel_display.c
30447 @@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30448
30449 wait_event(dev_priv->pending_flip_queue,
30450 atomic_read(&dev_priv->mm.wedged) ||
30451 - atomic_read(&obj->pending_flip) == 0);
30452 + atomic_read_unchecked(&obj->pending_flip) == 0);
30453
30454 /* Big Hammer, we also need to ensure that any pending
30455 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30456 @@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30457 obj = to_intel_framebuffer(crtc->fb)->obj;
30458 dev_priv = crtc->dev->dev_private;
30459 wait_event(dev_priv->pending_flip_queue,
30460 - atomic_read(&obj->pending_flip) == 0);
30461 + atomic_read_unchecked(&obj->pending_flip) == 0);
30462 }
30463
30464 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30465 @@ -7286,7 +7286,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30466
30467 atomic_clear_mask(1 << intel_crtc->plane,
30468 &obj->pending_flip.counter);
30469 - if (atomic_read(&obj->pending_flip) == 0)
30470 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30471 wake_up(&dev_priv->pending_flip_queue);
30472
30473 schedule_work(&work->work);
30474 @@ -7582,7 +7582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30475 /* Block clients from rendering to the new back buffer until
30476 * the flip occurs and the object is no longer visible.
30477 */
30478 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30479 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30480
30481 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30482 if (ret)
30483 @@ -7596,7 +7596,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30484 return 0;
30485
30486 cleanup_pending:
30487 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30488 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30489 drm_gem_object_unreference(&work->old_fb_obj->base);
30490 drm_gem_object_unreference(&obj->base);
30491 mutex_unlock(&dev->struct_mutex);
30492 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30493 index 54558a0..2d97005 100644
30494 --- a/drivers/gpu/drm/mga/mga_drv.h
30495 +++ b/drivers/gpu/drm/mga/mga_drv.h
30496 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30497 u32 clear_cmd;
30498 u32 maccess;
30499
30500 - atomic_t vbl_received; /**< Number of vblanks received. */
30501 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30502 wait_queue_head_t fence_queue;
30503 - atomic_t last_fence_retired;
30504 + atomic_unchecked_t last_fence_retired;
30505 u32 next_fence_to_post;
30506
30507 unsigned int fb_cpp;
30508 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30509 index 2581202..f230a8d9 100644
30510 --- a/drivers/gpu/drm/mga/mga_irq.c
30511 +++ b/drivers/gpu/drm/mga/mga_irq.c
30512 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30513 if (crtc != 0)
30514 return 0;
30515
30516 - return atomic_read(&dev_priv->vbl_received);
30517 + return atomic_read_unchecked(&dev_priv->vbl_received);
30518 }
30519
30520
30521 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30522 /* VBLANK interrupt */
30523 if (status & MGA_VLINEPEN) {
30524 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30525 - atomic_inc(&dev_priv->vbl_received);
30526 + atomic_inc_unchecked(&dev_priv->vbl_received);
30527 drm_handle_vblank(dev, 0);
30528 handled = 1;
30529 }
30530 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30531 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30532 MGA_WRITE(MGA_PRIMEND, prim_end);
30533
30534 - atomic_inc(&dev_priv->last_fence_retired);
30535 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30536 DRM_WAKEUP(&dev_priv->fence_queue);
30537 handled = 1;
30538 }
30539 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30540 * using fences.
30541 */
30542 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30543 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30544 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30545 - *sequence) <= (1 << 23)));
30546
30547 *sequence = cur_fence;
30548 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30549 index 0be4a81..7464804 100644
30550 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30551 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30552 @@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30553 struct bit_table {
30554 const char id;
30555 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30556 -};
30557 +} __no_const;
30558
30559 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30560
30561 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30562 index 3aef353..0ad1322 100644
30563 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30564 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30565 @@ -240,7 +240,7 @@ struct nouveau_channel {
30566 struct list_head pending;
30567 uint32_t sequence;
30568 uint32_t sequence_ack;
30569 - atomic_t last_sequence_irq;
30570 + atomic_unchecked_t last_sequence_irq;
30571 struct nouveau_vma vma;
30572 } fence;
30573
30574 @@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30575 u32 handle, u16 class);
30576 void (*set_tile_region)(struct drm_device *dev, int i);
30577 void (*tlb_flush)(struct drm_device *, int engine);
30578 -};
30579 +} __no_const;
30580
30581 struct nouveau_instmem_engine {
30582 void *priv;
30583 @@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30584 struct nouveau_mc_engine {
30585 int (*init)(struct drm_device *dev);
30586 void (*takedown)(struct drm_device *dev);
30587 -};
30588 +} __no_const;
30589
30590 struct nouveau_timer_engine {
30591 int (*init)(struct drm_device *dev);
30592 void (*takedown)(struct drm_device *dev);
30593 uint64_t (*read)(struct drm_device *dev);
30594 -};
30595 +} __no_const;
30596
30597 struct nouveau_fb_engine {
30598 int num_tiles;
30599 @@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30600 void (*put)(struct drm_device *, struct nouveau_mem **);
30601
30602 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30603 -};
30604 +} __no_const;
30605
30606 struct nouveau_engine {
30607 struct nouveau_instmem_engine instmem;
30608 @@ -739,7 +739,7 @@ struct drm_nouveau_private {
30609 struct drm_global_reference mem_global_ref;
30610 struct ttm_bo_global_ref bo_global_ref;
30611 struct ttm_bo_device bdev;
30612 - atomic_t validate_sequence;
30613 + atomic_unchecked_t validate_sequence;
30614 } ttm;
30615
30616 struct {
30617 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30618 index c1dc20f..4df673c 100644
30619 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30620 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30621 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30622 if (USE_REFCNT(dev))
30623 sequence = nvchan_rd32(chan, 0x48);
30624 else
30625 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30626 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30627
30628 if (chan->fence.sequence_ack == sequence)
30629 goto out;
30630 @@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30631 return ret;
30632 }
30633
30634 - atomic_set(&chan->fence.last_sequence_irq, 0);
30635 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30636 return 0;
30637 }
30638
30639 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30640 index ed52a6f..484acdc 100644
30641 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30642 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30643 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30644 int trycnt = 0;
30645 int ret, i;
30646
30647 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30648 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30649 retry:
30650 if (++trycnt > 100000) {
30651 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30652 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30653 index c2a8511..4b996f9 100644
30654 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30655 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30656 @@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30657 bool can_switch;
30658
30659 spin_lock(&dev->count_lock);
30660 - can_switch = (dev->open_count == 0);
30661 + can_switch = (local_read(&dev->open_count) == 0);
30662 spin_unlock(&dev->count_lock);
30663 return can_switch;
30664 }
30665 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30666 index dbdea8e..cd6eeeb 100644
30667 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30668 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30669 @@ -554,7 +554,7 @@ static int
30670 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30671 u32 class, u32 mthd, u32 data)
30672 {
30673 - atomic_set(&chan->fence.last_sequence_irq, data);
30674 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30675 return 0;
30676 }
30677
30678 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30679 index 2746402..c8dc4a4 100644
30680 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30681 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30682 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30683 }
30684
30685 if (nv_encoder->dcb->type == OUTPUT_DP) {
30686 - struct dp_train_func func = {
30687 + static struct dp_train_func func = {
30688 .link_set = nv50_sor_dp_link_set,
30689 .train_set = nv50_sor_dp_train_set,
30690 .train_adj = nv50_sor_dp_train_adj
30691 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30692 index 0247250..d2f6aaf 100644
30693 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30694 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30695 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30696 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30697
30698 if (nv_encoder->dcb->type == OUTPUT_DP) {
30699 - struct dp_train_func func = {
30700 + static struct dp_train_func func = {
30701 .link_set = nvd0_sor_dp_link_set,
30702 .train_set = nvd0_sor_dp_train_set,
30703 .train_adj = nvd0_sor_dp_train_adj
30704 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30705 index bcac90b..53bfc76 100644
30706 --- a/drivers/gpu/drm/r128/r128_cce.c
30707 +++ b/drivers/gpu/drm/r128/r128_cce.c
30708 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30709
30710 /* GH: Simple idle check.
30711 */
30712 - atomic_set(&dev_priv->idle_count, 0);
30713 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30714
30715 /* We don't support anything other than bus-mastering ring mode,
30716 * but the ring can be in either AGP or PCI space for the ring
30717 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30718 index 930c71b..499aded 100644
30719 --- a/drivers/gpu/drm/r128/r128_drv.h
30720 +++ b/drivers/gpu/drm/r128/r128_drv.h
30721 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30722 int is_pci;
30723 unsigned long cce_buffers_offset;
30724
30725 - atomic_t idle_count;
30726 + atomic_unchecked_t idle_count;
30727
30728 int page_flipping;
30729 int current_page;
30730 u32 crtc_offset;
30731 u32 crtc_offset_cntl;
30732
30733 - atomic_t vbl_received;
30734 + atomic_unchecked_t vbl_received;
30735
30736 u32 color_fmt;
30737 unsigned int front_offset;
30738 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30739 index 429d5a0..7e899ed 100644
30740 --- a/drivers/gpu/drm/r128/r128_irq.c
30741 +++ b/drivers/gpu/drm/r128/r128_irq.c
30742 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30743 if (crtc != 0)
30744 return 0;
30745
30746 - return atomic_read(&dev_priv->vbl_received);
30747 + return atomic_read_unchecked(&dev_priv->vbl_received);
30748 }
30749
30750 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30751 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30752 /* VBLANK interrupt */
30753 if (status & R128_CRTC_VBLANK_INT) {
30754 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30755 - atomic_inc(&dev_priv->vbl_received);
30756 + atomic_inc_unchecked(&dev_priv->vbl_received);
30757 drm_handle_vblank(dev, 0);
30758 return IRQ_HANDLED;
30759 }
30760 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30761 index a9e33ce..09edd4b 100644
30762 --- a/drivers/gpu/drm/r128/r128_state.c
30763 +++ b/drivers/gpu/drm/r128/r128_state.c
30764 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30765
30766 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30767 {
30768 - if (atomic_read(&dev_priv->idle_count) == 0)
30769 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30770 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30771 else
30772 - atomic_set(&dev_priv->idle_count, 0);
30773 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30774 }
30775
30776 #endif
30777 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30778 index 5a82b6b..9e69c73 100644
30779 --- a/drivers/gpu/drm/radeon/mkregtable.c
30780 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30781 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30782 regex_t mask_rex;
30783 regmatch_t match[4];
30784 char buf[1024];
30785 - size_t end;
30786 + long end;
30787 int len;
30788 int done = 0;
30789 int r;
30790 unsigned o;
30791 struct offset *offset;
30792 char last_reg_s[10];
30793 - int last_reg;
30794 + unsigned long last_reg;
30795
30796 if (regcomp
30797 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30798 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30799 index 138b952..d74f9cb 100644
30800 --- a/drivers/gpu/drm/radeon/radeon.h
30801 +++ b/drivers/gpu/drm/radeon/radeon.h
30802 @@ -253,7 +253,7 @@ struct radeon_fence_driver {
30803 uint32_t scratch_reg;
30804 uint64_t gpu_addr;
30805 volatile uint32_t *cpu_addr;
30806 - atomic_t seq;
30807 + atomic_unchecked_t seq;
30808 uint32_t last_seq;
30809 unsigned long last_jiffies;
30810 unsigned long last_timeout;
30811 @@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30812 int x2, int y2);
30813 void (*draw_auto)(struct radeon_device *rdev);
30814 void (*set_default_state)(struct radeon_device *rdev);
30815 -};
30816 +} __no_const;
30817
30818 struct r600_blit {
30819 struct mutex mutex;
30820 @@ -1246,7 +1246,7 @@ struct radeon_asic {
30821 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30822 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30823 } pflip;
30824 -};
30825 +} __no_const;
30826
30827 /*
30828 * Asic structures
30829 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30830 index 5992502..c19c633 100644
30831 --- a/drivers/gpu/drm/radeon/radeon_device.c
30832 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30833 @@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30834 bool can_switch;
30835
30836 spin_lock(&dev->count_lock);
30837 - can_switch = (dev->open_count == 0);
30838 + can_switch = (local_read(&dev->open_count) == 0);
30839 spin_unlock(&dev->count_lock);
30840 return can_switch;
30841 }
30842 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30843 index a1b59ca..86f2d44 100644
30844 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30845 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30846 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30847
30848 /* SW interrupt */
30849 wait_queue_head_t swi_queue;
30850 - atomic_t swi_emitted;
30851 + atomic_unchecked_t swi_emitted;
30852 int vblank_crtc;
30853 uint32_t irq_enable_reg;
30854 uint32_t r500_disp_irq_reg;
30855 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30856 index 4bd36a3..e66fe9c 100644
30857 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30858 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30859 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30860 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30861 return 0;
30862 }
30863 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30864 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30865 if (!rdev->ring[fence->ring].ready)
30866 /* FIXME: cp is not running assume everythings is done right
30867 * away
30868 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30869 }
30870 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30871 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30872 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30873 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30874 rdev->fence_drv[ring].initialized = true;
30875 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30876 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30877 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30878 rdev->fence_drv[ring].scratch_reg = -1;
30879 rdev->fence_drv[ring].cpu_addr = NULL;
30880 rdev->fence_drv[ring].gpu_addr = 0;
30881 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30882 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30883 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30884 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30885 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30886 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30887 index 48b7cea..342236f 100644
30888 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30889 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30890 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30891 request = compat_alloc_user_space(sizeof(*request));
30892 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30893 || __put_user(req32.param, &request->param)
30894 - || __put_user((void __user *)(unsigned long)req32.value,
30895 + || __put_user((unsigned long)req32.value,
30896 &request->value))
30897 return -EFAULT;
30898
30899 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30900 index 00da384..32f972d 100644
30901 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30902 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30903 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30904 unsigned int ret;
30905 RING_LOCALS;
30906
30907 - atomic_inc(&dev_priv->swi_emitted);
30908 - ret = atomic_read(&dev_priv->swi_emitted);
30909 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30910 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30911
30912 BEGIN_RING(4);
30913 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30914 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30915 drm_radeon_private_t *dev_priv =
30916 (drm_radeon_private_t *) dev->dev_private;
30917
30918 - atomic_set(&dev_priv->swi_emitted, 0);
30919 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30920 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30921
30922 dev->max_vblank_count = 0x001fffff;
30923 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30924 index e8422ae..d22d4a8 100644
30925 --- a/drivers/gpu/drm/radeon/radeon_state.c
30926 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30927 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30928 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30929 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30930
30931 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30932 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30933 sarea_priv->nbox * sizeof(depth_boxes[0])))
30934 return -EFAULT;
30935
30936 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30937 {
30938 drm_radeon_private_t *dev_priv = dev->dev_private;
30939 drm_radeon_getparam_t *param = data;
30940 - int value;
30941 + int value = 0;
30942
30943 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30944
30945 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30946 index f493c64..524ab6b 100644
30947 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30948 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30949 @@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30950 }
30951 if (unlikely(ttm_vm_ops == NULL)) {
30952 ttm_vm_ops = vma->vm_ops;
30953 - radeon_ttm_vm_ops = *ttm_vm_ops;
30954 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30955 + pax_open_kernel();
30956 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30957 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30958 + pax_close_kernel();
30959 }
30960 vma->vm_ops = &radeon_ttm_vm_ops;
30961 return 0;
30962 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30963 index f2c3b9d..d5a376b 100644
30964 --- a/drivers/gpu/drm/radeon/rs690.c
30965 +++ b/drivers/gpu/drm/radeon/rs690.c
30966 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30967 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30968 rdev->pm.sideport_bandwidth.full)
30969 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30970 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30971 + read_delay_latency.full = dfixed_const(800 * 1000);
30972 read_delay_latency.full = dfixed_div(read_delay_latency,
30973 rdev->pm.igp_sideport_mclk);
30974 + a.full = dfixed_const(370);
30975 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30976 } else {
30977 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30978 rdev->pm.k8_bandwidth.full)
30979 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30980 index ebc6fac..a8313ed 100644
30981 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30982 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30983 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30984 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30985 struct shrink_control *sc)
30986 {
30987 - static atomic_t start_pool = ATOMIC_INIT(0);
30988 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30989 unsigned i;
30990 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30991 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30992 struct ttm_page_pool *pool;
30993 int shrink_pages = sc->nr_to_scan;
30994
30995 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30996 index 88edacc..1e5412b 100644
30997 --- a/drivers/gpu/drm/via/via_drv.h
30998 +++ b/drivers/gpu/drm/via/via_drv.h
30999 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31000 typedef uint32_t maskarray_t[5];
31001
31002 typedef struct drm_via_irq {
31003 - atomic_t irq_received;
31004 + atomic_unchecked_t irq_received;
31005 uint32_t pending_mask;
31006 uint32_t enable_mask;
31007 wait_queue_head_t irq_queue;
31008 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31009 struct timeval last_vblank;
31010 int last_vblank_valid;
31011 unsigned usec_per_vblank;
31012 - atomic_t vbl_received;
31013 + atomic_unchecked_t vbl_received;
31014 drm_via_state_t hc_state;
31015 char pci_buf[VIA_PCI_BUF_SIZE];
31016 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31017 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31018 index d391f48..10c8ca3 100644
31019 --- a/drivers/gpu/drm/via/via_irq.c
31020 +++ b/drivers/gpu/drm/via/via_irq.c
31021 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31022 if (crtc != 0)
31023 return 0;
31024
31025 - return atomic_read(&dev_priv->vbl_received);
31026 + return atomic_read_unchecked(&dev_priv->vbl_received);
31027 }
31028
31029 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31030 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31031
31032 status = VIA_READ(VIA_REG_INTERRUPT);
31033 if (status & VIA_IRQ_VBLANK_PENDING) {
31034 - atomic_inc(&dev_priv->vbl_received);
31035 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31036 + atomic_inc_unchecked(&dev_priv->vbl_received);
31037 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31038 do_gettimeofday(&cur_vblank);
31039 if (dev_priv->last_vblank_valid) {
31040 dev_priv->usec_per_vblank =
31041 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31042 dev_priv->last_vblank = cur_vblank;
31043 dev_priv->last_vblank_valid = 1;
31044 }
31045 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31046 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31047 DRM_DEBUG("US per vblank is: %u\n",
31048 dev_priv->usec_per_vblank);
31049 }
31050 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31051
31052 for (i = 0; i < dev_priv->num_irqs; ++i) {
31053 if (status & cur_irq->pending_mask) {
31054 - atomic_inc(&cur_irq->irq_received);
31055 + atomic_inc_unchecked(&cur_irq->irq_received);
31056 DRM_WAKEUP(&cur_irq->irq_queue);
31057 handled = 1;
31058 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31059 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31060 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31061 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31062 masks[irq][4]));
31063 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31064 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31065 } else {
31066 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31067 (((cur_irq_sequence =
31068 - atomic_read(&cur_irq->irq_received)) -
31069 + atomic_read_unchecked(&cur_irq->irq_received)) -
31070 *sequence) <= (1 << 23)));
31071 }
31072 *sequence = cur_irq_sequence;
31073 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31074 }
31075
31076 for (i = 0; i < dev_priv->num_irqs; ++i) {
31077 - atomic_set(&cur_irq->irq_received, 0);
31078 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31079 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31080 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31081 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31082 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31083 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31084 case VIA_IRQ_RELATIVE:
31085 irqwait->request.sequence +=
31086 - atomic_read(&cur_irq->irq_received);
31087 + atomic_read_unchecked(&cur_irq->irq_received);
31088 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31089 case VIA_IRQ_ABSOLUTE:
31090 break;
31091 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31092 index d0f2c07..9ebd9c3 100644
31093 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31094 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31095 @@ -263,7 +263,7 @@ struct vmw_private {
31096 * Fencing and IRQs.
31097 */
31098
31099 - atomic_t marker_seq;
31100 + atomic_unchecked_t marker_seq;
31101 wait_queue_head_t fence_queue;
31102 wait_queue_head_t fifo_queue;
31103 int fence_queue_waiters; /* Protected by hw_mutex */
31104 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31105 index a0c2f12..68ae6cb 100644
31106 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31107 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31108 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31109 (unsigned int) min,
31110 (unsigned int) fifo->capabilities);
31111
31112 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31113 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31114 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31115 vmw_marker_queue_init(&fifo->marker_queue);
31116 return vmw_fifo_send_fence(dev_priv, &dummy);
31117 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31118 if (reserveable)
31119 iowrite32(bytes, fifo_mem +
31120 SVGA_FIFO_RESERVED);
31121 - return fifo_mem + (next_cmd >> 2);
31122 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31123 } else {
31124 need_bounce = true;
31125 }
31126 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31127
31128 fm = vmw_fifo_reserve(dev_priv, bytes);
31129 if (unlikely(fm == NULL)) {
31130 - *seqno = atomic_read(&dev_priv->marker_seq);
31131 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31132 ret = -ENOMEM;
31133 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31134 false, 3*HZ);
31135 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31136 }
31137
31138 do {
31139 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31140 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31141 } while (*seqno == 0);
31142
31143 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31144 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31145 index cabc95f..14b3d77 100644
31146 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31147 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31148 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31149 * emitted. Then the fence is stale and signaled.
31150 */
31151
31152 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31153 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31154 > VMW_FENCE_WRAP);
31155
31156 return ret;
31157 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31158
31159 if (fifo_idle)
31160 down_read(&fifo_state->rwsem);
31161 - signal_seq = atomic_read(&dev_priv->marker_seq);
31162 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31163 ret = 0;
31164
31165 for (;;) {
31166 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31167 index 8a8725c..afed796 100644
31168 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31169 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31170 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31171 while (!vmw_lag_lt(queue, us)) {
31172 spin_lock(&queue->lock);
31173 if (list_empty(&queue->head))
31174 - seqno = atomic_read(&dev_priv->marker_seq);
31175 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31176 else {
31177 marker = list_first_entry(&queue->head,
31178 struct vmw_marker, head);
31179 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31180 index 4da66b4..e948655 100644
31181 --- a/drivers/hid/hid-core.c
31182 +++ b/drivers/hid/hid-core.c
31183 @@ -2063,7 +2063,7 @@ static bool hid_ignore(struct hid_device *hdev)
31184
31185 int hid_add_device(struct hid_device *hdev)
31186 {
31187 - static atomic_t id = ATOMIC_INIT(0);
31188 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31189 int ret;
31190
31191 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31192 @@ -2078,7 +2078,7 @@ int hid_add_device(struct hid_device *hdev)
31193 /* XXX hack, any other cleaner solution after the driver core
31194 * is converted to allow more than 20 bytes as the device name? */
31195 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31196 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31197 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31198
31199 hid_debug_register(hdev, dev_name(&hdev->dev));
31200 ret = device_add(&hdev->dev);
31201 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31202 index eec3291..8ed706b 100644
31203 --- a/drivers/hid/hid-wiimote-debug.c
31204 +++ b/drivers/hid/hid-wiimote-debug.c
31205 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31206 else if (size == 0)
31207 return -EIO;
31208
31209 - if (copy_to_user(u, buf, size))
31210 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31211 return -EFAULT;
31212
31213 *off += size;
31214 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31215 index b1ec0e2..c295a61 100644
31216 --- a/drivers/hid/usbhid/hiddev.c
31217 +++ b/drivers/hid/usbhid/hiddev.c
31218 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31219 break;
31220
31221 case HIDIOCAPPLICATION:
31222 - if (arg < 0 || arg >= hid->maxapplication)
31223 + if (arg >= hid->maxapplication)
31224 break;
31225
31226 for (i = 0; i < hid->maxcollection; i++)
31227 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31228 index 4065374..10ed7dc 100644
31229 --- a/drivers/hv/channel.c
31230 +++ b/drivers/hv/channel.c
31231 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31232 int ret = 0;
31233 int t;
31234
31235 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31236 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31237 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31238 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31239
31240 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31241 if (ret)
31242 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31243 index 15956bd..ea34398 100644
31244 --- a/drivers/hv/hv.c
31245 +++ b/drivers/hv/hv.c
31246 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31247 u64 output_address = (output) ? virt_to_phys(output) : 0;
31248 u32 output_address_hi = output_address >> 32;
31249 u32 output_address_lo = output_address & 0xFFFFFFFF;
31250 - void *hypercall_page = hv_context.hypercall_page;
31251 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31252
31253 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31254 "=a"(hv_status_lo) : "d" (control_hi),
31255 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31256 index 699f0d8..f4f19250 100644
31257 --- a/drivers/hv/hyperv_vmbus.h
31258 +++ b/drivers/hv/hyperv_vmbus.h
31259 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31260 struct vmbus_connection {
31261 enum vmbus_connect_state conn_state;
31262
31263 - atomic_t next_gpadl_handle;
31264 + atomic_unchecked_t next_gpadl_handle;
31265
31266 /*
31267 * Represents channel interrupts. Each bit position represents a
31268 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31269 index a220e57..428f54d 100644
31270 --- a/drivers/hv/vmbus_drv.c
31271 +++ b/drivers/hv/vmbus_drv.c
31272 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31273 {
31274 int ret = 0;
31275
31276 - static atomic_t device_num = ATOMIC_INIT(0);
31277 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31278
31279 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31280 - atomic_inc_return(&device_num));
31281 + atomic_inc_return_unchecked(&device_num));
31282
31283 child_device_obj->device.bus = &hv_bus;
31284 child_device_obj->device.parent = &hv_acpi_dev->dev;
31285 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31286 index 9140236..ceaef4e 100644
31287 --- a/drivers/hwmon/acpi_power_meter.c
31288 +++ b/drivers/hwmon/acpi_power_meter.c
31289 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31290 return res;
31291
31292 temp /= 1000;
31293 - if (temp < 0)
31294 - return -EINVAL;
31295
31296 mutex_lock(&resource->lock);
31297 resource->trip[attr->index - 7] = temp;
31298 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31299 index 8b011d0..3de24a1 100644
31300 --- a/drivers/hwmon/sht15.c
31301 +++ b/drivers/hwmon/sht15.c
31302 @@ -166,7 +166,7 @@ struct sht15_data {
31303 int supply_uV;
31304 bool supply_uV_valid;
31305 struct work_struct update_supply_work;
31306 - atomic_t interrupt_handled;
31307 + atomic_unchecked_t interrupt_handled;
31308 };
31309
31310 /**
31311 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31312 return ret;
31313
31314 gpio_direction_input(data->pdata->gpio_data);
31315 - atomic_set(&data->interrupt_handled, 0);
31316 + atomic_set_unchecked(&data->interrupt_handled, 0);
31317
31318 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31319 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31320 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31321 /* Only relevant if the interrupt hasn't occurred. */
31322 - if (!atomic_read(&data->interrupt_handled))
31323 + if (!atomic_read_unchecked(&data->interrupt_handled))
31324 schedule_work(&data->read_work);
31325 }
31326 ret = wait_event_timeout(data->wait_queue,
31327 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31328
31329 /* First disable the interrupt */
31330 disable_irq_nosync(irq);
31331 - atomic_inc(&data->interrupt_handled);
31332 + atomic_inc_unchecked(&data->interrupt_handled);
31333 /* Then schedule a reading work struct */
31334 if (data->state != SHT15_READING_NOTHING)
31335 schedule_work(&data->read_work);
31336 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31337 * If not, then start the interrupt again - care here as could
31338 * have gone low in meantime so verify it hasn't!
31339 */
31340 - atomic_set(&data->interrupt_handled, 0);
31341 + atomic_set_unchecked(&data->interrupt_handled, 0);
31342 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31343 /* If still not occurred or another handler was scheduled */
31344 if (gpio_get_value(data->pdata->gpio_data)
31345 - || atomic_read(&data->interrupt_handled))
31346 + || atomic_read_unchecked(&data->interrupt_handled))
31347 return;
31348 }
31349
31350 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31351 index 378fcb5..5e91fa8 100644
31352 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31353 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31354 @@ -43,7 +43,7 @@
31355 extern struct i2c_adapter amd756_smbus;
31356
31357 static struct i2c_adapter *s4882_adapter;
31358 -static struct i2c_algorithm *s4882_algo;
31359 +static i2c_algorithm_no_const *s4882_algo;
31360
31361 /* Wrapper access functions for multiplexed SMBus */
31362 static DEFINE_MUTEX(amd756_lock);
31363 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31364 index 29015eb..af2d8e9 100644
31365 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31366 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31367 @@ -41,7 +41,7 @@
31368 extern struct i2c_adapter *nforce2_smbus;
31369
31370 static struct i2c_adapter *s4985_adapter;
31371 -static struct i2c_algorithm *s4985_algo;
31372 +static i2c_algorithm_no_const *s4985_algo;
31373
31374 /* Wrapper access functions for multiplexed SMBus */
31375 static DEFINE_MUTEX(nforce2_lock);
31376 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31377 index d7a4833..7fae376 100644
31378 --- a/drivers/i2c/i2c-mux.c
31379 +++ b/drivers/i2c/i2c-mux.c
31380 @@ -28,7 +28,7 @@
31381 /* multiplexer per channel data */
31382 struct i2c_mux_priv {
31383 struct i2c_adapter adap;
31384 - struct i2c_algorithm algo;
31385 + i2c_algorithm_no_const algo;
31386
31387 struct i2c_adapter *parent;
31388 void *mux_dev; /* the mux chip/device */
31389 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31390 index 57d00ca..0145194 100644
31391 --- a/drivers/ide/aec62xx.c
31392 +++ b/drivers/ide/aec62xx.c
31393 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31394 .cable_detect = atp86x_cable_detect,
31395 };
31396
31397 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31398 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31399 { /* 0: AEC6210 */
31400 .name = DRV_NAME,
31401 .init_chipset = init_chipset_aec62xx,
31402 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31403 index 2c8016a..911a27c 100644
31404 --- a/drivers/ide/alim15x3.c
31405 +++ b/drivers/ide/alim15x3.c
31406 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31407 .dma_sff_read_status = ide_dma_sff_read_status,
31408 };
31409
31410 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31411 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31412 .name = DRV_NAME,
31413 .init_chipset = init_chipset_ali15x3,
31414 .init_hwif = init_hwif_ali15x3,
31415 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31416 index 3747b25..56fc995 100644
31417 --- a/drivers/ide/amd74xx.c
31418 +++ b/drivers/ide/amd74xx.c
31419 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31420 .udma_mask = udma, \
31421 }
31422
31423 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31424 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31425 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31426 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31427 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31428 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31429 index 15f0ead..cb43480 100644
31430 --- a/drivers/ide/atiixp.c
31431 +++ b/drivers/ide/atiixp.c
31432 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31433 .cable_detect = atiixp_cable_detect,
31434 };
31435
31436 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31437 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31438 { /* 0: IXP200/300/400/700 */
31439 .name = DRV_NAME,
31440 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31441 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31442 index 5f80312..d1fc438 100644
31443 --- a/drivers/ide/cmd64x.c
31444 +++ b/drivers/ide/cmd64x.c
31445 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31446 .dma_sff_read_status = ide_dma_sff_read_status,
31447 };
31448
31449 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31450 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31451 { /* 0: CMD643 */
31452 .name = DRV_NAME,
31453 .init_chipset = init_chipset_cmd64x,
31454 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31455 index 2c1e5f7..1444762 100644
31456 --- a/drivers/ide/cs5520.c
31457 +++ b/drivers/ide/cs5520.c
31458 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31459 .set_dma_mode = cs5520_set_dma_mode,
31460 };
31461
31462 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31463 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31464 .name = DRV_NAME,
31465 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31466 .port_ops = &cs5520_port_ops,
31467 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31468 index 4dc4eb9..49b40ad 100644
31469 --- a/drivers/ide/cs5530.c
31470 +++ b/drivers/ide/cs5530.c
31471 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31472 .udma_filter = cs5530_udma_filter,
31473 };
31474
31475 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31476 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31477 .name = DRV_NAME,
31478 .init_chipset = init_chipset_cs5530,
31479 .init_hwif = init_hwif_cs5530,
31480 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31481 index 5059faf..18d4c85 100644
31482 --- a/drivers/ide/cs5535.c
31483 +++ b/drivers/ide/cs5535.c
31484 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31485 .cable_detect = cs5535_cable_detect,
31486 };
31487
31488 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31489 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31490 .name = DRV_NAME,
31491 .port_ops = &cs5535_port_ops,
31492 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31493 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31494 index 847553f..3ffb49d 100644
31495 --- a/drivers/ide/cy82c693.c
31496 +++ b/drivers/ide/cy82c693.c
31497 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31498 .set_dma_mode = cy82c693_set_dma_mode,
31499 };
31500
31501 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31502 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31503 .name = DRV_NAME,
31504 .init_iops = init_iops_cy82c693,
31505 .port_ops = &cy82c693_port_ops,
31506 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31507 index 58c51cd..4aec3b8 100644
31508 --- a/drivers/ide/hpt366.c
31509 +++ b/drivers/ide/hpt366.c
31510 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31511 }
31512 };
31513
31514 -static const struct hpt_info hpt36x __devinitdata = {
31515 +static const struct hpt_info hpt36x __devinitconst = {
31516 .chip_name = "HPT36x",
31517 .chip_type = HPT36x,
31518 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31519 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31520 .timings = &hpt36x_timings
31521 };
31522
31523 -static const struct hpt_info hpt370 __devinitdata = {
31524 +static const struct hpt_info hpt370 __devinitconst = {
31525 .chip_name = "HPT370",
31526 .chip_type = HPT370,
31527 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31528 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31529 .timings = &hpt37x_timings
31530 };
31531
31532 -static const struct hpt_info hpt370a __devinitdata = {
31533 +static const struct hpt_info hpt370a __devinitconst = {
31534 .chip_name = "HPT370A",
31535 .chip_type = HPT370A,
31536 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31537 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31538 .timings = &hpt37x_timings
31539 };
31540
31541 -static const struct hpt_info hpt374 __devinitdata = {
31542 +static const struct hpt_info hpt374 __devinitconst = {
31543 .chip_name = "HPT374",
31544 .chip_type = HPT374,
31545 .udma_mask = ATA_UDMA5,
31546 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31547 .timings = &hpt37x_timings
31548 };
31549
31550 -static const struct hpt_info hpt372 __devinitdata = {
31551 +static const struct hpt_info hpt372 __devinitconst = {
31552 .chip_name = "HPT372",
31553 .chip_type = HPT372,
31554 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31555 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31556 .timings = &hpt37x_timings
31557 };
31558
31559 -static const struct hpt_info hpt372a __devinitdata = {
31560 +static const struct hpt_info hpt372a __devinitconst = {
31561 .chip_name = "HPT372A",
31562 .chip_type = HPT372A,
31563 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31564 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31565 .timings = &hpt37x_timings
31566 };
31567
31568 -static const struct hpt_info hpt302 __devinitdata = {
31569 +static const struct hpt_info hpt302 __devinitconst = {
31570 .chip_name = "HPT302",
31571 .chip_type = HPT302,
31572 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31573 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31574 .timings = &hpt37x_timings
31575 };
31576
31577 -static const struct hpt_info hpt371 __devinitdata = {
31578 +static const struct hpt_info hpt371 __devinitconst = {
31579 .chip_name = "HPT371",
31580 .chip_type = HPT371,
31581 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31582 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31583 .timings = &hpt37x_timings
31584 };
31585
31586 -static const struct hpt_info hpt372n __devinitdata = {
31587 +static const struct hpt_info hpt372n __devinitconst = {
31588 .chip_name = "HPT372N",
31589 .chip_type = HPT372N,
31590 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31591 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31592 .timings = &hpt37x_timings
31593 };
31594
31595 -static const struct hpt_info hpt302n __devinitdata = {
31596 +static const struct hpt_info hpt302n __devinitconst = {
31597 .chip_name = "HPT302N",
31598 .chip_type = HPT302N,
31599 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31600 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31601 .timings = &hpt37x_timings
31602 };
31603
31604 -static const struct hpt_info hpt371n __devinitdata = {
31605 +static const struct hpt_info hpt371n __devinitconst = {
31606 .chip_name = "HPT371N",
31607 .chip_type = HPT371N,
31608 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31609 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31610 .dma_sff_read_status = ide_dma_sff_read_status,
31611 };
31612
31613 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31614 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31615 { /* 0: HPT36x */
31616 .name = DRV_NAME,
31617 .init_chipset = init_chipset_hpt366,
31618 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31619 index 8126824..55a2798 100644
31620 --- a/drivers/ide/ide-cd.c
31621 +++ b/drivers/ide/ide-cd.c
31622 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31623 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31624 if ((unsigned long)buf & alignment
31625 || blk_rq_bytes(rq) & q->dma_pad_mask
31626 - || object_is_on_stack(buf))
31627 + || object_starts_on_stack(buf))
31628 drive->dma = 0;
31629 }
31630 }
31631 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31632 index 7f56b73..dab5b67 100644
31633 --- a/drivers/ide/ide-pci-generic.c
31634 +++ b/drivers/ide/ide-pci-generic.c
31635 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31636 .udma_mask = ATA_UDMA6, \
31637 }
31638
31639 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31640 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31641 /* 0: Unknown */
31642 DECLARE_GENERIC_PCI_DEV(0),
31643
31644 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31645 index 560e66d..d5dd180 100644
31646 --- a/drivers/ide/it8172.c
31647 +++ b/drivers/ide/it8172.c
31648 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31649 .set_dma_mode = it8172_set_dma_mode,
31650 };
31651
31652 -static const struct ide_port_info it8172_port_info __devinitdata = {
31653 +static const struct ide_port_info it8172_port_info __devinitconst = {
31654 .name = DRV_NAME,
31655 .port_ops = &it8172_port_ops,
31656 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31657 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31658 index 46816ba..1847aeb 100644
31659 --- a/drivers/ide/it8213.c
31660 +++ b/drivers/ide/it8213.c
31661 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31662 .cable_detect = it8213_cable_detect,
31663 };
31664
31665 -static const struct ide_port_info it8213_chipset __devinitdata = {
31666 +static const struct ide_port_info it8213_chipset __devinitconst = {
31667 .name = DRV_NAME,
31668 .enablebits = { {0x41, 0x80, 0x80} },
31669 .port_ops = &it8213_port_ops,
31670 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31671 index 2e3169f..c5611db 100644
31672 --- a/drivers/ide/it821x.c
31673 +++ b/drivers/ide/it821x.c
31674 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31675 .cable_detect = it821x_cable_detect,
31676 };
31677
31678 -static const struct ide_port_info it821x_chipset __devinitdata = {
31679 +static const struct ide_port_info it821x_chipset __devinitconst = {
31680 .name = DRV_NAME,
31681 .init_chipset = init_chipset_it821x,
31682 .init_hwif = init_hwif_it821x,
31683 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31684 index 74c2c4a..efddd7d 100644
31685 --- a/drivers/ide/jmicron.c
31686 +++ b/drivers/ide/jmicron.c
31687 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31688 .cable_detect = jmicron_cable_detect,
31689 };
31690
31691 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31692 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31693 .name = DRV_NAME,
31694 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31695 .port_ops = &jmicron_port_ops,
31696 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31697 index 95327a2..73f78d8 100644
31698 --- a/drivers/ide/ns87415.c
31699 +++ b/drivers/ide/ns87415.c
31700 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31701 .dma_sff_read_status = superio_dma_sff_read_status,
31702 };
31703
31704 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31705 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31706 .name = DRV_NAME,
31707 .init_hwif = init_hwif_ns87415,
31708 .tp_ops = &ns87415_tp_ops,
31709 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31710 index 1a53a4c..39edc66 100644
31711 --- a/drivers/ide/opti621.c
31712 +++ b/drivers/ide/opti621.c
31713 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31714 .set_pio_mode = opti621_set_pio_mode,
31715 };
31716
31717 -static const struct ide_port_info opti621_chipset __devinitdata = {
31718 +static const struct ide_port_info opti621_chipset __devinitconst = {
31719 .name = DRV_NAME,
31720 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31721 .port_ops = &opti621_port_ops,
31722 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31723 index 9546fe2..2e5ceb6 100644
31724 --- a/drivers/ide/pdc202xx_new.c
31725 +++ b/drivers/ide/pdc202xx_new.c
31726 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31727 .udma_mask = udma, \
31728 }
31729
31730 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31731 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31732 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31733 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31734 };
31735 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31736 index 3a35ec6..5634510 100644
31737 --- a/drivers/ide/pdc202xx_old.c
31738 +++ b/drivers/ide/pdc202xx_old.c
31739 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31740 .max_sectors = sectors, \
31741 }
31742
31743 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31744 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31745 { /* 0: PDC20246 */
31746 .name = DRV_NAME,
31747 .init_chipset = init_chipset_pdc202xx,
31748 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31749 index 1892e81..fe0fd60 100644
31750 --- a/drivers/ide/piix.c
31751 +++ b/drivers/ide/piix.c
31752 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31753 .udma_mask = udma, \
31754 }
31755
31756 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31757 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31758 /* 0: MPIIX */
31759 { /*
31760 * MPIIX actually has only a single IDE channel mapped to
31761 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31762 index a6414a8..c04173e 100644
31763 --- a/drivers/ide/rz1000.c
31764 +++ b/drivers/ide/rz1000.c
31765 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31766 }
31767 }
31768
31769 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31770 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31771 .name = DRV_NAME,
31772 .host_flags = IDE_HFLAG_NO_DMA,
31773 };
31774 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31775 index 356b9b5..d4758eb 100644
31776 --- a/drivers/ide/sc1200.c
31777 +++ b/drivers/ide/sc1200.c
31778 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31779 .dma_sff_read_status = ide_dma_sff_read_status,
31780 };
31781
31782 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31783 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31784 .name = DRV_NAME,
31785 .port_ops = &sc1200_port_ops,
31786 .dma_ops = &sc1200_dma_ops,
31787 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31788 index b7f5b0c..9701038 100644
31789 --- a/drivers/ide/scc_pata.c
31790 +++ b/drivers/ide/scc_pata.c
31791 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31792 .dma_sff_read_status = scc_dma_sff_read_status,
31793 };
31794
31795 -static const struct ide_port_info scc_chipset __devinitdata = {
31796 +static const struct ide_port_info scc_chipset __devinitconst = {
31797 .name = "sccIDE",
31798 .init_iops = init_iops_scc,
31799 .init_dma = scc_init_dma,
31800 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31801 index 35fb8da..24d72ef 100644
31802 --- a/drivers/ide/serverworks.c
31803 +++ b/drivers/ide/serverworks.c
31804 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31805 .cable_detect = svwks_cable_detect,
31806 };
31807
31808 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31809 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31810 { /* 0: OSB4 */
31811 .name = DRV_NAME,
31812 .init_chipset = init_chipset_svwks,
31813 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31814 index ddeda44..46f7e30 100644
31815 --- a/drivers/ide/siimage.c
31816 +++ b/drivers/ide/siimage.c
31817 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31818 .udma_mask = ATA_UDMA6, \
31819 }
31820
31821 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31822 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31823 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31824 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31825 };
31826 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31827 index 4a00225..09e61b4 100644
31828 --- a/drivers/ide/sis5513.c
31829 +++ b/drivers/ide/sis5513.c
31830 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31831 .cable_detect = sis_cable_detect,
31832 };
31833
31834 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31835 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31836 .name = DRV_NAME,
31837 .init_chipset = init_chipset_sis5513,
31838 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31839 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31840 index f21dc2a..d051cd2 100644
31841 --- a/drivers/ide/sl82c105.c
31842 +++ b/drivers/ide/sl82c105.c
31843 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31844 .dma_sff_read_status = ide_dma_sff_read_status,
31845 };
31846
31847 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31848 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31849 .name = DRV_NAME,
31850 .init_chipset = init_chipset_sl82c105,
31851 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31852 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31853 index 864ffe0..863a5e9 100644
31854 --- a/drivers/ide/slc90e66.c
31855 +++ b/drivers/ide/slc90e66.c
31856 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31857 .cable_detect = slc90e66_cable_detect,
31858 };
31859
31860 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31861 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31862 .name = DRV_NAME,
31863 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31864 .port_ops = &slc90e66_port_ops,
31865 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31866 index 4799d5c..1794678 100644
31867 --- a/drivers/ide/tc86c001.c
31868 +++ b/drivers/ide/tc86c001.c
31869 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31870 .dma_sff_read_status = ide_dma_sff_read_status,
31871 };
31872
31873 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31874 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31875 .name = DRV_NAME,
31876 .init_hwif = init_hwif_tc86c001,
31877 .port_ops = &tc86c001_port_ops,
31878 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31879 index 281c914..55ce1b8 100644
31880 --- a/drivers/ide/triflex.c
31881 +++ b/drivers/ide/triflex.c
31882 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31883 .set_dma_mode = triflex_set_mode,
31884 };
31885
31886 -static const struct ide_port_info triflex_device __devinitdata = {
31887 +static const struct ide_port_info triflex_device __devinitconst = {
31888 .name = DRV_NAME,
31889 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31890 .port_ops = &triflex_port_ops,
31891 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31892 index 4b42ca0..e494a98 100644
31893 --- a/drivers/ide/trm290.c
31894 +++ b/drivers/ide/trm290.c
31895 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31896 .dma_check = trm290_dma_check,
31897 };
31898
31899 -static const struct ide_port_info trm290_chipset __devinitdata = {
31900 +static const struct ide_port_info trm290_chipset __devinitconst = {
31901 .name = DRV_NAME,
31902 .init_hwif = init_hwif_trm290,
31903 .tp_ops = &trm290_tp_ops,
31904 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31905 index f46f49c..eb77678 100644
31906 --- a/drivers/ide/via82cxxx.c
31907 +++ b/drivers/ide/via82cxxx.c
31908 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31909 .cable_detect = via82cxxx_cable_detect,
31910 };
31911
31912 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31913 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31914 .name = DRV_NAME,
31915 .init_chipset = init_chipset_via82cxxx,
31916 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31917 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31918 index 73d4531..c90cd2d 100644
31919 --- a/drivers/ieee802154/fakehard.c
31920 +++ b/drivers/ieee802154/fakehard.c
31921 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31922 phy->transmit_power = 0xbf;
31923
31924 dev->netdev_ops = &fake_ops;
31925 - dev->ml_priv = &fake_mlme;
31926 + dev->ml_priv = (void *)&fake_mlme;
31927
31928 priv = netdev_priv(dev);
31929 priv->phy = phy;
31930 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31931 index c889aae..6cf5aa7 100644
31932 --- a/drivers/infiniband/core/cm.c
31933 +++ b/drivers/infiniband/core/cm.c
31934 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31935
31936 struct cm_counter_group {
31937 struct kobject obj;
31938 - atomic_long_t counter[CM_ATTR_COUNT];
31939 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31940 };
31941
31942 struct cm_counter_attribute {
31943 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31944 struct ib_mad_send_buf *msg = NULL;
31945 int ret;
31946
31947 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31948 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31949 counter[CM_REQ_COUNTER]);
31950
31951 /* Quick state check to discard duplicate REQs. */
31952 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31953 if (!cm_id_priv)
31954 return;
31955
31956 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31957 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31958 counter[CM_REP_COUNTER]);
31959 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31960 if (ret)
31961 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31962 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31963 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31964 spin_unlock_irq(&cm_id_priv->lock);
31965 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31966 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31967 counter[CM_RTU_COUNTER]);
31968 goto out;
31969 }
31970 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31971 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31972 dreq_msg->local_comm_id);
31973 if (!cm_id_priv) {
31974 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31975 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31976 counter[CM_DREQ_COUNTER]);
31977 cm_issue_drep(work->port, work->mad_recv_wc);
31978 return -EINVAL;
31979 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31980 case IB_CM_MRA_REP_RCVD:
31981 break;
31982 case IB_CM_TIMEWAIT:
31983 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31984 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31985 counter[CM_DREQ_COUNTER]);
31986 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31987 goto unlock;
31988 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31989 cm_free_msg(msg);
31990 goto deref;
31991 case IB_CM_DREQ_RCVD:
31992 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31993 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31994 counter[CM_DREQ_COUNTER]);
31995 goto unlock;
31996 default:
31997 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31998 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31999 cm_id_priv->msg, timeout)) {
32000 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32001 - atomic_long_inc(&work->port->
32002 + atomic_long_inc_unchecked(&work->port->
32003 counter_group[CM_RECV_DUPLICATES].
32004 counter[CM_MRA_COUNTER]);
32005 goto out;
32006 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32007 break;
32008 case IB_CM_MRA_REQ_RCVD:
32009 case IB_CM_MRA_REP_RCVD:
32010 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32011 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32012 counter[CM_MRA_COUNTER]);
32013 /* fall through */
32014 default:
32015 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32016 case IB_CM_LAP_IDLE:
32017 break;
32018 case IB_CM_MRA_LAP_SENT:
32019 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32020 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32021 counter[CM_LAP_COUNTER]);
32022 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32023 goto unlock;
32024 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32025 cm_free_msg(msg);
32026 goto deref;
32027 case IB_CM_LAP_RCVD:
32028 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32029 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32030 counter[CM_LAP_COUNTER]);
32031 goto unlock;
32032 default:
32033 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32034 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32035 if (cur_cm_id_priv) {
32036 spin_unlock_irq(&cm.lock);
32037 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32038 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32039 counter[CM_SIDR_REQ_COUNTER]);
32040 goto out; /* Duplicate message. */
32041 }
32042 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32043 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32044 msg->retries = 1;
32045
32046 - atomic_long_add(1 + msg->retries,
32047 + atomic_long_add_unchecked(1 + msg->retries,
32048 &port->counter_group[CM_XMIT].counter[attr_index]);
32049 if (msg->retries)
32050 - atomic_long_add(msg->retries,
32051 + atomic_long_add_unchecked(msg->retries,
32052 &port->counter_group[CM_XMIT_RETRIES].
32053 counter[attr_index]);
32054
32055 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32056 }
32057
32058 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32059 - atomic_long_inc(&port->counter_group[CM_RECV].
32060 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32061 counter[attr_id - CM_ATTR_ID_OFFSET]);
32062
32063 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32064 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32065 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32066
32067 return sprintf(buf, "%ld\n",
32068 - atomic_long_read(&group->counter[cm_attr->index]));
32069 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32070 }
32071
32072 static const struct sysfs_ops cm_counter_ops = {
32073 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32074 index 176c8f9..2627b62 100644
32075 --- a/drivers/infiniband/core/fmr_pool.c
32076 +++ b/drivers/infiniband/core/fmr_pool.c
32077 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32078
32079 struct task_struct *thread;
32080
32081 - atomic_t req_ser;
32082 - atomic_t flush_ser;
32083 + atomic_unchecked_t req_ser;
32084 + atomic_unchecked_t flush_ser;
32085
32086 wait_queue_head_t force_wait;
32087 };
32088 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32089 struct ib_fmr_pool *pool = pool_ptr;
32090
32091 do {
32092 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32093 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32094 ib_fmr_batch_release(pool);
32095
32096 - atomic_inc(&pool->flush_ser);
32097 + atomic_inc_unchecked(&pool->flush_ser);
32098 wake_up_interruptible(&pool->force_wait);
32099
32100 if (pool->flush_function)
32101 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32102 }
32103
32104 set_current_state(TASK_INTERRUPTIBLE);
32105 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32106 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32107 !kthread_should_stop())
32108 schedule();
32109 __set_current_state(TASK_RUNNING);
32110 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32111 pool->dirty_watermark = params->dirty_watermark;
32112 pool->dirty_len = 0;
32113 spin_lock_init(&pool->pool_lock);
32114 - atomic_set(&pool->req_ser, 0);
32115 - atomic_set(&pool->flush_ser, 0);
32116 + atomic_set_unchecked(&pool->req_ser, 0);
32117 + atomic_set_unchecked(&pool->flush_ser, 0);
32118 init_waitqueue_head(&pool->force_wait);
32119
32120 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32121 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32122 }
32123 spin_unlock_irq(&pool->pool_lock);
32124
32125 - serial = atomic_inc_return(&pool->req_ser);
32126 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32127 wake_up_process(pool->thread);
32128
32129 if (wait_event_interruptible(pool->force_wait,
32130 - atomic_read(&pool->flush_ser) - serial >= 0))
32131 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32132 return -EINTR;
32133
32134 return 0;
32135 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32136 } else {
32137 list_add_tail(&fmr->list, &pool->dirty_list);
32138 if (++pool->dirty_len >= pool->dirty_watermark) {
32139 - atomic_inc(&pool->req_ser);
32140 + atomic_inc_unchecked(&pool->req_ser);
32141 wake_up_process(pool->thread);
32142 }
32143 }
32144 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32145 index 40c8353..946b0e4 100644
32146 --- a/drivers/infiniband/hw/cxgb4/mem.c
32147 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32148 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32149 int err;
32150 struct fw_ri_tpte tpt;
32151 u32 stag_idx;
32152 - static atomic_t key;
32153 + static atomic_unchecked_t key;
32154
32155 if (c4iw_fatal_error(rdev))
32156 return -EIO;
32157 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32158 &rdev->resource.tpt_fifo_lock);
32159 if (!stag_idx)
32160 return -ENOMEM;
32161 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32162 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32163 }
32164 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32165 __func__, stag_state, type, pdid, stag_idx);
32166 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32167 index 79b3dbc..96e5fcc 100644
32168 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32169 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32170 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32171 struct ib_atomic_eth *ateth;
32172 struct ipath_ack_entry *e;
32173 u64 vaddr;
32174 - atomic64_t *maddr;
32175 + atomic64_unchecked_t *maddr;
32176 u64 sdata;
32177 u32 rkey;
32178 u8 next;
32179 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32180 IB_ACCESS_REMOTE_ATOMIC)))
32181 goto nack_acc_unlck;
32182 /* Perform atomic OP and save result. */
32183 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32184 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32185 sdata = be64_to_cpu(ateth->swap_data);
32186 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32187 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32188 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32189 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32190 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32191 be64_to_cpu(ateth->compare_data),
32192 sdata);
32193 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32194 index 1f95bba..9530f87 100644
32195 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32196 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32197 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32198 unsigned long flags;
32199 struct ib_wc wc;
32200 u64 sdata;
32201 - atomic64_t *maddr;
32202 + atomic64_unchecked_t *maddr;
32203 enum ib_wc_status send_status;
32204
32205 /*
32206 @@ -382,11 +382,11 @@ again:
32207 IB_ACCESS_REMOTE_ATOMIC)))
32208 goto acc_err;
32209 /* Perform atomic OP and save result. */
32210 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32211 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32212 sdata = wqe->wr.wr.atomic.compare_add;
32213 *(u64 *) sqp->s_sge.sge.vaddr =
32214 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32215 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32216 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32217 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32218 sdata, wqe->wr.wr.atomic.swap);
32219 goto send_comp;
32220 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32221 index 7140199..da60063 100644
32222 --- a/drivers/infiniband/hw/nes/nes.c
32223 +++ b/drivers/infiniband/hw/nes/nes.c
32224 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32225 LIST_HEAD(nes_adapter_list);
32226 static LIST_HEAD(nes_dev_list);
32227
32228 -atomic_t qps_destroyed;
32229 +atomic_unchecked_t qps_destroyed;
32230
32231 static unsigned int ee_flsh_adapter;
32232 static unsigned int sysfs_nonidx_addr;
32233 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32234 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32235 struct nes_adapter *nesadapter = nesdev->nesadapter;
32236
32237 - atomic_inc(&qps_destroyed);
32238 + atomic_inc_unchecked(&qps_destroyed);
32239
32240 /* Free the control structures */
32241
32242 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32243 index c438e46..ca30356 100644
32244 --- a/drivers/infiniband/hw/nes/nes.h
32245 +++ b/drivers/infiniband/hw/nes/nes.h
32246 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32247 extern unsigned int wqm_quanta;
32248 extern struct list_head nes_adapter_list;
32249
32250 -extern atomic_t cm_connects;
32251 -extern atomic_t cm_accepts;
32252 -extern atomic_t cm_disconnects;
32253 -extern atomic_t cm_closes;
32254 -extern atomic_t cm_connecteds;
32255 -extern atomic_t cm_connect_reqs;
32256 -extern atomic_t cm_rejects;
32257 -extern atomic_t mod_qp_timouts;
32258 -extern atomic_t qps_created;
32259 -extern atomic_t qps_destroyed;
32260 -extern atomic_t sw_qps_destroyed;
32261 +extern atomic_unchecked_t cm_connects;
32262 +extern atomic_unchecked_t cm_accepts;
32263 +extern atomic_unchecked_t cm_disconnects;
32264 +extern atomic_unchecked_t cm_closes;
32265 +extern atomic_unchecked_t cm_connecteds;
32266 +extern atomic_unchecked_t cm_connect_reqs;
32267 +extern atomic_unchecked_t cm_rejects;
32268 +extern atomic_unchecked_t mod_qp_timouts;
32269 +extern atomic_unchecked_t qps_created;
32270 +extern atomic_unchecked_t qps_destroyed;
32271 +extern atomic_unchecked_t sw_qps_destroyed;
32272 extern u32 mh_detected;
32273 extern u32 mh_pauses_sent;
32274 extern u32 cm_packets_sent;
32275 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32276 extern u32 cm_packets_received;
32277 extern u32 cm_packets_dropped;
32278 extern u32 cm_packets_retrans;
32279 -extern atomic_t cm_listens_created;
32280 -extern atomic_t cm_listens_destroyed;
32281 +extern atomic_unchecked_t cm_listens_created;
32282 +extern atomic_unchecked_t cm_listens_destroyed;
32283 extern u32 cm_backlog_drops;
32284 -extern atomic_t cm_loopbacks;
32285 -extern atomic_t cm_nodes_created;
32286 -extern atomic_t cm_nodes_destroyed;
32287 -extern atomic_t cm_accel_dropped_pkts;
32288 -extern atomic_t cm_resets_recvd;
32289 -extern atomic_t pau_qps_created;
32290 -extern atomic_t pau_qps_destroyed;
32291 +extern atomic_unchecked_t cm_loopbacks;
32292 +extern atomic_unchecked_t cm_nodes_created;
32293 +extern atomic_unchecked_t cm_nodes_destroyed;
32294 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32295 +extern atomic_unchecked_t cm_resets_recvd;
32296 +extern atomic_unchecked_t pau_qps_created;
32297 +extern atomic_unchecked_t pau_qps_destroyed;
32298
32299 extern u32 int_mod_timer_init;
32300 extern u32 int_mod_cq_depth_256;
32301 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32302 index 71edfbb..15b62ae 100644
32303 --- a/drivers/infiniband/hw/nes/nes_cm.c
32304 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32305 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32306 u32 cm_packets_retrans;
32307 u32 cm_packets_created;
32308 u32 cm_packets_received;
32309 -atomic_t cm_listens_created;
32310 -atomic_t cm_listens_destroyed;
32311 +atomic_unchecked_t cm_listens_created;
32312 +atomic_unchecked_t cm_listens_destroyed;
32313 u32 cm_backlog_drops;
32314 -atomic_t cm_loopbacks;
32315 -atomic_t cm_nodes_created;
32316 -atomic_t cm_nodes_destroyed;
32317 -atomic_t cm_accel_dropped_pkts;
32318 -atomic_t cm_resets_recvd;
32319 +atomic_unchecked_t cm_loopbacks;
32320 +atomic_unchecked_t cm_nodes_created;
32321 +atomic_unchecked_t cm_nodes_destroyed;
32322 +atomic_unchecked_t cm_accel_dropped_pkts;
32323 +atomic_unchecked_t cm_resets_recvd;
32324
32325 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32326 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32327 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32328
32329 static struct nes_cm_core *g_cm_core;
32330
32331 -atomic_t cm_connects;
32332 -atomic_t cm_accepts;
32333 -atomic_t cm_disconnects;
32334 -atomic_t cm_closes;
32335 -atomic_t cm_connecteds;
32336 -atomic_t cm_connect_reqs;
32337 -atomic_t cm_rejects;
32338 +atomic_unchecked_t cm_connects;
32339 +atomic_unchecked_t cm_accepts;
32340 +atomic_unchecked_t cm_disconnects;
32341 +atomic_unchecked_t cm_closes;
32342 +atomic_unchecked_t cm_connecteds;
32343 +atomic_unchecked_t cm_connect_reqs;
32344 +atomic_unchecked_t cm_rejects;
32345
32346 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32347 {
32348 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32349 kfree(listener);
32350 listener = NULL;
32351 ret = 0;
32352 - atomic_inc(&cm_listens_destroyed);
32353 + atomic_inc_unchecked(&cm_listens_destroyed);
32354 } else {
32355 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32356 }
32357 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32358 cm_node->rem_mac);
32359
32360 add_hte_node(cm_core, cm_node);
32361 - atomic_inc(&cm_nodes_created);
32362 + atomic_inc_unchecked(&cm_nodes_created);
32363
32364 return cm_node;
32365 }
32366 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32367 }
32368
32369 atomic_dec(&cm_core->node_cnt);
32370 - atomic_inc(&cm_nodes_destroyed);
32371 + atomic_inc_unchecked(&cm_nodes_destroyed);
32372 nesqp = cm_node->nesqp;
32373 if (nesqp) {
32374 nesqp->cm_node = NULL;
32375 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32376
32377 static void drop_packet(struct sk_buff *skb)
32378 {
32379 - atomic_inc(&cm_accel_dropped_pkts);
32380 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32381 dev_kfree_skb_any(skb);
32382 }
32383
32384 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32385 {
32386
32387 int reset = 0; /* whether to send reset in case of err.. */
32388 - atomic_inc(&cm_resets_recvd);
32389 + atomic_inc_unchecked(&cm_resets_recvd);
32390 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32391 " refcnt=%d\n", cm_node, cm_node->state,
32392 atomic_read(&cm_node->ref_count));
32393 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32394 rem_ref_cm_node(cm_node->cm_core, cm_node);
32395 return NULL;
32396 }
32397 - atomic_inc(&cm_loopbacks);
32398 + atomic_inc_unchecked(&cm_loopbacks);
32399 loopbackremotenode->loopbackpartner = cm_node;
32400 loopbackremotenode->tcp_cntxt.rcv_wscale =
32401 NES_CM_DEFAULT_RCV_WND_SCALE;
32402 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32403 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32404 else {
32405 rem_ref_cm_node(cm_core, cm_node);
32406 - atomic_inc(&cm_accel_dropped_pkts);
32407 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32408 dev_kfree_skb_any(skb);
32409 }
32410 break;
32411 @@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32412
32413 if ((cm_id) && (cm_id->event_handler)) {
32414 if (issue_disconn) {
32415 - atomic_inc(&cm_disconnects);
32416 + atomic_inc_unchecked(&cm_disconnects);
32417 cm_event.event = IW_CM_EVENT_DISCONNECT;
32418 cm_event.status = disconn_status;
32419 cm_event.local_addr = cm_id->local_addr;
32420 @@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32421 }
32422
32423 if (issue_close) {
32424 - atomic_inc(&cm_closes);
32425 + atomic_inc_unchecked(&cm_closes);
32426 nes_disconnect(nesqp, 1);
32427
32428 cm_id->provider_data = nesqp;
32429 @@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32430
32431 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32432 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32433 - atomic_inc(&cm_accepts);
32434 + atomic_inc_unchecked(&cm_accepts);
32435
32436 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32437 netdev_refcnt_read(nesvnic->netdev));
32438 @@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32439 struct nes_cm_core *cm_core;
32440 u8 *start_buff;
32441
32442 - atomic_inc(&cm_rejects);
32443 + atomic_inc_unchecked(&cm_rejects);
32444 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32445 loopback = cm_node->loopbackpartner;
32446 cm_core = cm_node->cm_core;
32447 @@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32448 ntohl(cm_id->local_addr.sin_addr.s_addr),
32449 ntohs(cm_id->local_addr.sin_port));
32450
32451 - atomic_inc(&cm_connects);
32452 + atomic_inc_unchecked(&cm_connects);
32453 nesqp->active_conn = 1;
32454
32455 /* cache the cm_id in the qp */
32456 @@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32457 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32458 return err;
32459 }
32460 - atomic_inc(&cm_listens_created);
32461 + atomic_inc_unchecked(&cm_listens_created);
32462 }
32463
32464 cm_id->add_ref(cm_id);
32465 @@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32466
32467 if (nesqp->destroyed)
32468 return;
32469 - atomic_inc(&cm_connecteds);
32470 + atomic_inc_unchecked(&cm_connecteds);
32471 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32472 " local port 0x%04X. jiffies = %lu.\n",
32473 nesqp->hwqp.qp_id,
32474 @@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32475
32476 cm_id->add_ref(cm_id);
32477 ret = cm_id->event_handler(cm_id, &cm_event);
32478 - atomic_inc(&cm_closes);
32479 + atomic_inc_unchecked(&cm_closes);
32480 cm_event.event = IW_CM_EVENT_CLOSE;
32481 cm_event.status = 0;
32482 cm_event.provider_data = cm_id->provider_data;
32483 @@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32484 return;
32485 cm_id = cm_node->cm_id;
32486
32487 - atomic_inc(&cm_connect_reqs);
32488 + atomic_inc_unchecked(&cm_connect_reqs);
32489 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32490 cm_node, cm_id, jiffies);
32491
32492 @@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32493 return;
32494 cm_id = cm_node->cm_id;
32495
32496 - atomic_inc(&cm_connect_reqs);
32497 + atomic_inc_unchecked(&cm_connect_reqs);
32498 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32499 cm_node, cm_id, jiffies);
32500
32501 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32502 index 3ba7be3..c81f6ff 100644
32503 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32504 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32505 @@ -40,8 +40,8 @@
32506 #include "nes.h"
32507 #include "nes_mgt.h"
32508
32509 -atomic_t pau_qps_created;
32510 -atomic_t pau_qps_destroyed;
32511 +atomic_unchecked_t pau_qps_created;
32512 +atomic_unchecked_t pau_qps_destroyed;
32513
32514 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32515 {
32516 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32517 {
32518 struct sk_buff *skb;
32519 unsigned long flags;
32520 - atomic_inc(&pau_qps_destroyed);
32521 + atomic_inc_unchecked(&pau_qps_destroyed);
32522
32523 /* Free packets that have not yet been forwarded */
32524 /* Lock is acquired by skb_dequeue when removing the skb */
32525 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32526 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32527 skb_queue_head_init(&nesqp->pau_list);
32528 spin_lock_init(&nesqp->pau_lock);
32529 - atomic_inc(&pau_qps_created);
32530 + atomic_inc_unchecked(&pau_qps_created);
32531 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32532 }
32533
32534 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32535 index f3a3ecf..57d311d 100644
32536 --- a/drivers/infiniband/hw/nes/nes_nic.c
32537 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32538 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32539 target_stat_values[++index] = mh_detected;
32540 target_stat_values[++index] = mh_pauses_sent;
32541 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32542 - target_stat_values[++index] = atomic_read(&cm_connects);
32543 - target_stat_values[++index] = atomic_read(&cm_accepts);
32544 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32545 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32546 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32547 - target_stat_values[++index] = atomic_read(&cm_rejects);
32548 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32549 - target_stat_values[++index] = atomic_read(&qps_created);
32550 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32551 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32552 - target_stat_values[++index] = atomic_read(&cm_closes);
32553 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32554 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32555 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32556 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32557 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32558 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32559 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32560 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32561 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32562 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32563 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32564 target_stat_values[++index] = cm_packets_sent;
32565 target_stat_values[++index] = cm_packets_bounced;
32566 target_stat_values[++index] = cm_packets_created;
32567 target_stat_values[++index] = cm_packets_received;
32568 target_stat_values[++index] = cm_packets_dropped;
32569 target_stat_values[++index] = cm_packets_retrans;
32570 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32571 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32572 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32573 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32574 target_stat_values[++index] = cm_backlog_drops;
32575 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32576 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32577 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32578 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32579 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32580 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32581 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32582 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32583 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32584 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32585 target_stat_values[++index] = nesadapter->free_4kpbl;
32586 target_stat_values[++index] = nesadapter->free_256pbl;
32587 target_stat_values[++index] = int_mod_timer_init;
32588 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32589 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32590 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32591 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32592 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32593 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32594 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32595 }
32596
32597 /**
32598 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32599 index 8b8812d..a5e1133 100644
32600 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32601 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32602 @@ -46,9 +46,9 @@
32603
32604 #include <rdma/ib_umem.h>
32605
32606 -atomic_t mod_qp_timouts;
32607 -atomic_t qps_created;
32608 -atomic_t sw_qps_destroyed;
32609 +atomic_unchecked_t mod_qp_timouts;
32610 +atomic_unchecked_t qps_created;
32611 +atomic_unchecked_t sw_qps_destroyed;
32612
32613 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32614
32615 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32616 if (init_attr->create_flags)
32617 return ERR_PTR(-EINVAL);
32618
32619 - atomic_inc(&qps_created);
32620 + atomic_inc_unchecked(&qps_created);
32621 switch (init_attr->qp_type) {
32622 case IB_QPT_RC:
32623 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32624 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32625 struct iw_cm_event cm_event;
32626 int ret = 0;
32627
32628 - atomic_inc(&sw_qps_destroyed);
32629 + atomic_inc_unchecked(&sw_qps_destroyed);
32630 nesqp->destroyed = 1;
32631
32632 /* Blow away the connection if it exists. */
32633 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32634 index 6b811e3..f8acf88 100644
32635 --- a/drivers/infiniband/hw/qib/qib.h
32636 +++ b/drivers/infiniband/hw/qib/qib.h
32637 @@ -51,6 +51,7 @@
32638 #include <linux/completion.h>
32639 #include <linux/kref.h>
32640 #include <linux/sched.h>
32641 +#include <linux/slab.h>
32642
32643 #include "qib_common.h"
32644 #include "qib_verbs.h"
32645 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32646 index da739d9..da1c7f4 100644
32647 --- a/drivers/input/gameport/gameport.c
32648 +++ b/drivers/input/gameport/gameport.c
32649 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32650 */
32651 static void gameport_init_port(struct gameport *gameport)
32652 {
32653 - static atomic_t gameport_no = ATOMIC_INIT(0);
32654 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32655
32656 __module_get(THIS_MODULE);
32657
32658 mutex_init(&gameport->drv_mutex);
32659 device_initialize(&gameport->dev);
32660 dev_set_name(&gameport->dev, "gameport%lu",
32661 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32662 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32663 gameport->dev.bus = &gameport_bus;
32664 gameport->dev.release = gameport_release_port;
32665 if (gameport->parent)
32666 diff --git a/drivers/input/input.c b/drivers/input/input.c
32667 index 8921c61..f5cd63d 100644
32668 --- a/drivers/input/input.c
32669 +++ b/drivers/input/input.c
32670 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32671 */
32672 int input_register_device(struct input_dev *dev)
32673 {
32674 - static atomic_t input_no = ATOMIC_INIT(0);
32675 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32676 struct input_handler *handler;
32677 const char *path;
32678 int error;
32679 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32680 dev->setkeycode = input_default_setkeycode;
32681
32682 dev_set_name(&dev->dev, "input%ld",
32683 - (unsigned long) atomic_inc_return(&input_no) - 1);
32684 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32685
32686 error = device_add(&dev->dev);
32687 if (error)
32688 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32689 index b8d8611..7a4a04b 100644
32690 --- a/drivers/input/joystick/sidewinder.c
32691 +++ b/drivers/input/joystick/sidewinder.c
32692 @@ -30,6 +30,7 @@
32693 #include <linux/kernel.h>
32694 #include <linux/module.h>
32695 #include <linux/slab.h>
32696 +#include <linux/sched.h>
32697 #include <linux/init.h>
32698 #include <linux/input.h>
32699 #include <linux/gameport.h>
32700 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32701 index fd7a0d5..a4af10c 100644
32702 --- a/drivers/input/joystick/xpad.c
32703 +++ b/drivers/input/joystick/xpad.c
32704 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32705
32706 static int xpad_led_probe(struct usb_xpad *xpad)
32707 {
32708 - static atomic_t led_seq = ATOMIC_INIT(0);
32709 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32710 long led_no;
32711 struct xpad_led *led;
32712 struct led_classdev *led_cdev;
32713 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32714 if (!led)
32715 return -ENOMEM;
32716
32717 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32718 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32719
32720 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32721 led->xpad = xpad;
32722 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32723 index 0110b5a..d3ad144 100644
32724 --- a/drivers/input/mousedev.c
32725 +++ b/drivers/input/mousedev.c
32726 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32727
32728 spin_unlock_irq(&client->packet_lock);
32729
32730 - if (copy_to_user(buffer, data, count))
32731 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32732 return -EFAULT;
32733
32734 return count;
32735 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32736 index d0f7533..fb8215b 100644
32737 --- a/drivers/input/serio/serio.c
32738 +++ b/drivers/input/serio/serio.c
32739 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32740 */
32741 static void serio_init_port(struct serio *serio)
32742 {
32743 - static atomic_t serio_no = ATOMIC_INIT(0);
32744 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32745
32746 __module_get(THIS_MODULE);
32747
32748 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32749 mutex_init(&serio->drv_mutex);
32750 device_initialize(&serio->dev);
32751 dev_set_name(&serio->dev, "serio%ld",
32752 - (long)atomic_inc_return(&serio_no) - 1);
32753 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32754 serio->dev.bus = &serio_bus;
32755 serio->dev.release = serio_release_port;
32756 serio->dev.groups = serio_device_attr_groups;
32757 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32758 index b902794..fc7b85b 100644
32759 --- a/drivers/isdn/capi/capi.c
32760 +++ b/drivers/isdn/capi/capi.c
32761 @@ -83,8 +83,8 @@ struct capiminor {
32762
32763 struct capi20_appl *ap;
32764 u32 ncci;
32765 - atomic_t datahandle;
32766 - atomic_t msgid;
32767 + atomic_unchecked_t datahandle;
32768 + atomic_unchecked_t msgid;
32769
32770 struct tty_port port;
32771 int ttyinstop;
32772 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32773 capimsg_setu16(s, 2, mp->ap->applid);
32774 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32775 capimsg_setu8 (s, 5, CAPI_RESP);
32776 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32777 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32778 capimsg_setu32(s, 8, mp->ncci);
32779 capimsg_setu16(s, 12, datahandle);
32780 }
32781 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32782 mp->outbytes -= len;
32783 spin_unlock_bh(&mp->outlock);
32784
32785 - datahandle = atomic_inc_return(&mp->datahandle);
32786 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32787 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32788 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32789 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32790 capimsg_setu16(skb->data, 2, mp->ap->applid);
32791 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32792 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32793 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32794 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32795 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32796 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32797 capimsg_setu16(skb->data, 16, len); /* Data length */
32798 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32799 index 821f7ac..28d4030 100644
32800 --- a/drivers/isdn/hardware/avm/b1.c
32801 +++ b/drivers/isdn/hardware/avm/b1.c
32802 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32803 }
32804 if (left) {
32805 if (t4file->user) {
32806 - if (copy_from_user(buf, dp, left))
32807 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32808 return -EFAULT;
32809 } else {
32810 memcpy(buf, dp, left);
32811 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32812 }
32813 if (left) {
32814 if (config->user) {
32815 - if (copy_from_user(buf, dp, left))
32816 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32817 return -EFAULT;
32818 } else {
32819 memcpy(buf, dp, left);
32820 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32821 index dd6b53a..19d9ee6 100644
32822 --- a/drivers/isdn/hardware/eicon/divasync.h
32823 +++ b/drivers/isdn/hardware/eicon/divasync.h
32824 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32825 } diva_didd_add_adapter_t;
32826 typedef struct _diva_didd_remove_adapter {
32827 IDI_CALL p_request;
32828 -} diva_didd_remove_adapter_t;
32829 +} __no_const diva_didd_remove_adapter_t;
32830 typedef struct _diva_didd_read_adapter_array {
32831 void *buffer;
32832 dword length;
32833 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32834 index d303e65..28bcb7b 100644
32835 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32836 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32837 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32838 typedef struct _diva_os_idi_adapter_interface {
32839 diva_init_card_proc_t cleanup_adapter_proc;
32840 diva_cmd_card_proc_t cmd_proc;
32841 -} diva_os_idi_adapter_interface_t;
32842 +} __no_const diva_os_idi_adapter_interface_t;
32843
32844 typedef struct _diva_os_xdi_adapter {
32845 struct list_head link;
32846 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32847 index e74df7c..03a03ba 100644
32848 --- a/drivers/isdn/icn/icn.c
32849 +++ b/drivers/isdn/icn/icn.c
32850 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32851 if (count > len)
32852 count = len;
32853 if (user) {
32854 - if (copy_from_user(msg, buf, count))
32855 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32856 return -EFAULT;
32857 } else
32858 memcpy(msg, buf, count);
32859 diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32860 index 8bc4915..4cc6a2e 100644
32861 --- a/drivers/leds/leds-mc13783.c
32862 +++ b/drivers/leds/leds-mc13783.c
32863 @@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32864 return -EINVAL;
32865 }
32866
32867 - led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32868 + led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32869 if (led == NULL) {
32870 dev_err(&pdev->dev, "failed to alloc memory\n");
32871 return -ENOMEM;
32872 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32873 index b5fdcb7..5b6c59f 100644
32874 --- a/drivers/lguest/core.c
32875 +++ b/drivers/lguest/core.c
32876 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32877 * it's worked so far. The end address needs +1 because __get_vm_area
32878 * allocates an extra guard page, so we need space for that.
32879 */
32880 +
32881 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32882 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32883 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32884 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32885 +#else
32886 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32887 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32888 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32889 +#endif
32890 +
32891 if (!switcher_vma) {
32892 err = -ENOMEM;
32893 printk("lguest: could not map switcher pages high\n");
32894 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32895 * Now the Switcher is mapped at the right address, we can't fail!
32896 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32897 */
32898 - memcpy(switcher_vma->addr, start_switcher_text,
32899 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32900 end_switcher_text - start_switcher_text);
32901
32902 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32903 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32904 index 3980903..ce25c5e 100644
32905 --- a/drivers/lguest/x86/core.c
32906 +++ b/drivers/lguest/x86/core.c
32907 @@ -59,7 +59,7 @@ static struct {
32908 /* Offset from where switcher.S was compiled to where we've copied it */
32909 static unsigned long switcher_offset(void)
32910 {
32911 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32912 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32913 }
32914
32915 /* This cpu's struct lguest_pages. */
32916 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32917 * These copies are pretty cheap, so we do them unconditionally: */
32918 /* Save the current Host top-level page directory.
32919 */
32920 +
32921 +#ifdef CONFIG_PAX_PER_CPU_PGD
32922 + pages->state.host_cr3 = read_cr3();
32923 +#else
32924 pages->state.host_cr3 = __pa(current->mm->pgd);
32925 +#endif
32926 +
32927 /*
32928 * Set up the Guest's page tables to see this CPU's pages (and no
32929 * other CPU's pages).
32930 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32931 * compiled-in switcher code and the high-mapped copy we just made.
32932 */
32933 for (i = 0; i < IDT_ENTRIES; i++)
32934 - default_idt_entries[i] += switcher_offset();
32935 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32936
32937 /*
32938 * Set up the Switcher's per-cpu areas.
32939 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32940 * it will be undisturbed when we switch. To change %cs and jump we
32941 * need this structure to feed to Intel's "lcall" instruction.
32942 */
32943 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32944 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32945 lguest_entry.segment = LGUEST_CS;
32946
32947 /*
32948 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32949 index 40634b0..4f5855e 100644
32950 --- a/drivers/lguest/x86/switcher_32.S
32951 +++ b/drivers/lguest/x86/switcher_32.S
32952 @@ -87,6 +87,7 @@
32953 #include <asm/page.h>
32954 #include <asm/segment.h>
32955 #include <asm/lguest.h>
32956 +#include <asm/processor-flags.h>
32957
32958 // We mark the start of the code to copy
32959 // It's placed in .text tho it's never run here
32960 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32961 // Changes type when we load it: damn Intel!
32962 // For after we switch over our page tables
32963 // That entry will be read-only: we'd crash.
32964 +
32965 +#ifdef CONFIG_PAX_KERNEXEC
32966 + mov %cr0, %edx
32967 + xor $X86_CR0_WP, %edx
32968 + mov %edx, %cr0
32969 +#endif
32970 +
32971 movl $(GDT_ENTRY_TSS*8), %edx
32972 ltr %dx
32973
32974 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32975 // Let's clear it again for our return.
32976 // The GDT descriptor of the Host
32977 // Points to the table after two "size" bytes
32978 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32979 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32980 // Clear "used" from type field (byte 5, bit 2)
32981 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32982 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32983 +
32984 +#ifdef CONFIG_PAX_KERNEXEC
32985 + mov %cr0, %eax
32986 + xor $X86_CR0_WP, %eax
32987 + mov %eax, %cr0
32988 +#endif
32989
32990 // Once our page table's switched, the Guest is live!
32991 // The Host fades as we run this final step.
32992 @@ -295,13 +309,12 @@ deliver_to_host:
32993 // I consulted gcc, and it gave
32994 // These instructions, which I gladly credit:
32995 leal (%edx,%ebx,8), %eax
32996 - movzwl (%eax),%edx
32997 - movl 4(%eax), %eax
32998 - xorw %ax, %ax
32999 - orl %eax, %edx
33000 + movl 4(%eax), %edx
33001 + movw (%eax), %dx
33002 // Now the address of the handler's in %edx
33003 // We call it now: its "iret" drops us home.
33004 - jmp *%edx
33005 + ljmp $__KERNEL_CS, $1f
33006 +1: jmp *%edx
33007
33008 // Every interrupt can come to us here
33009 // But we must truly tell each apart.
33010 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33011 index 20e5c2c..9e849a9 100644
33012 --- a/drivers/macintosh/macio_asic.c
33013 +++ b/drivers/macintosh/macio_asic.c
33014 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33015 * MacIO is matched against any Apple ID, it's probe() function
33016 * will then decide wether it applies or not
33017 */
33018 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33019 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33020 .vendor = PCI_VENDOR_ID_APPLE,
33021 .device = PCI_ANY_ID,
33022 .subvendor = PCI_ANY_ID,
33023 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33024 index 17e2b47..bcbeec4 100644
33025 --- a/drivers/md/bitmap.c
33026 +++ b/drivers/md/bitmap.c
33027 @@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33028 chunk_kb ? "KB" : "B");
33029 if (bitmap->file) {
33030 seq_printf(seq, ", file: ");
33031 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33032 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33033 }
33034
33035 seq_printf(seq, "\n");
33036 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33037 index a1a3e6d..1918bfc 100644
33038 --- a/drivers/md/dm-ioctl.c
33039 +++ b/drivers/md/dm-ioctl.c
33040 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33041 cmd == DM_LIST_VERSIONS_CMD)
33042 return 0;
33043
33044 - if ((cmd == DM_DEV_CREATE_CMD)) {
33045 + if (cmd == DM_DEV_CREATE_CMD) {
33046 if (!*param->name) {
33047 DMWARN("name not supplied when creating device");
33048 return -EINVAL;
33049 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33050 index d039de8..0cf5b87 100644
33051 --- a/drivers/md/dm-raid1.c
33052 +++ b/drivers/md/dm-raid1.c
33053 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33054
33055 struct mirror {
33056 struct mirror_set *ms;
33057 - atomic_t error_count;
33058 + atomic_unchecked_t error_count;
33059 unsigned long error_type;
33060 struct dm_dev *dev;
33061 sector_t offset;
33062 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33063 struct mirror *m;
33064
33065 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33066 - if (!atomic_read(&m->error_count))
33067 + if (!atomic_read_unchecked(&m->error_count))
33068 return m;
33069
33070 return NULL;
33071 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33072 * simple way to tell if a device has encountered
33073 * errors.
33074 */
33075 - atomic_inc(&m->error_count);
33076 + atomic_inc_unchecked(&m->error_count);
33077
33078 if (test_and_set_bit(error_type, &m->error_type))
33079 return;
33080 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33081 struct mirror *m = get_default_mirror(ms);
33082
33083 do {
33084 - if (likely(!atomic_read(&m->error_count)))
33085 + if (likely(!atomic_read_unchecked(&m->error_count)))
33086 return m;
33087
33088 if (m-- == ms->mirror)
33089 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33090 {
33091 struct mirror *default_mirror = get_default_mirror(m->ms);
33092
33093 - return !atomic_read(&default_mirror->error_count);
33094 + return !atomic_read_unchecked(&default_mirror->error_count);
33095 }
33096
33097 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33098 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33099 */
33100 if (likely(region_in_sync(ms, region, 1)))
33101 m = choose_mirror(ms, bio->bi_sector);
33102 - else if (m && atomic_read(&m->error_count))
33103 + else if (m && atomic_read_unchecked(&m->error_count))
33104 m = NULL;
33105
33106 if (likely(m))
33107 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33108 }
33109
33110 ms->mirror[mirror].ms = ms;
33111 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33112 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33113 ms->mirror[mirror].error_type = 0;
33114 ms->mirror[mirror].offset = offset;
33115
33116 @@ -1351,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33117 */
33118 static char device_status_char(struct mirror *m)
33119 {
33120 - if (!atomic_read(&(m->error_count)))
33121 + if (!atomic_read_unchecked(&(m->error_count)))
33122 return 'A';
33123
33124 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33125 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33126 index 35c94ff..20d4c17 100644
33127 --- a/drivers/md/dm-stripe.c
33128 +++ b/drivers/md/dm-stripe.c
33129 @@ -20,7 +20,7 @@ struct stripe {
33130 struct dm_dev *dev;
33131 sector_t physical_start;
33132
33133 - atomic_t error_count;
33134 + atomic_unchecked_t error_count;
33135 };
33136
33137 struct stripe_c {
33138 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33139 kfree(sc);
33140 return r;
33141 }
33142 - atomic_set(&(sc->stripe[i].error_count), 0);
33143 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33144 }
33145
33146 ti->private = sc;
33147 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33148 DMEMIT("%d ", sc->stripes);
33149 for (i = 0; i < sc->stripes; i++) {
33150 DMEMIT("%s ", sc->stripe[i].dev->name);
33151 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33152 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33153 'D' : 'A';
33154 }
33155 buffer[i] = '\0';
33156 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33157 */
33158 for (i = 0; i < sc->stripes; i++)
33159 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33160 - atomic_inc(&(sc->stripe[i].error_count));
33161 - if (atomic_read(&(sc->stripe[i].error_count)) <
33162 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33163 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33164 DM_IO_ERROR_THRESHOLD)
33165 schedule_work(&sc->trigger_event);
33166 }
33167 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33168 index 2e227fb..44ead1f 100644
33169 --- a/drivers/md/dm-table.c
33170 +++ b/drivers/md/dm-table.c
33171 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
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 --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33181 index 737d388..811ad5a 100644
33182 --- a/drivers/md/dm-thin-metadata.c
33183 +++ b/drivers/md/dm-thin-metadata.c
33184 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33185
33186 pmd->info.tm = tm;
33187 pmd->info.levels = 2;
33188 - pmd->info.value_type.context = pmd->data_sm;
33189 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33190 pmd->info.value_type.size = sizeof(__le64);
33191 pmd->info.value_type.inc = data_block_inc;
33192 pmd->info.value_type.dec = data_block_dec;
33193 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33194
33195 pmd->bl_info.tm = tm;
33196 pmd->bl_info.levels = 1;
33197 - pmd->bl_info.value_type.context = pmd->data_sm;
33198 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33199 pmd->bl_info.value_type.size = sizeof(__le64);
33200 pmd->bl_info.value_type.inc = data_block_inc;
33201 pmd->bl_info.value_type.dec = data_block_dec;
33202 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33203 index e24143c..ce2f21a1 100644
33204 --- a/drivers/md/dm.c
33205 +++ b/drivers/md/dm.c
33206 @@ -176,9 +176,9 @@ struct mapped_device {
33207 /*
33208 * Event handling.
33209 */
33210 - atomic_t event_nr;
33211 + atomic_unchecked_t event_nr;
33212 wait_queue_head_t eventq;
33213 - atomic_t uevent_seq;
33214 + atomic_unchecked_t uevent_seq;
33215 struct list_head uevent_list;
33216 spinlock_t uevent_lock; /* Protect access to uevent_list */
33217
33218 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33219 rwlock_init(&md->map_lock);
33220 atomic_set(&md->holders, 1);
33221 atomic_set(&md->open_count, 0);
33222 - atomic_set(&md->event_nr, 0);
33223 - atomic_set(&md->uevent_seq, 0);
33224 + atomic_set_unchecked(&md->event_nr, 0);
33225 + atomic_set_unchecked(&md->uevent_seq, 0);
33226 INIT_LIST_HEAD(&md->uevent_list);
33227 spin_lock_init(&md->uevent_lock);
33228
33229 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33230
33231 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33232
33233 - atomic_inc(&md->event_nr);
33234 + atomic_inc_unchecked(&md->event_nr);
33235 wake_up(&md->eventq);
33236 }
33237
33238 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33239
33240 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33241 {
33242 - return atomic_add_return(1, &md->uevent_seq);
33243 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33244 }
33245
33246 uint32_t dm_get_event_nr(struct mapped_device *md)
33247 {
33248 - return atomic_read(&md->event_nr);
33249 + return atomic_read_unchecked(&md->event_nr);
33250 }
33251
33252 int dm_wait_event(struct mapped_device *md, int event_nr)
33253 {
33254 return wait_event_interruptible(md->eventq,
33255 - (event_nr != atomic_read(&md->event_nr)));
33256 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33257 }
33258
33259 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33260 diff --git a/drivers/md/md.c b/drivers/md/md.c
33261 index 2b30ffd..bf789ce 100644
33262 --- a/drivers/md/md.c
33263 +++ b/drivers/md/md.c
33264 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33265 * start build, activate spare
33266 */
33267 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33268 -static atomic_t md_event_count;
33269 +static atomic_unchecked_t md_event_count;
33270 void md_new_event(struct mddev *mddev)
33271 {
33272 - atomic_inc(&md_event_count);
33273 + atomic_inc_unchecked(&md_event_count);
33274 wake_up(&md_event_waiters);
33275 }
33276 EXPORT_SYMBOL_GPL(md_new_event);
33277 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33278 */
33279 static void md_new_event_inintr(struct mddev *mddev)
33280 {
33281 - atomic_inc(&md_event_count);
33282 + atomic_inc_unchecked(&md_event_count);
33283 wake_up(&md_event_waiters);
33284 }
33285
33286 @@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33287
33288 rdev->preferred_minor = 0xffff;
33289 rdev->data_offset = le64_to_cpu(sb->data_offset);
33290 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33291 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33292
33293 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33294 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33295 @@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33296 else
33297 sb->resync_offset = cpu_to_le64(0);
33298
33299 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33300 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33301
33302 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33303 sb->size = cpu_to_le64(mddev->dev_sectors);
33304 @@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33305 static ssize_t
33306 errors_show(struct md_rdev *rdev, char *page)
33307 {
33308 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33309 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33310 }
33311
33312 static ssize_t
33313 @@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33314 char *e;
33315 unsigned long n = simple_strtoul(buf, &e, 10);
33316 if (*buf && (*e == 0 || *e == '\n')) {
33317 - atomic_set(&rdev->corrected_errors, n);
33318 + atomic_set_unchecked(&rdev->corrected_errors, n);
33319 return len;
33320 }
33321 return -EINVAL;
33322 @@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33323 rdev->sb_loaded = 0;
33324 rdev->bb_page = NULL;
33325 atomic_set(&rdev->nr_pending, 0);
33326 - atomic_set(&rdev->read_errors, 0);
33327 - atomic_set(&rdev->corrected_errors, 0);
33328 + atomic_set_unchecked(&rdev->read_errors, 0);
33329 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33330
33331 INIT_LIST_HEAD(&rdev->same_set);
33332 init_waitqueue_head(&rdev->blocked_wait);
33333 @@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33334
33335 spin_unlock(&pers_lock);
33336 seq_printf(seq, "\n");
33337 - seq->poll_event = atomic_read(&md_event_count);
33338 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33339 return 0;
33340 }
33341 if (v == (void*)2) {
33342 @@ -6841,7 +6841,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33343 return error;
33344
33345 seq = file->private_data;
33346 - seq->poll_event = atomic_read(&md_event_count);
33347 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33348 return error;
33349 }
33350
33351 @@ -6855,7 +6855,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33352 /* always allow read */
33353 mask = POLLIN | POLLRDNORM;
33354
33355 - if (seq->poll_event != atomic_read(&md_event_count))
33356 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33357 mask |= POLLERR | POLLPRI;
33358 return mask;
33359 }
33360 @@ -6899,7 +6899,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33361 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33362 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33363 (int)part_stat_read(&disk->part0, sectors[1]) -
33364 - atomic_read(&disk->sync_io);
33365 + atomic_read_unchecked(&disk->sync_io);
33366 /* sync IO will cause sync_io to increase before the disk_stats
33367 * as sync_io is counted when a request starts, and
33368 * disk_stats is counted when it completes.
33369 diff --git a/drivers/md/md.h b/drivers/md/md.h
33370 index 1c2063c..9639970 100644
33371 --- a/drivers/md/md.h
33372 +++ b/drivers/md/md.h
33373 @@ -93,13 +93,13 @@ struct md_rdev {
33374 * only maintained for arrays that
33375 * support hot removal
33376 */
33377 - atomic_t read_errors; /* number of consecutive read errors that
33378 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33379 * we have tried to ignore.
33380 */
33381 struct timespec last_read_error; /* monotonic time since our
33382 * last read error
33383 */
33384 - atomic_t corrected_errors; /* number of corrected read errors,
33385 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33386 * for reporting to userspace and storing
33387 * in superblock.
33388 */
33389 @@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33390
33391 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33392 {
33393 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33394 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33395 }
33396
33397 struct md_personality
33398 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33399 index fc90c11..c8cd9a9 100644
33400 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33401 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33402 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33403 /*----------------------------------------------------------------*/
33404
33405 struct sm_checker {
33406 - struct dm_space_map sm;
33407 + dm_space_map_no_const sm;
33408
33409 struct count_array old_counts;
33410 struct count_array counts;
33411 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33412 index 3d0ed53..35dc592 100644
33413 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33414 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33415 @@ -23,7 +23,7 @@
33416 * Space map interface.
33417 */
33418 struct sm_disk {
33419 - struct dm_space_map sm;
33420 + dm_space_map_no_const sm;
33421
33422 struct ll_disk ll;
33423 struct ll_disk old_ll;
33424 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33425 index e89ae5e..062e4c2 100644
33426 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33427 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33428 @@ -43,7 +43,7 @@ struct block_op {
33429 };
33430
33431 struct sm_metadata {
33432 - struct dm_space_map sm;
33433 + dm_space_map_no_const sm;
33434
33435 struct ll_disk ll;
33436 struct ll_disk old_ll;
33437 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33438 index 1cbfc6b..56e1dbb 100644
33439 --- a/drivers/md/persistent-data/dm-space-map.h
33440 +++ b/drivers/md/persistent-data/dm-space-map.h
33441 @@ -60,6 +60,7 @@ struct dm_space_map {
33442 int (*root_size)(struct dm_space_map *sm, size_t *result);
33443 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33444 };
33445 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33446
33447 /*----------------------------------------------------------------*/
33448
33449 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33450 index d7e9577..faa512f2 100644
33451 --- a/drivers/md/raid1.c
33452 +++ b/drivers/md/raid1.c
33453 @@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33454 if (r1_sync_page_io(rdev, sect, s,
33455 bio->bi_io_vec[idx].bv_page,
33456 READ) != 0)
33457 - atomic_add(s, &rdev->corrected_errors);
33458 + atomic_add_unchecked(s, &rdev->corrected_errors);
33459 }
33460 sectors -= s;
33461 sect += s;
33462 @@ -1902,7 +1902,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33463 test_bit(In_sync, &rdev->flags)) {
33464 if (r1_sync_page_io(rdev, sect, s,
33465 conf->tmppage, READ)) {
33466 - atomic_add(s, &rdev->corrected_errors);
33467 + atomic_add_unchecked(s, &rdev->corrected_errors);
33468 printk(KERN_INFO
33469 "md/raid1:%s: read error corrected "
33470 "(%d sectors at %llu on %s)\n",
33471 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33472 index a954c95..6e7a21c 100644
33473 --- a/drivers/md/raid10.c
33474 +++ b/drivers/md/raid10.c
33475 @@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33476 /* The write handler will notice the lack of
33477 * R10BIO_Uptodate and record any errors etc
33478 */
33479 - atomic_add(r10_bio->sectors,
33480 + atomic_add_unchecked(r10_bio->sectors,
33481 &conf->mirrors[d].rdev->corrected_errors);
33482
33483 /* for reconstruct, we always reschedule after a read.
33484 @@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33485 {
33486 struct timespec cur_time_mon;
33487 unsigned long hours_since_last;
33488 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33489 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33490
33491 ktime_get_ts(&cur_time_mon);
33492
33493 @@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33494 * overflowing the shift of read_errors by hours_since_last.
33495 */
33496 if (hours_since_last >= 8 * sizeof(read_errors))
33497 - atomic_set(&rdev->read_errors, 0);
33498 + atomic_set_unchecked(&rdev->read_errors, 0);
33499 else
33500 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33501 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33502 }
33503
33504 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33505 @@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33506 return;
33507
33508 check_decay_read_errors(mddev, rdev);
33509 - atomic_inc(&rdev->read_errors);
33510 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33511 + atomic_inc_unchecked(&rdev->read_errors);
33512 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33513 char b[BDEVNAME_SIZE];
33514 bdevname(rdev->bdev, b);
33515
33516 @@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33517 "md/raid10:%s: %s: Raid device exceeded "
33518 "read_error threshold [cur %d:max %d]\n",
33519 mdname(mddev), b,
33520 - atomic_read(&rdev->read_errors), max_read_errors);
33521 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33522 printk(KERN_NOTICE
33523 "md/raid10:%s: %s: Failing raid device\n",
33524 mdname(mddev), b);
33525 @@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33526 (unsigned long long)(
33527 sect + rdev->data_offset),
33528 bdevname(rdev->bdev, b));
33529 - atomic_add(s, &rdev->corrected_errors);
33530 + atomic_add_unchecked(s, &rdev->corrected_errors);
33531 }
33532
33533 rdev_dec_pending(rdev, mddev);
33534 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33535 index 73a5800..2b0e3b1 100644
33536 --- a/drivers/md/raid5.c
33537 +++ b/drivers/md/raid5.c
33538 @@ -1694,18 +1694,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33539 (unsigned long long)(sh->sector
33540 + rdev->data_offset),
33541 bdevname(rdev->bdev, b));
33542 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33543 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33544 clear_bit(R5_ReadError, &sh->dev[i].flags);
33545 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33546 }
33547 - if (atomic_read(&rdev->read_errors))
33548 - atomic_set(&rdev->read_errors, 0);
33549 + if (atomic_read_unchecked(&rdev->read_errors))
33550 + atomic_set_unchecked(&rdev->read_errors, 0);
33551 } else {
33552 const char *bdn = bdevname(rdev->bdev, b);
33553 int retry = 0;
33554
33555 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33556 - atomic_inc(&rdev->read_errors);
33557 + atomic_inc_unchecked(&rdev->read_errors);
33558 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33559 printk_ratelimited(
33560 KERN_WARNING
33561 @@ -1734,7 +1734,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33562 (unsigned long long)(sh->sector
33563 + rdev->data_offset),
33564 bdn);
33565 - else if (atomic_read(&rdev->read_errors)
33566 + else if (atomic_read_unchecked(&rdev->read_errors)
33567 > conf->max_nr_stripes)
33568 printk(KERN_WARNING
33569 "md/raid:%s: Too many read errors, failing device %s.\n",
33570 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33571 index d88c4aa..17c80b1 100644
33572 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33573 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33574 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33575 .subvendor = _subvend, .subdevice = _subdev, \
33576 .driver_data = (unsigned long)&_driverdata }
33577
33578 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33579 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33580 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33581 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33582 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33583 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33584 index a7d876f..8c21b61 100644
33585 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33586 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33587 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33588 union {
33589 dmx_ts_cb ts;
33590 dmx_section_cb sec;
33591 - } cb;
33592 + } __no_const cb;
33593
33594 struct dvb_demux *demux;
33595 void *priv;
33596 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33597 index 00a6732..70a682e 100644
33598 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33599 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33600 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33601 const struct dvb_device *template, void *priv, int type)
33602 {
33603 struct dvb_device *dvbdev;
33604 - struct file_operations *dvbdevfops;
33605 + file_operations_no_const *dvbdevfops;
33606 struct device *clsdev;
33607 int minor;
33608 int id;
33609 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33610 index 3940bb0..fb3952a 100644
33611 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33612 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33613 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33614
33615 struct dib0700_adapter_state {
33616 int (*set_param_save) (struct dvb_frontend *);
33617 -};
33618 +} __no_const;
33619
33620 static int dib7070_set_param_override(struct dvb_frontend *fe)
33621 {
33622 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33623 index 451c5a7..649f711 100644
33624 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33625 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33626 @@ -95,7 +95,7 @@ struct su3000_state {
33627
33628 struct s6x0_state {
33629 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33630 -};
33631 +} __no_const;
33632
33633 /* debug */
33634 static int dvb_usb_dw2102_debug;
33635 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33636 index 404f63a..4796533 100644
33637 --- a/drivers/media/dvb/frontends/dib3000.h
33638 +++ b/drivers/media/dvb/frontends/dib3000.h
33639 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33640 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33641 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33642 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33643 -};
33644 +} __no_const;
33645
33646 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33647 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33648 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33649 index 7539a5d..06531a6 100644
33650 --- a/drivers/media/dvb/ngene/ngene-cards.c
33651 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33652 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33653
33654 /****************************************************************************/
33655
33656 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33657 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33658 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33659 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33660 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33661 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33662 index 16a089f..1661b11 100644
33663 --- a/drivers/media/radio/radio-cadet.c
33664 +++ b/drivers/media/radio/radio-cadet.c
33665 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33666 unsigned char readbuf[RDS_BUFFER];
33667 int i = 0;
33668
33669 + if (count > RDS_BUFFER)
33670 + return -EFAULT;
33671 mutex_lock(&dev->lock);
33672 if (dev->rdsstat == 0) {
33673 dev->rdsstat = 1;
33674 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33675 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33676 mutex_unlock(&dev->lock);
33677
33678 - if (copy_to_user(data, readbuf, i))
33679 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33680 return -EFAULT;
33681 return i;
33682 }
33683 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33684 index 9cde353..8c6a1c3 100644
33685 --- a/drivers/media/video/au0828/au0828.h
33686 +++ b/drivers/media/video/au0828/au0828.h
33687 @@ -191,7 +191,7 @@ struct au0828_dev {
33688
33689 /* I2C */
33690 struct i2c_adapter i2c_adap;
33691 - struct i2c_algorithm i2c_algo;
33692 + i2c_algorithm_no_const i2c_algo;
33693 struct i2c_client i2c_client;
33694 u32 i2c_rc;
33695
33696 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33697 index 04bf662..e0ac026 100644
33698 --- a/drivers/media/video/cx88/cx88-alsa.c
33699 +++ b/drivers/media/video/cx88/cx88-alsa.c
33700 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33701 * Only boards with eeprom and byte 1 at eeprom=1 have it
33702 */
33703
33704 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33705 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33706 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33707 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33708 {0, }
33709 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33710 index 88cf9d9..bbc4b2c 100644
33711 --- a/drivers/media/video/omap/omap_vout.c
33712 +++ b/drivers/media/video/omap/omap_vout.c
33713 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33714 OMAP_VIDEO2,
33715 };
33716
33717 -static struct videobuf_queue_ops video_vbq_ops;
33718 /* Variables configurable through module params*/
33719 static u32 video1_numbuffers = 3;
33720 static u32 video2_numbuffers = 3;
33721 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33722 {
33723 struct videobuf_queue *q;
33724 struct omap_vout_device *vout = NULL;
33725 + static struct videobuf_queue_ops video_vbq_ops = {
33726 + .buf_setup = omap_vout_buffer_setup,
33727 + .buf_prepare = omap_vout_buffer_prepare,
33728 + .buf_release = omap_vout_buffer_release,
33729 + .buf_queue = omap_vout_buffer_queue,
33730 + };
33731
33732 vout = video_drvdata(file);
33733 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33734 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33735 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33736
33737 q = &vout->vbq;
33738 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33739 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33740 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33741 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33742 spin_lock_init(&vout->vbq_lock);
33743
33744 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33745 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33746 index 305e6aa..0143317 100644
33747 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33748 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33749 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33750
33751 /* I2C stuff */
33752 struct i2c_adapter i2c_adap;
33753 - struct i2c_algorithm i2c_algo;
33754 + i2c_algorithm_no_const i2c_algo;
33755 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33756 int i2c_cx25840_hack_state;
33757 int i2c_linked;
33758 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33759 index 02194c0..091733b 100644
33760 --- a/drivers/media/video/timblogiw.c
33761 +++ b/drivers/media/video/timblogiw.c
33762 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33763
33764 /* Platform device functions */
33765
33766 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33767 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33768 .vidioc_querycap = timblogiw_querycap,
33769 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33770 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33771 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33772 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33773 };
33774
33775 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33776 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33777 .owner = THIS_MODULE,
33778 .open = timblogiw_open,
33779 .release = timblogiw_close,
33780 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33781 index a5c591f..db692a3 100644
33782 --- a/drivers/message/fusion/mptbase.c
33783 +++ b/drivers/message/fusion/mptbase.c
33784 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33785 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33786 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33787
33788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33789 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33790 +#else
33791 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33792 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33793 +#endif
33794 +
33795 /*
33796 * Rounding UP to nearest 4-kB boundary here...
33797 */
33798 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33799 index 551262e..7551198 100644
33800 --- a/drivers/message/fusion/mptsas.c
33801 +++ b/drivers/message/fusion/mptsas.c
33802 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33803 return 0;
33804 }
33805
33806 +static inline void
33807 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33808 +{
33809 + if (phy_info->port_details) {
33810 + phy_info->port_details->rphy = rphy;
33811 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33812 + ioc->name, rphy));
33813 + }
33814 +
33815 + if (rphy) {
33816 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33817 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33818 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33819 + ioc->name, rphy, rphy->dev.release));
33820 + }
33821 +}
33822 +
33823 /* no mutex */
33824 static void
33825 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33826 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33827 return NULL;
33828 }
33829
33830 -static inline void
33831 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33832 -{
33833 - if (phy_info->port_details) {
33834 - phy_info->port_details->rphy = rphy;
33835 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33836 - ioc->name, rphy));
33837 - }
33838 -
33839 - if (rphy) {
33840 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33841 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33842 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33843 - ioc->name, rphy, rphy->dev.release));
33844 - }
33845 -}
33846 -
33847 static inline struct sas_port *
33848 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33849 {
33850 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33851 index 0c3ced7..1fe34ec 100644
33852 --- a/drivers/message/fusion/mptscsih.c
33853 +++ b/drivers/message/fusion/mptscsih.c
33854 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33855
33856 h = shost_priv(SChost);
33857
33858 - if (h) {
33859 - if (h->info_kbuf == NULL)
33860 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33861 - return h->info_kbuf;
33862 - h->info_kbuf[0] = '\0';
33863 + if (!h)
33864 + return NULL;
33865
33866 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33867 - h->info_kbuf[size-1] = '\0';
33868 - }
33869 + if (h->info_kbuf == NULL)
33870 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33871 + return h->info_kbuf;
33872 + h->info_kbuf[0] = '\0';
33873 +
33874 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33875 + h->info_kbuf[size-1] = '\0';
33876
33877 return h->info_kbuf;
33878 }
33879 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33880 index 6d115c7..58ff7fd 100644
33881 --- a/drivers/message/i2o/i2o_proc.c
33882 +++ b/drivers/message/i2o/i2o_proc.c
33883 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33884 "Array Controller Device"
33885 };
33886
33887 -static char *chtostr(u8 * chars, int n)
33888 -{
33889 - char tmp[256];
33890 - tmp[0] = 0;
33891 - return strncat(tmp, (char *)chars, n);
33892 -}
33893 -
33894 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33895 char *group)
33896 {
33897 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33898
33899 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33900 seq_printf(seq, "%-#8x", ddm_table.module_id);
33901 - seq_printf(seq, "%-29s",
33902 - chtostr(ddm_table.module_name_version, 28));
33903 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33904 seq_printf(seq, "%9d ", ddm_table.data_size);
33905 seq_printf(seq, "%8d", ddm_table.code_size);
33906
33907 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33908
33909 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33910 seq_printf(seq, "%-#8x", dst->module_id);
33911 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33912 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33913 + seq_printf(seq, "%-.28s", dst->module_name_version);
33914 + seq_printf(seq, "%-.8s", dst->date);
33915 seq_printf(seq, "%8d ", dst->module_size);
33916 seq_printf(seq, "%8d ", dst->mpb_size);
33917 seq_printf(seq, "0x%04x", dst->module_flags);
33918 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33919 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33920 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33921 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33922 - seq_printf(seq, "Vendor info : %s\n",
33923 - chtostr((u8 *) (work32 + 2), 16));
33924 - seq_printf(seq, "Product info : %s\n",
33925 - chtostr((u8 *) (work32 + 6), 16));
33926 - seq_printf(seq, "Description : %s\n",
33927 - chtostr((u8 *) (work32 + 10), 16));
33928 - seq_printf(seq, "Product rev. : %s\n",
33929 - chtostr((u8 *) (work32 + 14), 8));
33930 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33931 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33932 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33933 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33934
33935 seq_printf(seq, "Serial number : ");
33936 print_serial_number(seq, (u8 *) (work32 + 16),
33937 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33938 }
33939
33940 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33941 - seq_printf(seq, "Module name : %s\n",
33942 - chtostr(result.module_name, 24));
33943 - seq_printf(seq, "Module revision : %s\n",
33944 - chtostr(result.module_rev, 8));
33945 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33946 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33947
33948 seq_printf(seq, "Serial number : ");
33949 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33950 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33951 return 0;
33952 }
33953
33954 - seq_printf(seq, "Device name : %s\n",
33955 - chtostr(result.device_name, 64));
33956 - seq_printf(seq, "Service name : %s\n",
33957 - chtostr(result.service_name, 64));
33958 - seq_printf(seq, "Physical name : %s\n",
33959 - chtostr(result.physical_location, 64));
33960 - seq_printf(seq, "Instance number : %s\n",
33961 - chtostr(result.instance_number, 4));
33962 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33963 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33964 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33965 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33966
33967 return 0;
33968 }
33969 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
33970 index a8c08f3..155fe3d 100644
33971 --- a/drivers/message/i2o/iop.c
33972 +++ b/drivers/message/i2o/iop.c
33973 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
33974
33975 spin_lock_irqsave(&c->context_list_lock, flags);
33976
33977 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33978 - atomic_inc(&c->context_list_counter);
33979 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33980 + atomic_inc_unchecked(&c->context_list_counter);
33981
33982 - entry->context = atomic_read(&c->context_list_counter);
33983 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33984
33985 list_add(&entry->list, &c->context_list);
33986
33987 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
33988
33989 #if BITS_PER_LONG == 64
33990 spin_lock_init(&c->context_list_lock);
33991 - atomic_set(&c->context_list_counter, 0);
33992 + atomic_set_unchecked(&c->context_list_counter, 0);
33993 INIT_LIST_HEAD(&c->context_list);
33994 #endif
33995
33996 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
33997 index 7ce65f4..e66e9bc 100644
33998 --- a/drivers/mfd/abx500-core.c
33999 +++ b/drivers/mfd/abx500-core.c
34000 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34001
34002 struct abx500_device_entry {
34003 struct list_head list;
34004 - struct abx500_ops ops;
34005 + abx500_ops_no_const ops;
34006 struct device *dev;
34007 };
34008
34009 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34010 index a9223ed..4127b13 100644
34011 --- a/drivers/mfd/janz-cmodio.c
34012 +++ b/drivers/mfd/janz-cmodio.c
34013 @@ -13,6 +13,7 @@
34014
34015 #include <linux/kernel.h>
34016 #include <linux/module.h>
34017 +#include <linux/slab.h>
34018 #include <linux/init.h>
34019 #include <linux/pci.h>
34020 #include <linux/interrupt.h>
34021 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34022 index a981e2a..5ca0c8b 100644
34023 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34024 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34025 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34026 * the lid is closed. This leads to interrupts as soon as a little move
34027 * is done.
34028 */
34029 - atomic_inc(&lis3->count);
34030 + atomic_inc_unchecked(&lis3->count);
34031
34032 wake_up_interruptible(&lis3->misc_wait);
34033 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34034 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34035 if (lis3->pm_dev)
34036 pm_runtime_get_sync(lis3->pm_dev);
34037
34038 - atomic_set(&lis3->count, 0);
34039 + atomic_set_unchecked(&lis3->count, 0);
34040 return 0;
34041 }
34042
34043 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34044 add_wait_queue(&lis3->misc_wait, &wait);
34045 while (true) {
34046 set_current_state(TASK_INTERRUPTIBLE);
34047 - data = atomic_xchg(&lis3->count, 0);
34048 + data = atomic_xchg_unchecked(&lis3->count, 0);
34049 if (data)
34050 break;
34051
34052 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34053 struct lis3lv02d, miscdev);
34054
34055 poll_wait(file, &lis3->misc_wait, wait);
34056 - if (atomic_read(&lis3->count))
34057 + if (atomic_read_unchecked(&lis3->count))
34058 return POLLIN | POLLRDNORM;
34059 return 0;
34060 }
34061 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34062 index 2b1482a..5d33616 100644
34063 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34064 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34065 @@ -266,7 +266,7 @@ struct lis3lv02d {
34066 struct input_polled_dev *idev; /* input device */
34067 struct platform_device *pdev; /* platform device */
34068 struct regulator_bulk_data regulators[2];
34069 - atomic_t count; /* interrupt count after last read */
34070 + atomic_unchecked_t count; /* interrupt count after last read */
34071 union axis_conversion ac; /* hw -> logical axis */
34072 int mapped_btns[3];
34073
34074 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34075 index 2f30bad..c4c13d0 100644
34076 --- a/drivers/misc/sgi-gru/gruhandles.c
34077 +++ b/drivers/misc/sgi-gru/gruhandles.c
34078 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34079 unsigned long nsec;
34080
34081 nsec = CLKS2NSEC(clks);
34082 - atomic_long_inc(&mcs_op_statistics[op].count);
34083 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34084 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34085 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34086 if (mcs_op_statistics[op].max < nsec)
34087 mcs_op_statistics[op].max = nsec;
34088 }
34089 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34090 index 950dbe9..eeef0f8 100644
34091 --- a/drivers/misc/sgi-gru/gruprocfs.c
34092 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34093 @@ -32,9 +32,9 @@
34094
34095 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34096
34097 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34098 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34099 {
34100 - unsigned long val = atomic_long_read(v);
34101 + unsigned long val = atomic_long_read_unchecked(v);
34102
34103 seq_printf(s, "%16lu %s\n", val, id);
34104 }
34105 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34106
34107 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34108 for (op = 0; op < mcsop_last; op++) {
34109 - count = atomic_long_read(&mcs_op_statistics[op].count);
34110 - total = atomic_long_read(&mcs_op_statistics[op].total);
34111 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34112 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34113 max = mcs_op_statistics[op].max;
34114 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34115 count ? total / count : 0, max);
34116 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34117 index 5c3ce24..4915ccb 100644
34118 --- a/drivers/misc/sgi-gru/grutables.h
34119 +++ b/drivers/misc/sgi-gru/grutables.h
34120 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34121 * GRU statistics.
34122 */
34123 struct gru_stats_s {
34124 - atomic_long_t vdata_alloc;
34125 - atomic_long_t vdata_free;
34126 - atomic_long_t gts_alloc;
34127 - atomic_long_t gts_free;
34128 - atomic_long_t gms_alloc;
34129 - atomic_long_t gms_free;
34130 - atomic_long_t gts_double_allocate;
34131 - atomic_long_t assign_context;
34132 - atomic_long_t assign_context_failed;
34133 - atomic_long_t free_context;
34134 - atomic_long_t load_user_context;
34135 - atomic_long_t load_kernel_context;
34136 - atomic_long_t lock_kernel_context;
34137 - atomic_long_t unlock_kernel_context;
34138 - atomic_long_t steal_user_context;
34139 - atomic_long_t steal_kernel_context;
34140 - atomic_long_t steal_context_failed;
34141 - atomic_long_t nopfn;
34142 - atomic_long_t asid_new;
34143 - atomic_long_t asid_next;
34144 - atomic_long_t asid_wrap;
34145 - atomic_long_t asid_reuse;
34146 - atomic_long_t intr;
34147 - atomic_long_t intr_cbr;
34148 - atomic_long_t intr_tfh;
34149 - atomic_long_t intr_spurious;
34150 - atomic_long_t intr_mm_lock_failed;
34151 - atomic_long_t call_os;
34152 - atomic_long_t call_os_wait_queue;
34153 - atomic_long_t user_flush_tlb;
34154 - atomic_long_t user_unload_context;
34155 - atomic_long_t user_exception;
34156 - atomic_long_t set_context_option;
34157 - atomic_long_t check_context_retarget_intr;
34158 - atomic_long_t check_context_unload;
34159 - atomic_long_t tlb_dropin;
34160 - atomic_long_t tlb_preload_page;
34161 - atomic_long_t tlb_dropin_fail_no_asid;
34162 - atomic_long_t tlb_dropin_fail_upm;
34163 - atomic_long_t tlb_dropin_fail_invalid;
34164 - atomic_long_t tlb_dropin_fail_range_active;
34165 - atomic_long_t tlb_dropin_fail_idle;
34166 - atomic_long_t tlb_dropin_fail_fmm;
34167 - atomic_long_t tlb_dropin_fail_no_exception;
34168 - atomic_long_t tfh_stale_on_fault;
34169 - atomic_long_t mmu_invalidate_range;
34170 - atomic_long_t mmu_invalidate_page;
34171 - atomic_long_t flush_tlb;
34172 - atomic_long_t flush_tlb_gru;
34173 - atomic_long_t flush_tlb_gru_tgh;
34174 - atomic_long_t flush_tlb_gru_zero_asid;
34175 + atomic_long_unchecked_t vdata_alloc;
34176 + atomic_long_unchecked_t vdata_free;
34177 + atomic_long_unchecked_t gts_alloc;
34178 + atomic_long_unchecked_t gts_free;
34179 + atomic_long_unchecked_t gms_alloc;
34180 + atomic_long_unchecked_t gms_free;
34181 + atomic_long_unchecked_t gts_double_allocate;
34182 + atomic_long_unchecked_t assign_context;
34183 + atomic_long_unchecked_t assign_context_failed;
34184 + atomic_long_unchecked_t free_context;
34185 + atomic_long_unchecked_t load_user_context;
34186 + atomic_long_unchecked_t load_kernel_context;
34187 + atomic_long_unchecked_t lock_kernel_context;
34188 + atomic_long_unchecked_t unlock_kernel_context;
34189 + atomic_long_unchecked_t steal_user_context;
34190 + atomic_long_unchecked_t steal_kernel_context;
34191 + atomic_long_unchecked_t steal_context_failed;
34192 + atomic_long_unchecked_t nopfn;
34193 + atomic_long_unchecked_t asid_new;
34194 + atomic_long_unchecked_t asid_next;
34195 + atomic_long_unchecked_t asid_wrap;
34196 + atomic_long_unchecked_t asid_reuse;
34197 + atomic_long_unchecked_t intr;
34198 + atomic_long_unchecked_t intr_cbr;
34199 + atomic_long_unchecked_t intr_tfh;
34200 + atomic_long_unchecked_t intr_spurious;
34201 + atomic_long_unchecked_t intr_mm_lock_failed;
34202 + atomic_long_unchecked_t call_os;
34203 + atomic_long_unchecked_t call_os_wait_queue;
34204 + atomic_long_unchecked_t user_flush_tlb;
34205 + atomic_long_unchecked_t user_unload_context;
34206 + atomic_long_unchecked_t user_exception;
34207 + atomic_long_unchecked_t set_context_option;
34208 + atomic_long_unchecked_t check_context_retarget_intr;
34209 + atomic_long_unchecked_t check_context_unload;
34210 + atomic_long_unchecked_t tlb_dropin;
34211 + atomic_long_unchecked_t tlb_preload_page;
34212 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34213 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34214 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34215 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34216 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34217 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34218 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34219 + atomic_long_unchecked_t tfh_stale_on_fault;
34220 + atomic_long_unchecked_t mmu_invalidate_range;
34221 + atomic_long_unchecked_t mmu_invalidate_page;
34222 + atomic_long_unchecked_t flush_tlb;
34223 + atomic_long_unchecked_t flush_tlb_gru;
34224 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34225 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34226
34227 - atomic_long_t copy_gpa;
34228 - atomic_long_t read_gpa;
34229 + atomic_long_unchecked_t copy_gpa;
34230 + atomic_long_unchecked_t read_gpa;
34231
34232 - atomic_long_t mesq_receive;
34233 - atomic_long_t mesq_receive_none;
34234 - atomic_long_t mesq_send;
34235 - atomic_long_t mesq_send_failed;
34236 - atomic_long_t mesq_noop;
34237 - atomic_long_t mesq_send_unexpected_error;
34238 - atomic_long_t mesq_send_lb_overflow;
34239 - atomic_long_t mesq_send_qlimit_reached;
34240 - atomic_long_t mesq_send_amo_nacked;
34241 - atomic_long_t mesq_send_put_nacked;
34242 - atomic_long_t mesq_page_overflow;
34243 - atomic_long_t mesq_qf_locked;
34244 - atomic_long_t mesq_qf_noop_not_full;
34245 - atomic_long_t mesq_qf_switch_head_failed;
34246 - atomic_long_t mesq_qf_unexpected_error;
34247 - atomic_long_t mesq_noop_unexpected_error;
34248 - atomic_long_t mesq_noop_lb_overflow;
34249 - atomic_long_t mesq_noop_qlimit_reached;
34250 - atomic_long_t mesq_noop_amo_nacked;
34251 - atomic_long_t mesq_noop_put_nacked;
34252 - atomic_long_t mesq_noop_page_overflow;
34253 + atomic_long_unchecked_t mesq_receive;
34254 + atomic_long_unchecked_t mesq_receive_none;
34255 + atomic_long_unchecked_t mesq_send;
34256 + atomic_long_unchecked_t mesq_send_failed;
34257 + atomic_long_unchecked_t mesq_noop;
34258 + atomic_long_unchecked_t mesq_send_unexpected_error;
34259 + atomic_long_unchecked_t mesq_send_lb_overflow;
34260 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34261 + atomic_long_unchecked_t mesq_send_amo_nacked;
34262 + atomic_long_unchecked_t mesq_send_put_nacked;
34263 + atomic_long_unchecked_t mesq_page_overflow;
34264 + atomic_long_unchecked_t mesq_qf_locked;
34265 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34266 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34267 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34268 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34269 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34270 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34271 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34272 + atomic_long_unchecked_t mesq_noop_put_nacked;
34273 + atomic_long_unchecked_t mesq_noop_page_overflow;
34274
34275 };
34276
34277 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34278 tghop_invalidate, mcsop_last};
34279
34280 struct mcs_op_statistic {
34281 - atomic_long_t count;
34282 - atomic_long_t total;
34283 + atomic_long_unchecked_t count;
34284 + atomic_long_unchecked_t total;
34285 unsigned long max;
34286 };
34287
34288 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34289
34290 #define STAT(id) do { \
34291 if (gru_options & OPT_STATS) \
34292 - atomic_long_inc(&gru_stats.id); \
34293 + atomic_long_inc_unchecked(&gru_stats.id); \
34294 } while (0)
34295
34296 #ifdef CONFIG_SGI_GRU_DEBUG
34297 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34298 index c862cd4..0d176fe 100644
34299 --- a/drivers/misc/sgi-xp/xp.h
34300 +++ b/drivers/misc/sgi-xp/xp.h
34301 @@ -288,7 +288,7 @@ struct xpc_interface {
34302 xpc_notify_func, void *);
34303 void (*received) (short, int, void *);
34304 enum xp_retval (*partid_to_nasids) (short, void *);
34305 -};
34306 +} __no_const;
34307
34308 extern struct xpc_interface xpc_interface;
34309
34310 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34311 index b94d5f7..7f494c5 100644
34312 --- a/drivers/misc/sgi-xp/xpc.h
34313 +++ b/drivers/misc/sgi-xp/xpc.h
34314 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34315 void (*received_payload) (struct xpc_channel *, void *);
34316 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34317 };
34318 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34319
34320 /* struct xpc_partition act_state values (for XPC HB) */
34321
34322 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34323 /* found in xpc_main.c */
34324 extern struct device *xpc_part;
34325 extern struct device *xpc_chan;
34326 -extern struct xpc_arch_operations xpc_arch_ops;
34327 +extern xpc_arch_operations_no_const xpc_arch_ops;
34328 extern int xpc_disengage_timelimit;
34329 extern int xpc_disengage_timedout;
34330 extern int xpc_activate_IRQ_rcvd;
34331 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34332 index 8d082b4..aa749ae 100644
34333 --- a/drivers/misc/sgi-xp/xpc_main.c
34334 +++ b/drivers/misc/sgi-xp/xpc_main.c
34335 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34336 .notifier_call = xpc_system_die,
34337 };
34338
34339 -struct xpc_arch_operations xpc_arch_ops;
34340 +xpc_arch_operations_no_const xpc_arch_ops;
34341
34342 /*
34343 * Timer function to enforce the timelimit on the partition disengage.
34344 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34345 index 69ef0be..f3ef91e 100644
34346 --- a/drivers/mmc/host/sdhci-pci.c
34347 +++ b/drivers/mmc/host/sdhci-pci.c
34348 @@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34349 .probe = via_probe,
34350 };
34351
34352 -static const struct pci_device_id pci_ids[] __devinitdata = {
34353 +static const struct pci_device_id pci_ids[] __devinitconst = {
34354 {
34355 .vendor = PCI_VENDOR_ID_RICOH,
34356 .device = PCI_DEVICE_ID_RICOH_R5C822,
34357 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34358 index a4eb8b5..8c0628f 100644
34359 --- a/drivers/mtd/devices/doc2000.c
34360 +++ b/drivers/mtd/devices/doc2000.c
34361 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34362
34363 /* The ECC will not be calculated correctly if less than 512 is written */
34364 /* DBB-
34365 - if (len != 0x200 && eccbuf)
34366 + if (len != 0x200)
34367 printk(KERN_WARNING
34368 "ECC needs a full sector write (adr: %lx size %lx)\n",
34369 (long) to, (long) len);
34370 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34371 index a9e57d6..c6d8731 100644
34372 --- a/drivers/mtd/nand/denali.c
34373 +++ b/drivers/mtd/nand/denali.c
34374 @@ -26,6 +26,7 @@
34375 #include <linux/pci.h>
34376 #include <linux/mtd/mtd.h>
34377 #include <linux/module.h>
34378 +#include <linux/slab.h>
34379
34380 #include "denali.h"
34381
34382 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34383 index 51b9d6a..52af9a7 100644
34384 --- a/drivers/mtd/nftlmount.c
34385 +++ b/drivers/mtd/nftlmount.c
34386 @@ -24,6 +24,7 @@
34387 #include <asm/errno.h>
34388 #include <linux/delay.h>
34389 #include <linux/slab.h>
34390 +#include <linux/sched.h>
34391 #include <linux/mtd/mtd.h>
34392 #include <linux/mtd/nand.h>
34393 #include <linux/mtd/nftl.h>
34394 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34395 index 6762dc4..9956862 100644
34396 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34397 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34398 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34399 */
34400
34401 #define ATL2_PARAM(X, desc) \
34402 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34403 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34404 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34405 MODULE_PARM_DESC(X, desc);
34406 #else
34407 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34408 index 61a7670..7da6e34 100644
34409 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34410 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34411 @@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34412
34413 int (*wait_comp)(struct bnx2x *bp,
34414 struct bnx2x_rx_mode_ramrod_params *p);
34415 -};
34416 +} __no_const;
34417
34418 /********************** Set multicast group ***********************************/
34419
34420 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34421 index 93865f8..5448741 100644
34422 --- a/drivers/net/ethernet/broadcom/tg3.h
34423 +++ b/drivers/net/ethernet/broadcom/tg3.h
34424 @@ -140,6 +140,7 @@
34425 #define CHIPREV_ID_5750_A0 0x4000
34426 #define CHIPREV_ID_5750_A1 0x4001
34427 #define CHIPREV_ID_5750_A3 0x4003
34428 +#define CHIPREV_ID_5750_C1 0x4201
34429 #define CHIPREV_ID_5750_C2 0x4202
34430 #define CHIPREV_ID_5752_A0_HW 0x5000
34431 #define CHIPREV_ID_5752_A0 0x6000
34432 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34433 index c4e8643..0979484 100644
34434 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34435 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34436 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34437 */
34438 struct l2t_skb_cb {
34439 arp_failure_handler_func arp_failure_handler;
34440 -};
34441 +} __no_const;
34442
34443 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34444
34445 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34446 index 18b106c..2b38d36 100644
34447 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34448 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34449 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34450 for (i=0; i<ETH_ALEN; i++) {
34451 tmp.addr[i] = dev->dev_addr[i];
34452 }
34453 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34454 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34455 break;
34456
34457 case DE4X5_SET_HWADDR: /* Set the hardware address */
34458 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34459 spin_lock_irqsave(&lp->lock, flags);
34460 memcpy(&statbuf, &lp->pktStats, ioc->len);
34461 spin_unlock_irqrestore(&lp->lock, flags);
34462 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34463 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34464 return -EFAULT;
34465 break;
34466 }
34467 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34468 index ed7d1dc..d426748 100644
34469 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34470 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34471 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34472 {NULL}};
34473
34474
34475 -static const char *block_name[] __devinitdata = {
34476 +static const char *block_name[] __devinitconst = {
34477 "21140 non-MII",
34478 "21140 MII PHY",
34479 "21142 Serial PHY",
34480 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34481 index 2ac6fff..2d127d0 100644
34482 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34483 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34484 @@ -236,7 +236,7 @@ struct pci_id_info {
34485 int drv_flags; /* Driver use, intended as capability flags. */
34486 };
34487
34488 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34489 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34490 { /* Sometime a Level-One switch card. */
34491 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34492 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34493 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34494 index d783f4f..97fa1b0 100644
34495 --- a/drivers/net/ethernet/dlink/sundance.c
34496 +++ b/drivers/net/ethernet/dlink/sundance.c
34497 @@ -218,7 +218,7 @@ enum {
34498 struct pci_id_info {
34499 const char *name;
34500 };
34501 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34502 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34503 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34504 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34505 {"D-Link DFE-580TX 4 port Server Adapter"},
34506 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34507 index 1bbf6b3..430dcd0 100644
34508 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34509 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34510 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34511
34512 if (wrapped)
34513 newacc += 65536;
34514 - ACCESS_ONCE(*acc) = newacc;
34515 + ACCESS_ONCE_RW(*acc) = newacc;
34516 }
34517
34518 void be_parse_stats(struct be_adapter *adapter)
34519 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34520 index 16b0704..d2c07d7 100644
34521 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34522 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34523 @@ -31,6 +31,8 @@
34524 #include <linux/netdevice.h>
34525 #include <linux/phy.h>
34526 #include <linux/platform_device.h>
34527 +#include <linux/interrupt.h>
34528 +#include <linux/irqreturn.h>
34529 #include <net/ip.h>
34530
34531 #include "ftgmac100.h"
34532 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34533 index 829b109..4ae5f6a 100644
34534 --- a/drivers/net/ethernet/faraday/ftmac100.c
34535 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34536 @@ -31,6 +31,8 @@
34537 #include <linux/module.h>
34538 #include <linux/netdevice.h>
34539 #include <linux/platform_device.h>
34540 +#include <linux/interrupt.h>
34541 +#include <linux/irqreturn.h>
34542
34543 #include "ftmac100.h"
34544
34545 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34546 index 1637b98..c42f87b 100644
34547 --- a/drivers/net/ethernet/fealnx.c
34548 +++ b/drivers/net/ethernet/fealnx.c
34549 @@ -150,7 +150,7 @@ struct chip_info {
34550 int flags;
34551 };
34552
34553 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34554 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34555 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34556 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34557 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34558 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34559 index b83897f..b2d970f 100644
34560 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34561 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34562 @@ -181,7 +181,7 @@ struct e1000_info;
34563 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34564 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34565 E1000_TXDCTL_COUNT_DESC | \
34566 - (5 << 16) | /* wthresh must be +1 more than desired */\
34567 + (1 << 16) | /* wthresh must be +1 more than desired */\
34568 (1 << 8) | /* hthresh */ \
34569 0x1f) /* pthresh */
34570
34571 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34572 index f82ecf5..7d59ecb 100644
34573 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34574 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34575 @@ -784,6 +784,7 @@ struct e1000_mac_operations {
34576 void (*config_collision_dist)(struct e1000_hw *);
34577 s32 (*read_mac_addr)(struct e1000_hw *);
34578 };
34579 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34580
34581 /*
34582 * When to use various PHY register access functions:
34583 @@ -824,6 +825,7 @@ struct e1000_phy_operations {
34584 void (*power_up)(struct e1000_hw *);
34585 void (*power_down)(struct e1000_hw *);
34586 };
34587 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34588
34589 /* Function pointers for the NVM. */
34590 struct e1000_nvm_operations {
34591 @@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34592 s32 (*validate)(struct e1000_hw *);
34593 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34594 };
34595 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34596
34597 struct e1000_mac_info {
34598 - struct e1000_mac_operations ops;
34599 + e1000_mac_operations_no_const ops;
34600 u8 addr[ETH_ALEN];
34601 u8 perm_addr[ETH_ALEN];
34602
34603 @@ -879,7 +882,7 @@ struct e1000_mac_info {
34604 };
34605
34606 struct e1000_phy_info {
34607 - struct e1000_phy_operations ops;
34608 + e1000_phy_operations_no_const ops;
34609
34610 enum e1000_phy_type type;
34611
34612 @@ -913,7 +916,7 @@ struct e1000_phy_info {
34613 };
34614
34615 struct e1000_nvm_info {
34616 - struct e1000_nvm_operations ops;
34617 + e1000_nvm_operations_no_const ops;
34618
34619 enum e1000_nvm_type type;
34620 enum e1000_nvm_override override;
34621 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34622 index f67cbd3..cef9e3d 100644
34623 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34624 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34625 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34626 s32 (*read_mac_addr)(struct e1000_hw *);
34627 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34628 };
34629 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34630
34631 struct e1000_phy_operations {
34632 s32 (*acquire)(struct e1000_hw *);
34633 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34634 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34635 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34636 };
34637 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34638
34639 struct e1000_nvm_operations {
34640 s32 (*acquire)(struct e1000_hw *);
34641 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34642 s32 (*update)(struct e1000_hw *);
34643 s32 (*validate)(struct e1000_hw *);
34644 };
34645 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34646
34647 struct e1000_info {
34648 s32 (*get_invariants)(struct e1000_hw *);
34649 @@ -350,7 +353,7 @@ struct e1000_info {
34650 extern const struct e1000_info e1000_82575_info;
34651
34652 struct e1000_mac_info {
34653 - struct e1000_mac_operations ops;
34654 + e1000_mac_operations_no_const ops;
34655
34656 u8 addr[6];
34657 u8 perm_addr[6];
34658 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34659 };
34660
34661 struct e1000_phy_info {
34662 - struct e1000_phy_operations ops;
34663 + e1000_phy_operations_no_const ops;
34664
34665 enum e1000_phy_type type;
34666
34667 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34668 };
34669
34670 struct e1000_nvm_info {
34671 - struct e1000_nvm_operations ops;
34672 + e1000_nvm_operations_no_const ops;
34673 enum e1000_nvm_type type;
34674 enum e1000_nvm_override override;
34675
34676 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34677 s32 (*check_for_ack)(struct e1000_hw *, u16);
34678 s32 (*check_for_rst)(struct e1000_hw *, u16);
34679 };
34680 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34681
34682 struct e1000_mbx_stats {
34683 u32 msgs_tx;
34684 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34685 };
34686
34687 struct e1000_mbx_info {
34688 - struct e1000_mbx_operations ops;
34689 + e1000_mbx_operations_no_const ops;
34690 struct e1000_mbx_stats stats;
34691 u32 timeout;
34692 u32 usec_delay;
34693 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34694 index 57db3c6..aa825fc 100644
34695 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34696 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34697 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34698 s32 (*read_mac_addr)(struct e1000_hw *);
34699 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34700 };
34701 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34702
34703 struct e1000_mac_info {
34704 - struct e1000_mac_operations ops;
34705 + e1000_mac_operations_no_const ops;
34706 u8 addr[6];
34707 u8 perm_addr[6];
34708
34709 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34710 s32 (*check_for_ack)(struct e1000_hw *);
34711 s32 (*check_for_rst)(struct e1000_hw *);
34712 };
34713 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34714
34715 struct e1000_mbx_stats {
34716 u32 msgs_tx;
34717 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34718 };
34719
34720 struct e1000_mbx_info {
34721 - struct e1000_mbx_operations ops;
34722 + e1000_mbx_operations_no_const ops;
34723 struct e1000_mbx_stats stats;
34724 u32 timeout;
34725 u32 usec_delay;
34726 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34727 index 8636e83..ab9bbc3 100644
34728 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34729 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34730 @@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34731 s32 (*update_checksum)(struct ixgbe_hw *);
34732 u16 (*calc_checksum)(struct ixgbe_hw *);
34733 };
34734 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34735
34736 struct ixgbe_mac_operations {
34737 s32 (*init_hw)(struct ixgbe_hw *);
34738 @@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34739 /* Manageability interface */
34740 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34741 };
34742 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34743
34744 struct ixgbe_phy_operations {
34745 s32 (*identify)(struct ixgbe_hw *);
34746 @@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34747 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34748 s32 (*check_overtemp)(struct ixgbe_hw *);
34749 };
34750 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34751
34752 struct ixgbe_eeprom_info {
34753 - struct ixgbe_eeprom_operations ops;
34754 + ixgbe_eeprom_operations_no_const ops;
34755 enum ixgbe_eeprom_type type;
34756 u32 semaphore_delay;
34757 u16 word_size;
34758 @@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34759
34760 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34761 struct ixgbe_mac_info {
34762 - struct ixgbe_mac_operations ops;
34763 + ixgbe_mac_operations_no_const ops;
34764 enum ixgbe_mac_type type;
34765 u8 addr[ETH_ALEN];
34766 u8 perm_addr[ETH_ALEN];
34767 @@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34768 };
34769
34770 struct ixgbe_phy_info {
34771 - struct ixgbe_phy_operations ops;
34772 + ixgbe_phy_operations_no_const ops;
34773 struct mdio_if_info mdio;
34774 enum ixgbe_phy_type type;
34775 u32 id;
34776 @@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34777 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34778 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34779 };
34780 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34781
34782 struct ixgbe_mbx_stats {
34783 u32 msgs_tx;
34784 @@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34785 };
34786
34787 struct ixgbe_mbx_info {
34788 - struct ixgbe_mbx_operations ops;
34789 + ixgbe_mbx_operations_no_const ops;
34790 struct ixgbe_mbx_stats stats;
34791 u32 timeout;
34792 u32 usec_delay;
34793 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34794 index 25c951d..cc7cf33 100644
34795 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34796 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34797 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34798 s32 (*clear_vfta)(struct ixgbe_hw *);
34799 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34800 };
34801 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34802
34803 enum ixgbe_mac_type {
34804 ixgbe_mac_unknown = 0,
34805 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34806 };
34807
34808 struct ixgbe_mac_info {
34809 - struct ixgbe_mac_operations ops;
34810 + ixgbe_mac_operations_no_const ops;
34811 u8 addr[6];
34812 u8 perm_addr[6];
34813
34814 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34815 s32 (*check_for_ack)(struct ixgbe_hw *);
34816 s32 (*check_for_rst)(struct ixgbe_hw *);
34817 };
34818 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34819
34820 struct ixgbe_mbx_stats {
34821 u32 msgs_tx;
34822 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34823 };
34824
34825 struct ixgbe_mbx_info {
34826 - struct ixgbe_mbx_operations ops;
34827 + ixgbe_mbx_operations_no_const ops;
34828 struct ixgbe_mbx_stats stats;
34829 u32 timeout;
34830 u32 udelay;
34831 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34832 index 8bb05b4..074796f 100644
34833 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34834 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34835 @@ -41,6 +41,7 @@
34836 #include <linux/slab.h>
34837 #include <linux/io-mapping.h>
34838 #include <linux/delay.h>
34839 +#include <linux/sched.h>
34840
34841 #include <linux/mlx4/device.h>
34842 #include <linux/mlx4/doorbell.h>
34843 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34844 index 5046a64..71ca936 100644
34845 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34846 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34847 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34848 void (*link_down)(struct __vxge_hw_device *devh);
34849 void (*crit_err)(struct __vxge_hw_device *devh,
34850 enum vxge_hw_event type, u64 ext_data);
34851 -};
34852 +} __no_const;
34853
34854 /*
34855 * struct __vxge_hw_blockpool_entry - Block private data structure
34856 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34857 index 4a518a3..936b334 100644
34858 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34859 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34860 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34861 struct vxge_hw_mempool_dma *dma_object,
34862 u32 index,
34863 u32 is_last);
34864 -};
34865 +} __no_const;
34866
34867 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34868 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34869 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34870 index 161e045..0bb5b86 100644
34871 --- a/drivers/net/ethernet/realtek/r8169.c
34872 +++ b/drivers/net/ethernet/realtek/r8169.c
34873 @@ -708,17 +708,17 @@ struct rtl8169_private {
34874 struct mdio_ops {
34875 void (*write)(void __iomem *, int, int);
34876 int (*read)(void __iomem *, int);
34877 - } mdio_ops;
34878 + } __no_const mdio_ops;
34879
34880 struct pll_power_ops {
34881 void (*down)(struct rtl8169_private *);
34882 void (*up)(struct rtl8169_private *);
34883 - } pll_power_ops;
34884 + } __no_const pll_power_ops;
34885
34886 struct jumbo_ops {
34887 void (*enable)(struct rtl8169_private *);
34888 void (*disable)(struct rtl8169_private *);
34889 - } jumbo_ops;
34890 + } __no_const jumbo_ops;
34891
34892 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34893 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34894 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34895 index a9deda8..5507c31 100644
34896 --- a/drivers/net/ethernet/sis/sis190.c
34897 +++ b/drivers/net/ethernet/sis/sis190.c
34898 @@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34899 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34900 struct net_device *dev)
34901 {
34902 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34903 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34904 struct sis190_private *tp = netdev_priv(dev);
34905 struct pci_dev *isa_bridge;
34906 u8 reg, tmp8;
34907 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34908 index c07cfe9..81cbf7e 100644
34909 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34910 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34911 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34912
34913 writel(value, ioaddr + MMC_CNTRL);
34914
34915 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34916 - MMC_CNTRL, value);
34917 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34918 +// MMC_CNTRL, value);
34919 }
34920
34921 /* To mask all all interrupts.*/
34922 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34923 index 48d56da..a27e46c 100644
34924 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34925 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34926 @@ -1584,7 +1584,7 @@ static const struct file_operations stmmac_rings_status_fops = {
34927 .open = stmmac_sysfs_ring_open,
34928 .read = seq_read,
34929 .llseek = seq_lseek,
34930 - .release = seq_release,
34931 + .release = single_release,
34932 };
34933
34934 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
34935 @@ -1656,7 +1656,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
34936 .open = stmmac_sysfs_dma_cap_open,
34937 .read = seq_read,
34938 .llseek = seq_lseek,
34939 - .release = seq_release,
34940 + .release = single_release,
34941 };
34942
34943 static int stmmac_init_fs(struct net_device *dev)
34944 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
34945 index c358245..8c1de63 100644
34946 --- a/drivers/net/hyperv/hyperv_net.h
34947 +++ b/drivers/net/hyperv/hyperv_net.h
34948 @@ -98,7 +98,7 @@ struct rndis_device {
34949
34950 enum rndis_device_state state;
34951 bool link_state;
34952 - atomic_t new_req_id;
34953 + atomic_unchecked_t new_req_id;
34954
34955 spinlock_t request_lock;
34956 struct list_head req_list;
34957 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
34958 index d6be64b..5d97e3b 100644
34959 --- a/drivers/net/hyperv/rndis_filter.c
34960 +++ b/drivers/net/hyperv/rndis_filter.c
34961 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
34962 * template
34963 */
34964 set = &rndis_msg->msg.set_req;
34965 - set->req_id = atomic_inc_return(&dev->new_req_id);
34966 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34967
34968 /* Add to the request list */
34969 spin_lock_irqsave(&dev->request_lock, flags);
34970 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
34971
34972 /* Setup the rndis set */
34973 halt = &request->request_msg.msg.halt_req;
34974 - halt->req_id = atomic_inc_return(&dev->new_req_id);
34975 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34976
34977 /* Ignore return since this msg is optional. */
34978 rndis_filter_send_request(dev, request);
34979 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
34980 index 21d7151..8034208 100644
34981 --- a/drivers/net/ppp/ppp_generic.c
34982 +++ b/drivers/net/ppp/ppp_generic.c
34983 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34984 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34985 struct ppp_stats stats;
34986 struct ppp_comp_stats cstats;
34987 - char *vers;
34988
34989 switch (cmd) {
34990 case SIOCGPPPSTATS:
34991 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34992 break;
34993
34994 case SIOCGPPPVER:
34995 - vers = PPP_VERSION;
34996 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34997 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34998 break;
34999 err = 0;
35000 break;
35001 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35002 index b715e6b..6d2490f 100644
35003 --- a/drivers/net/tokenring/abyss.c
35004 +++ b/drivers/net/tokenring/abyss.c
35005 @@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35006
35007 static int __init abyss_init (void)
35008 {
35009 - abyss_netdev_ops = tms380tr_netdev_ops;
35010 + pax_open_kernel();
35011 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35012
35013 - abyss_netdev_ops.ndo_open = abyss_open;
35014 - abyss_netdev_ops.ndo_stop = abyss_close;
35015 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35016 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35017 + pax_close_kernel();
35018
35019 return pci_register_driver(&abyss_driver);
35020 }
35021 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35022 index 28adcdf..ae82f35 100644
35023 --- a/drivers/net/tokenring/madgemc.c
35024 +++ b/drivers/net/tokenring/madgemc.c
35025 @@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35026
35027 static int __init madgemc_init (void)
35028 {
35029 - madgemc_netdev_ops = tms380tr_netdev_ops;
35030 - madgemc_netdev_ops.ndo_open = madgemc_open;
35031 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35032 + pax_open_kernel();
35033 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35034 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35035 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35036 + pax_close_kernel();
35037
35038 return mca_register_driver (&madgemc_driver);
35039 }
35040 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35041 index 62d90e4..9d84237 100644
35042 --- a/drivers/net/tokenring/proteon.c
35043 +++ b/drivers/net/tokenring/proteon.c
35044 @@ -352,9 +352,11 @@ static int __init proteon_init(void)
35045 struct platform_device *pdev;
35046 int i, num = 0, err = 0;
35047
35048 - proteon_netdev_ops = tms380tr_netdev_ops;
35049 - proteon_netdev_ops.ndo_open = proteon_open;
35050 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35051 + pax_open_kernel();
35052 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35053 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35054 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35055 + pax_close_kernel();
35056
35057 err = platform_driver_register(&proteon_driver);
35058 if (err)
35059 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35060 index ee11e93..c8f19c7 100644
35061 --- a/drivers/net/tokenring/skisa.c
35062 +++ b/drivers/net/tokenring/skisa.c
35063 @@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35064 struct platform_device *pdev;
35065 int i, num = 0, err = 0;
35066
35067 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35068 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35069 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35070 + pax_open_kernel();
35071 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35072 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35073 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35074 + pax_close_kernel();
35075
35076 err = platform_driver_register(&sk_isa_driver);
35077 if (err)
35078 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35079 index 2d2a688..35f2372 100644
35080 --- a/drivers/net/usb/hso.c
35081 +++ b/drivers/net/usb/hso.c
35082 @@ -71,7 +71,7 @@
35083 #include <asm/byteorder.h>
35084 #include <linux/serial_core.h>
35085 #include <linux/serial.h>
35086 -
35087 +#include <asm/local.h>
35088
35089 #define MOD_AUTHOR "Option Wireless"
35090 #define MOD_DESCRIPTION "USB High Speed Option driver"
35091 @@ -257,7 +257,7 @@ struct hso_serial {
35092
35093 /* from usb_serial_port */
35094 struct tty_struct *tty;
35095 - int open_count;
35096 + local_t open_count;
35097 spinlock_t serial_lock;
35098
35099 int (*write_data) (struct hso_serial *serial);
35100 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35101 struct urb *urb;
35102
35103 urb = serial->rx_urb[0];
35104 - if (serial->open_count > 0) {
35105 + if (local_read(&serial->open_count) > 0) {
35106 count = put_rxbuf_data(urb, serial);
35107 if (count == -1)
35108 return;
35109 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35110 DUMP1(urb->transfer_buffer, urb->actual_length);
35111
35112 /* Anyone listening? */
35113 - if (serial->open_count == 0)
35114 + if (local_read(&serial->open_count) == 0)
35115 return;
35116
35117 if (status == 0) {
35118 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35119 spin_unlock_irq(&serial->serial_lock);
35120
35121 /* check for port already opened, if not set the termios */
35122 - serial->open_count++;
35123 - if (serial->open_count == 1) {
35124 + if (local_inc_return(&serial->open_count) == 1) {
35125 serial->rx_state = RX_IDLE;
35126 /* Force default termio settings */
35127 _hso_serial_set_termios(tty, NULL);
35128 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35129 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35130 if (result) {
35131 hso_stop_serial_device(serial->parent);
35132 - serial->open_count--;
35133 + local_dec(&serial->open_count);
35134 kref_put(&serial->parent->ref, hso_serial_ref_free);
35135 }
35136 } else {
35137 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35138
35139 /* reset the rts and dtr */
35140 /* do the actual close */
35141 - serial->open_count--;
35142 + local_dec(&serial->open_count);
35143
35144 - if (serial->open_count <= 0) {
35145 - serial->open_count = 0;
35146 + if (local_read(&serial->open_count) <= 0) {
35147 + local_set(&serial->open_count, 0);
35148 spin_lock_irq(&serial->serial_lock);
35149 if (serial->tty == tty) {
35150 serial->tty->driver_data = NULL;
35151 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35152
35153 /* the actual setup */
35154 spin_lock_irqsave(&serial->serial_lock, flags);
35155 - if (serial->open_count)
35156 + if (local_read(&serial->open_count))
35157 _hso_serial_set_termios(tty, old);
35158 else
35159 tty->termios = old;
35160 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35161 D1("Pending read interrupt on port %d\n", i);
35162 spin_lock(&serial->serial_lock);
35163 if (serial->rx_state == RX_IDLE &&
35164 - serial->open_count > 0) {
35165 + local_read(&serial->open_count) > 0) {
35166 /* Setup and send a ctrl req read on
35167 * port i */
35168 if (!serial->rx_urb_filled[0]) {
35169 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35170 /* Start all serial ports */
35171 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35172 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35173 - if (dev2ser(serial_table[i])->open_count) {
35174 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35175 result =
35176 hso_start_serial_device(serial_table[i], GFP_NOIO);
35177 hso_kick_transmit(dev2ser(serial_table[i]));
35178 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35179 index 420d69b..74f90a2 100644
35180 --- a/drivers/net/wireless/ath/ath.h
35181 +++ b/drivers/net/wireless/ath/ath.h
35182 @@ -119,6 +119,7 @@ struct ath_ops {
35183 void (*write_flush) (void *);
35184 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35185 };
35186 +typedef struct ath_ops __no_const ath_ops_no_const;
35187
35188 struct ath_common;
35189 struct ath_bus_ops;
35190 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35191 index aa2abaf..5f5152d 100644
35192 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35193 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35194 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35195 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35196 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35197
35198 - ACCESS_ONCE(ads->ds_link) = i->link;
35199 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35200 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35201 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35202
35203 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35204 ctl6 = SM(i->keytype, AR_EncrType);
35205 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35206
35207 if ((i->is_first || i->is_last) &&
35208 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35209 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35210 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35211 | set11nTries(i->rates, 1)
35212 | set11nTries(i->rates, 2)
35213 | set11nTries(i->rates, 3)
35214 | (i->dur_update ? AR_DurUpdateEna : 0)
35215 | SM(0, AR_BurstDur);
35216
35217 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35218 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35219 | set11nRate(i->rates, 1)
35220 | set11nRate(i->rates, 2)
35221 | set11nRate(i->rates, 3);
35222 } else {
35223 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35224 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35225 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35226 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35227 }
35228
35229 if (!i->is_first) {
35230 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35231 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35232 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35233 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35234 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35235 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35236 return;
35237 }
35238
35239 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35240 break;
35241 }
35242
35243 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35244 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35245 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35246 | SM(i->txpower, AR_XmitPower)
35247 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35248 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35249 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35250 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35251
35252 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35253 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35254 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35255 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35256
35257 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35258 return;
35259
35260 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35261 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35262 | set11nPktDurRTSCTS(i->rates, 1);
35263
35264 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35265 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35266 | set11nPktDurRTSCTS(i->rates, 3);
35267
35268 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35269 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35270 | set11nRateFlags(i->rates, 1)
35271 | set11nRateFlags(i->rates, 2)
35272 | set11nRateFlags(i->rates, 3)
35273 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35274 index a66a13b..0ef399e 100644
35275 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35276 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35277 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35278 (i->qcu << AR_TxQcuNum_S) | desc_len;
35279
35280 checksum += val;
35281 - ACCESS_ONCE(ads->info) = val;
35282 + ACCESS_ONCE_RW(ads->info) = val;
35283
35284 checksum += i->link;
35285 - ACCESS_ONCE(ads->link) = i->link;
35286 + ACCESS_ONCE_RW(ads->link) = i->link;
35287
35288 checksum += i->buf_addr[0];
35289 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35290 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35291 checksum += i->buf_addr[1];
35292 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35293 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35294 checksum += i->buf_addr[2];
35295 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35296 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35297 checksum += i->buf_addr[3];
35298 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35299 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35300
35301 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35302 - ACCESS_ONCE(ads->ctl3) = val;
35303 + ACCESS_ONCE_RW(ads->ctl3) = val;
35304 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35305 - ACCESS_ONCE(ads->ctl5) = val;
35306 + ACCESS_ONCE_RW(ads->ctl5) = val;
35307 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35308 - ACCESS_ONCE(ads->ctl7) = val;
35309 + ACCESS_ONCE_RW(ads->ctl7) = val;
35310 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35311 - ACCESS_ONCE(ads->ctl9) = val;
35312 + ACCESS_ONCE_RW(ads->ctl9) = val;
35313
35314 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35315 - ACCESS_ONCE(ads->ctl10) = checksum;
35316 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35317
35318 if (i->is_first || i->is_last) {
35319 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35320 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35321 | set11nTries(i->rates, 1)
35322 | set11nTries(i->rates, 2)
35323 | set11nTries(i->rates, 3)
35324 | (i->dur_update ? AR_DurUpdateEna : 0)
35325 | SM(0, AR_BurstDur);
35326
35327 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35328 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35329 | set11nRate(i->rates, 1)
35330 | set11nRate(i->rates, 2)
35331 | set11nRate(i->rates, 3);
35332 } else {
35333 - ACCESS_ONCE(ads->ctl13) = 0;
35334 - ACCESS_ONCE(ads->ctl14) = 0;
35335 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35336 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35337 }
35338
35339 ads->ctl20 = 0;
35340 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35341
35342 ctl17 = SM(i->keytype, AR_EncrType);
35343 if (!i->is_first) {
35344 - ACCESS_ONCE(ads->ctl11) = 0;
35345 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35346 - ACCESS_ONCE(ads->ctl15) = 0;
35347 - ACCESS_ONCE(ads->ctl16) = 0;
35348 - ACCESS_ONCE(ads->ctl17) = ctl17;
35349 - ACCESS_ONCE(ads->ctl18) = 0;
35350 - ACCESS_ONCE(ads->ctl19) = 0;
35351 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35352 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35353 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35354 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35355 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35356 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35357 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35358 return;
35359 }
35360
35361 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35362 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35363 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35364 | SM(i->txpower, AR_XmitPower)
35365 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35366 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35367 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35368 ctl12 |= SM(val, AR_PAPRDChainMask);
35369
35370 - ACCESS_ONCE(ads->ctl12) = ctl12;
35371 - ACCESS_ONCE(ads->ctl17) = ctl17;
35372 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35373 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35374
35375 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35376 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35377 | set11nPktDurRTSCTS(i->rates, 1);
35378
35379 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35380 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35381 | set11nPktDurRTSCTS(i->rates, 3);
35382
35383 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35384 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35385 | set11nRateFlags(i->rates, 1)
35386 | set11nRateFlags(i->rates, 2)
35387 | set11nRateFlags(i->rates, 3)
35388 | SM(i->rtscts_rate, AR_RTSCTSRate);
35389
35390 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35391 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35392 }
35393
35394 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35395 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35396 index e88f182..4e57f5d 100644
35397 --- a/drivers/net/wireless/ath/ath9k/hw.h
35398 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35399 @@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35400
35401 /* ANI */
35402 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35403 -};
35404 +} __no_const;
35405
35406 /**
35407 * struct ath_hw_ops - callbacks used by hardware code and driver code
35408 @@ -644,7 +644,7 @@ struct ath_hw_ops {
35409 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35410 struct ath_hw_antcomb_conf *antconf);
35411
35412 -};
35413 +} __no_const;
35414
35415 struct ath_nf_limits {
35416 s16 max;
35417 @@ -664,7 +664,7 @@ enum ath_cal_list {
35418 #define AH_FASTCC 0x4
35419
35420 struct ath_hw {
35421 - struct ath_ops reg_ops;
35422 + ath_ops_no_const reg_ops;
35423
35424 struct ieee80211_hw *hw;
35425 struct ath_common common;
35426 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35427 index af00e2c..ab04d34 100644
35428 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35429 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35430 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35431 void (*carrsuppr)(struct brcms_phy *);
35432 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35433 void (*detach)(struct brcms_phy *);
35434 -};
35435 +} __no_const;
35436
35437 struct brcms_phy {
35438 struct brcms_phy_pub pubpi_ro;
35439 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35440 index faec404..a5277f1 100644
35441 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35442 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35443 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35444 */
35445 if (il3945_mod_params.disable_hw_scan) {
35446 D_INFO("Disabling hw_scan\n");
35447 - il3945_mac_ops.hw_scan = NULL;
35448 + pax_open_kernel();
35449 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35450 + pax_close_kernel();
35451 }
35452
35453 D_INFO("*** LOAD DRIVER ***\n");
35454 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35455 index b7ce6a6..5649756 100644
35456 --- a/drivers/net/wireless/mac80211_hwsim.c
35457 +++ b/drivers/net/wireless/mac80211_hwsim.c
35458 @@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35459 return -EINVAL;
35460
35461 if (fake_hw_scan) {
35462 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35463 - mac80211_hwsim_ops.sw_scan_start = NULL;
35464 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35465 + pax_open_kernel();
35466 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35467 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35468 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35469 + pax_close_kernel();
35470 }
35471
35472 spin_lock_init(&hwsim_radio_lock);
35473 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35474 index 35225e9..95e6bf9 100644
35475 --- a/drivers/net/wireless/mwifiex/main.h
35476 +++ b/drivers/net/wireless/mwifiex/main.h
35477 @@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35478 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35479 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35480 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35481 -};
35482 +} __no_const;
35483
35484 struct mwifiex_adapter {
35485 u8 iface_type;
35486 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35487 index d66e298..55b0a89 100644
35488 --- a/drivers/net/wireless/rndis_wlan.c
35489 +++ b/drivers/net/wireless/rndis_wlan.c
35490 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35491
35492 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35493
35494 - if (rts_threshold < 0 || rts_threshold > 2347)
35495 + if (rts_threshold > 2347)
35496 rts_threshold = 2347;
35497
35498 tmp = cpu_to_le32(rts_threshold);
35499 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35500 index c264dfa..08ee30e 100644
35501 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35502 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35503 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35504 * for hardware which doesn't support hardware
35505 * sequence counting.
35506 */
35507 - atomic_t seqno;
35508 + atomic_unchecked_t seqno;
35509 };
35510
35511 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35512 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35513 index 50f92d5..f3afc41 100644
35514 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35515 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35516 @@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35517 * sequence counter given by mac80211.
35518 */
35519 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35520 - seqno = atomic_add_return(0x10, &intf->seqno);
35521 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35522 else
35523 - seqno = atomic_read(&intf->seqno);
35524 + seqno = atomic_read_unchecked(&intf->seqno);
35525
35526 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35527 hdr->seq_ctrl |= cpu_to_le16(seqno);
35528 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35529 index 9d8f581..0f6589e 100644
35530 --- a/drivers/net/wireless/wl1251/wl1251.h
35531 +++ b/drivers/net/wireless/wl1251/wl1251.h
35532 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35533 void (*reset)(struct wl1251 *wl);
35534 void (*enable_irq)(struct wl1251 *wl);
35535 void (*disable_irq)(struct wl1251 *wl);
35536 -};
35537 +} __no_const;
35538
35539 struct wl1251 {
35540 struct ieee80211_hw *hw;
35541 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35542 index f34b5b2..b5abb9f 100644
35543 --- a/drivers/oprofile/buffer_sync.c
35544 +++ b/drivers/oprofile/buffer_sync.c
35545 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35546 if (cookie == NO_COOKIE)
35547 offset = pc;
35548 if (cookie == INVALID_COOKIE) {
35549 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35550 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35551 offset = pc;
35552 }
35553 if (cookie != last_cookie) {
35554 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35555 /* add userspace sample */
35556
35557 if (!mm) {
35558 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35559 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35560 return 0;
35561 }
35562
35563 cookie = lookup_dcookie(mm, s->eip, &offset);
35564
35565 if (cookie == INVALID_COOKIE) {
35566 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35567 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35568 return 0;
35569 }
35570
35571 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35572 /* ignore backtraces if failed to add a sample */
35573 if (state == sb_bt_start) {
35574 state = sb_bt_ignore;
35575 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35576 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35577 }
35578 }
35579 release_mm(mm);
35580 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35581 index c0cc4e7..44d4e54 100644
35582 --- a/drivers/oprofile/event_buffer.c
35583 +++ b/drivers/oprofile/event_buffer.c
35584 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35585 }
35586
35587 if (buffer_pos == buffer_size) {
35588 - atomic_inc(&oprofile_stats.event_lost_overflow);
35589 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35590 return;
35591 }
35592
35593 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35594 index ed2c3ec..deda85a 100644
35595 --- a/drivers/oprofile/oprof.c
35596 +++ b/drivers/oprofile/oprof.c
35597 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35598 if (oprofile_ops.switch_events())
35599 return;
35600
35601 - atomic_inc(&oprofile_stats.multiplex_counter);
35602 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35603 start_switch_worker();
35604 }
35605
35606 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35607 index 917d28e..d62d981 100644
35608 --- a/drivers/oprofile/oprofile_stats.c
35609 +++ b/drivers/oprofile/oprofile_stats.c
35610 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35611 cpu_buf->sample_invalid_eip = 0;
35612 }
35613
35614 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35615 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35616 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35617 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35618 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35619 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35620 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35621 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35622 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35623 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35624 }
35625
35626
35627 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35628 index 38b6fc0..b5cbfce 100644
35629 --- a/drivers/oprofile/oprofile_stats.h
35630 +++ b/drivers/oprofile/oprofile_stats.h
35631 @@ -13,11 +13,11 @@
35632 #include <linux/atomic.h>
35633
35634 struct oprofile_stat_struct {
35635 - atomic_t sample_lost_no_mm;
35636 - atomic_t sample_lost_no_mapping;
35637 - atomic_t bt_lost_no_mapping;
35638 - atomic_t event_lost_overflow;
35639 - atomic_t multiplex_counter;
35640 + atomic_unchecked_t sample_lost_no_mm;
35641 + atomic_unchecked_t sample_lost_no_mapping;
35642 + atomic_unchecked_t bt_lost_no_mapping;
35643 + atomic_unchecked_t event_lost_overflow;
35644 + atomic_unchecked_t multiplex_counter;
35645 };
35646
35647 extern struct oprofile_stat_struct oprofile_stats;
35648 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35649 index 849357c..b83c1e0 100644
35650 --- a/drivers/oprofile/oprofilefs.c
35651 +++ b/drivers/oprofile/oprofilefs.c
35652 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35653
35654
35655 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35656 - char const *name, atomic_t *val)
35657 + char const *name, atomic_unchecked_t *val)
35658 {
35659 return __oprofilefs_create_file(sb, root, name,
35660 &atomic_ro_fops, 0444, val);
35661 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35662 index 3f56bc0..707d642 100644
35663 --- a/drivers/parport/procfs.c
35664 +++ b/drivers/parport/procfs.c
35665 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35666
35667 *ppos += len;
35668
35669 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35670 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35671 }
35672
35673 #ifdef CONFIG_PARPORT_1284
35674 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35675
35676 *ppos += len;
35677
35678 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35679 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35680 }
35681 #endif /* IEEE1284.3 support. */
35682
35683 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35684 index 9fff878..ad0ad53 100644
35685 --- a/drivers/pci/hotplug/cpci_hotplug.h
35686 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35687 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35688 int (*hardware_test) (struct slot* slot, u32 value);
35689 u8 (*get_power) (struct slot* slot);
35690 int (*set_power) (struct slot* slot, int value);
35691 -};
35692 +} __no_const;
35693
35694 struct cpci_hp_controller {
35695 unsigned int irq;
35696 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35697 index 76ba8a1..20ca857 100644
35698 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35699 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35700 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35701
35702 void compaq_nvram_init (void __iomem *rom_start)
35703 {
35704 +
35705 +#ifndef CONFIG_PAX_KERNEXEC
35706 if (rom_start) {
35707 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35708 }
35709 +#endif
35710 +
35711 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35712
35713 /* initialize our int15 lock */
35714 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35715 index b500840..d7159d3 100644
35716 --- a/drivers/pci/pcie/aspm.c
35717 +++ b/drivers/pci/pcie/aspm.c
35718 @@ -27,9 +27,9 @@
35719 #define MODULE_PARAM_PREFIX "pcie_aspm."
35720
35721 /* Note: those are not register definitions */
35722 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35723 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35724 -#define ASPM_STATE_L1 (4) /* L1 state */
35725 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35726 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35727 +#define ASPM_STATE_L1 (4U) /* L1 state */
35728 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35729 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35730
35731 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35732 index 5e1ca3c..08082fe 100644
35733 --- a/drivers/pci/probe.c
35734 +++ b/drivers/pci/probe.c
35735 @@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35736 u16 orig_cmd;
35737 struct pci_bus_region region;
35738
35739 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35740 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35741
35742 if (!dev->mmio_always_on) {
35743 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35744 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35745 index 27911b5..5b6db88 100644
35746 --- a/drivers/pci/proc.c
35747 +++ b/drivers/pci/proc.c
35748 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35749 static int __init pci_proc_init(void)
35750 {
35751 struct pci_dev *dev = NULL;
35752 +
35753 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35754 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35755 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35756 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35757 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35758 +#endif
35759 +#else
35760 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35761 +#endif
35762 proc_create("devices", 0, proc_bus_pci_dir,
35763 &proc_bus_pci_dev_operations);
35764 proc_initialized = 1;
35765 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35766 index d68c000..f6094ca 100644
35767 --- a/drivers/platform/x86/thinkpad_acpi.c
35768 +++ b/drivers/platform/x86/thinkpad_acpi.c
35769 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35770 return 0;
35771 }
35772
35773 -void static hotkey_mask_warn_incomplete_mask(void)
35774 +static void hotkey_mask_warn_incomplete_mask(void)
35775 {
35776 /* log only what the user can fix... */
35777 const u32 wantedmask = hotkey_driver_mask &
35778 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35779 }
35780 }
35781
35782 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35783 - struct tp_nvram_state *newn,
35784 - const u32 event_mask)
35785 -{
35786 -
35787 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35788 do { \
35789 if ((event_mask & (1 << __scancode)) && \
35790 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35791 tpacpi_hotkey_send_key(__scancode); \
35792 } while (0)
35793
35794 - void issue_volchange(const unsigned int oldvol,
35795 - const unsigned int newvol)
35796 - {
35797 - unsigned int i = oldvol;
35798 +static void issue_volchange(const unsigned int oldvol,
35799 + const unsigned int newvol,
35800 + const u32 event_mask)
35801 +{
35802 + unsigned int i = oldvol;
35803
35804 - while (i > newvol) {
35805 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35806 - i--;
35807 - }
35808 - while (i < newvol) {
35809 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35810 - i++;
35811 - }
35812 + while (i > newvol) {
35813 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35814 + i--;
35815 }
35816 + while (i < newvol) {
35817 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35818 + i++;
35819 + }
35820 +}
35821
35822 - void issue_brightnesschange(const unsigned int oldbrt,
35823 - const unsigned int newbrt)
35824 - {
35825 - unsigned int i = oldbrt;
35826 +static void issue_brightnesschange(const unsigned int oldbrt,
35827 + const unsigned int newbrt,
35828 + const u32 event_mask)
35829 +{
35830 + unsigned int i = oldbrt;
35831
35832 - while (i > newbrt) {
35833 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35834 - i--;
35835 - }
35836 - while (i < newbrt) {
35837 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35838 - i++;
35839 - }
35840 + while (i > newbrt) {
35841 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35842 + i--;
35843 + }
35844 + while (i < newbrt) {
35845 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35846 + i++;
35847 }
35848 +}
35849
35850 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35851 + struct tp_nvram_state *newn,
35852 + const u32 event_mask)
35853 +{
35854 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35855 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35856 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35857 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35858 oldn->volume_level != newn->volume_level) {
35859 /* recently muted, or repeated mute keypress, or
35860 * multiple presses ending in mute */
35861 - issue_volchange(oldn->volume_level, newn->volume_level);
35862 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35863 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35864 }
35865 } else {
35866 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35867 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35868 }
35869 if (oldn->volume_level != newn->volume_level) {
35870 - issue_volchange(oldn->volume_level, newn->volume_level);
35871 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35872 } else if (oldn->volume_toggle != newn->volume_toggle) {
35873 /* repeated vol up/down keypress at end of scale ? */
35874 if (newn->volume_level == 0)
35875 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35876 /* handle brightness */
35877 if (oldn->brightness_level != newn->brightness_level) {
35878 issue_brightnesschange(oldn->brightness_level,
35879 - newn->brightness_level);
35880 + newn->brightness_level,
35881 + event_mask);
35882 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35883 /* repeated key presses that didn't change state */
35884 if (newn->brightness_level == 0)
35885 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35886 && !tp_features.bright_unkfw)
35887 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35888 }
35889 +}
35890
35891 #undef TPACPI_COMPARE_KEY
35892 #undef TPACPI_MAY_SEND_KEY
35893 -}
35894
35895 /*
35896 * Polling driver
35897 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35898 index 769d265..a3a05ca 100644
35899 --- a/drivers/pnp/pnpbios/bioscalls.c
35900 +++ b/drivers/pnp/pnpbios/bioscalls.c
35901 @@ -58,7 +58,7 @@ do { \
35902 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35903 } while(0)
35904
35905 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35906 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35907 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35908
35909 /*
35910 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35911
35912 cpu = get_cpu();
35913 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35914 +
35915 + pax_open_kernel();
35916 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35917 + pax_close_kernel();
35918
35919 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35920 spin_lock_irqsave(&pnp_bios_lock, flags);
35921 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35922 :"memory");
35923 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35924
35925 + pax_open_kernel();
35926 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35927 + pax_close_kernel();
35928 +
35929 put_cpu();
35930
35931 /* If we get here and this is set then the PnP BIOS faulted on us. */
35932 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35933 return status;
35934 }
35935
35936 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35937 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35938 {
35939 int i;
35940
35941 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35942 pnp_bios_callpoint.offset = header->fields.pm16offset;
35943 pnp_bios_callpoint.segment = PNP_CS16;
35944
35945 + pax_open_kernel();
35946 +
35947 for_each_possible_cpu(i) {
35948 struct desc_struct *gdt = get_cpu_gdt_table(i);
35949 if (!gdt)
35950 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35951 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35952 (unsigned long)__va(header->fields.pm16dseg));
35953 }
35954 +
35955 + pax_close_kernel();
35956 }
35957 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35958 index b0ecacb..7c9da2e 100644
35959 --- a/drivers/pnp/resource.c
35960 +++ b/drivers/pnp/resource.c
35961 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35962 return 1;
35963
35964 /* check if the resource is valid */
35965 - if (*irq < 0 || *irq > 15)
35966 + if (*irq > 15)
35967 return 0;
35968
35969 /* check if the resource is reserved */
35970 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35971 return 1;
35972
35973 /* check if the resource is valid */
35974 - if (*dma < 0 || *dma == 4 || *dma > 7)
35975 + if (*dma == 4 || *dma > 7)
35976 return 0;
35977
35978 /* check if the resource is reserved */
35979 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35980 index 222ccd8..6275fa5 100644
35981 --- a/drivers/power/bq27x00_battery.c
35982 +++ b/drivers/power/bq27x00_battery.c
35983 @@ -72,7 +72,7 @@
35984 struct bq27x00_device_info;
35985 struct bq27x00_access_methods {
35986 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35987 -};
35988 +} __no_const;
35989
35990 enum bq27x00_chip { BQ27000, BQ27500 };
35991
35992 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35993 index 4c5b053..104263e 100644
35994 --- a/drivers/regulator/max8660.c
35995 +++ b/drivers/regulator/max8660.c
35996 @@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35997 max8660->shadow_regs[MAX8660_OVER1] = 5;
35998 } else {
35999 /* Otherwise devices can be toggled via software */
36000 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36001 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36002 + pax_open_kernel();
36003 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36004 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36005 + pax_close_kernel();
36006 }
36007
36008 /*
36009 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36010 index 845aa22..99ec402 100644
36011 --- a/drivers/regulator/mc13892-regulator.c
36012 +++ b/drivers/regulator/mc13892-regulator.c
36013 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36014 }
36015 mc13xxx_unlock(mc13892);
36016
36017 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36018 + pax_open_kernel();
36019 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36020 = mc13892_vcam_set_mode;
36021 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36022 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36023 = mc13892_vcam_get_mode;
36024 + pax_close_kernel();
36025
36026 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36027 ARRAY_SIZE(mc13892_regulators));
36028 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36029 index cace6d3..f623fda 100644
36030 --- a/drivers/rtc/rtc-dev.c
36031 +++ b/drivers/rtc/rtc-dev.c
36032 @@ -14,6 +14,7 @@
36033 #include <linux/module.h>
36034 #include <linux/rtc.h>
36035 #include <linux/sched.h>
36036 +#include <linux/grsecurity.h>
36037 #include "rtc-core.h"
36038
36039 static dev_t rtc_devt;
36040 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36041 if (copy_from_user(&tm, uarg, sizeof(tm)))
36042 return -EFAULT;
36043
36044 + gr_log_timechange();
36045 +
36046 return rtc_set_time(rtc, &tm);
36047
36048 case RTC_PIE_ON:
36049 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36050 index 3fcf627..f334910 100644
36051 --- a/drivers/scsi/aacraid/aacraid.h
36052 +++ b/drivers/scsi/aacraid/aacraid.h
36053 @@ -492,7 +492,7 @@ struct adapter_ops
36054 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36055 /* Administrative operations */
36056 int (*adapter_comm)(struct aac_dev * dev, int comm);
36057 -};
36058 +} __no_const;
36059
36060 /*
36061 * Define which interrupt handler needs to be installed
36062 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36063 index 0d279c44..3d25a97 100644
36064 --- a/drivers/scsi/aacraid/linit.c
36065 +++ b/drivers/scsi/aacraid/linit.c
36066 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36067 #elif defined(__devinitconst)
36068 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36069 #else
36070 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36071 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36072 #endif
36073 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36074 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36075 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36076 index ff80552..1c4120c 100644
36077 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36078 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36079 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36080 .lldd_ata_set_dmamode = asd_set_dmamode,
36081 };
36082
36083 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36084 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36085 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36086 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36087 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36088 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36089 index 4ad7e36..d004679 100644
36090 --- a/drivers/scsi/bfa/bfa.h
36091 +++ b/drivers/scsi/bfa/bfa.h
36092 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36093 u32 *end);
36094 int cpe_vec_q0;
36095 int rme_vec_q0;
36096 -};
36097 +} __no_const;
36098 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36099
36100 struct bfa_faa_cbfn_s {
36101 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36102 index f0f80e2..8ec946b 100644
36103 --- a/drivers/scsi/bfa/bfa_fcpim.c
36104 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36105 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36106
36107 bfa_iotag_attach(fcp);
36108
36109 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36110 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36111 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36112 (fcp->num_itns * sizeof(struct bfa_itn_s));
36113 memset(fcp->itn_arr, 0,
36114 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36115 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36116 {
36117 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36118 - struct bfa_itn_s *itn;
36119 + bfa_itn_s_no_const *itn;
36120
36121 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36122 itn->isr = isr;
36123 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36124 index 36f26da..38a34a8 100644
36125 --- a/drivers/scsi/bfa/bfa_fcpim.h
36126 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36127 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36128 struct bfa_itn_s {
36129 bfa_isr_func_t isr;
36130 };
36131 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36132
36133 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36134 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36135 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36136 struct list_head iotag_tio_free_q; /* free IO resources */
36137 struct list_head iotag_unused_q; /* unused IO resources*/
36138 struct bfa_iotag_s *iotag_arr;
36139 - struct bfa_itn_s *itn_arr;
36140 + bfa_itn_s_no_const *itn_arr;
36141 int num_ioim_reqs;
36142 int num_fwtio_reqs;
36143 int num_itns;
36144 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36145 index 1a99d4b..e85d64b 100644
36146 --- a/drivers/scsi/bfa/bfa_ioc.h
36147 +++ b/drivers/scsi/bfa/bfa_ioc.h
36148 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36149 bfa_ioc_disable_cbfn_t disable_cbfn;
36150 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36151 bfa_ioc_reset_cbfn_t reset_cbfn;
36152 -};
36153 +} __no_const;
36154
36155 /*
36156 * IOC event notification mechanism.
36157 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36158 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36159 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36160 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36161 -};
36162 +} __no_const;
36163
36164 /*
36165 * Queue element to wait for room in request queue. FIFO order is
36166 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36167 index a3a056a..b9bbc2f 100644
36168 --- a/drivers/scsi/hosts.c
36169 +++ b/drivers/scsi/hosts.c
36170 @@ -42,7 +42,7 @@
36171 #include "scsi_logging.h"
36172
36173
36174 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36175 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36176
36177
36178 static void scsi_host_cls_release(struct device *dev)
36179 @@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36180 * subtract one because we increment first then return, but we need to
36181 * know what the next host number was before increment
36182 */
36183 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36184 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36185 shost->dma_channel = 0xff;
36186
36187 /* These three are default values which can be overridden */
36188 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36189 index 500e20d..ebd3059 100644
36190 --- a/drivers/scsi/hpsa.c
36191 +++ b/drivers/scsi/hpsa.c
36192 @@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36193 u32 a;
36194
36195 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36196 - return h->access.command_completed(h);
36197 + return h->access->command_completed(h);
36198
36199 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36200 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36201 @@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36202 while (!list_empty(&h->reqQ)) {
36203 c = list_entry(h->reqQ.next, struct CommandList, list);
36204 /* can't do anything if fifo is full */
36205 - if ((h->access.fifo_full(h))) {
36206 + if ((h->access->fifo_full(h))) {
36207 dev_warn(&h->pdev->dev, "fifo full\n");
36208 break;
36209 }
36210 @@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36211 h->Qdepth--;
36212
36213 /* Tell the controller execute command */
36214 - h->access.submit_command(h, c);
36215 + h->access->submit_command(h, c);
36216
36217 /* Put job onto the completed Q */
36218 addQ(&h->cmpQ, c);
36219 @@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36220
36221 static inline unsigned long get_next_completion(struct ctlr_info *h)
36222 {
36223 - return h->access.command_completed(h);
36224 + return h->access->command_completed(h);
36225 }
36226
36227 static inline bool interrupt_pending(struct ctlr_info *h)
36228 {
36229 - return h->access.intr_pending(h);
36230 + return h->access->intr_pending(h);
36231 }
36232
36233 static inline long interrupt_not_for_us(struct ctlr_info *h)
36234 {
36235 - return (h->access.intr_pending(h) == 0) ||
36236 + return (h->access->intr_pending(h) == 0) ||
36237 (h->interrupts_enabled == 0);
36238 }
36239
36240 @@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36241 if (prod_index < 0)
36242 return -ENODEV;
36243 h->product_name = products[prod_index].product_name;
36244 - h->access = *(products[prod_index].access);
36245 + h->access = products[prod_index].access;
36246
36247 if (hpsa_board_disabled(h->pdev)) {
36248 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36249 @@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36250
36251 assert_spin_locked(&lockup_detector_lock);
36252 remove_ctlr_from_lockup_detector_list(h);
36253 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36254 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36255 spin_lock_irqsave(&h->lock, flags);
36256 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36257 spin_unlock_irqrestore(&h->lock, flags);
36258 @@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36259 }
36260
36261 /* make sure the board interrupts are off */
36262 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36263 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36264
36265 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36266 goto clean2;
36267 @@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36268 * fake ones to scoop up any residual completions.
36269 */
36270 spin_lock_irqsave(&h->lock, flags);
36271 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36272 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36273 spin_unlock_irqrestore(&h->lock, flags);
36274 free_irq(h->intr[h->intr_mode], h);
36275 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36276 @@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36277 dev_info(&h->pdev->dev, "Board READY.\n");
36278 dev_info(&h->pdev->dev,
36279 "Waiting for stale completions to drain.\n");
36280 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36281 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36282 msleep(10000);
36283 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36284 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36285
36286 rc = controller_reset_failed(h->cfgtable);
36287 if (rc)
36288 @@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36289 }
36290
36291 /* Turn the interrupts on so we can service requests */
36292 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36293 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36294
36295 hpsa_hba_inquiry(h);
36296 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36297 @@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36298 * To write all data in the battery backed cache to disks
36299 */
36300 hpsa_flush_cache(h);
36301 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36302 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36303 free_irq(h->intr[h->intr_mode], h);
36304 #ifdef CONFIG_PCI_MSI
36305 if (h->msix_vector)
36306 @@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36307 return;
36308 }
36309 /* Change the access methods to the performant access methods */
36310 - h->access = SA5_performant_access;
36311 + h->access = &SA5_performant_access;
36312 h->transMethod = CFGTBL_Trans_Performant;
36313 }
36314
36315 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36316 index 7b28d54..952f23a 100644
36317 --- a/drivers/scsi/hpsa.h
36318 +++ b/drivers/scsi/hpsa.h
36319 @@ -72,7 +72,7 @@ struct ctlr_info {
36320 unsigned int msix_vector;
36321 unsigned int msi_vector;
36322 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36323 - struct access_method access;
36324 + struct access_method *access;
36325
36326 /* queue and queue Info */
36327 struct list_head reqQ;
36328 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36329 index f2df059..a3a9930 100644
36330 --- a/drivers/scsi/ips.h
36331 +++ b/drivers/scsi/ips.h
36332 @@ -1027,7 +1027,7 @@ typedef struct {
36333 int (*intr)(struct ips_ha *);
36334 void (*enableint)(struct ips_ha *);
36335 uint32_t (*statupd)(struct ips_ha *);
36336 -} ips_hw_func_t;
36337 +} __no_const ips_hw_func_t;
36338
36339 typedef struct ips_ha {
36340 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36341 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36342 index aceffad..c35c08d 100644
36343 --- a/drivers/scsi/libfc/fc_exch.c
36344 +++ b/drivers/scsi/libfc/fc_exch.c
36345 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36346 * all together if not used XXX
36347 */
36348 struct {
36349 - atomic_t no_free_exch;
36350 - atomic_t no_free_exch_xid;
36351 - atomic_t xid_not_found;
36352 - atomic_t xid_busy;
36353 - atomic_t seq_not_found;
36354 - atomic_t non_bls_resp;
36355 + atomic_unchecked_t no_free_exch;
36356 + atomic_unchecked_t no_free_exch_xid;
36357 + atomic_unchecked_t xid_not_found;
36358 + atomic_unchecked_t xid_busy;
36359 + atomic_unchecked_t seq_not_found;
36360 + atomic_unchecked_t non_bls_resp;
36361 } stats;
36362 };
36363
36364 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36365 /* allocate memory for exchange */
36366 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36367 if (!ep) {
36368 - atomic_inc(&mp->stats.no_free_exch);
36369 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36370 goto out;
36371 }
36372 memset(ep, 0, sizeof(*ep));
36373 @@ -780,7 +780,7 @@ out:
36374 return ep;
36375 err:
36376 spin_unlock_bh(&pool->lock);
36377 - atomic_inc(&mp->stats.no_free_exch_xid);
36378 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36379 mempool_free(ep, mp->ep_pool);
36380 return NULL;
36381 }
36382 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36383 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36384 ep = fc_exch_find(mp, xid);
36385 if (!ep) {
36386 - atomic_inc(&mp->stats.xid_not_found);
36387 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36388 reject = FC_RJT_OX_ID;
36389 goto out;
36390 }
36391 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36392 ep = fc_exch_find(mp, xid);
36393 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36394 if (ep) {
36395 - atomic_inc(&mp->stats.xid_busy);
36396 + atomic_inc_unchecked(&mp->stats.xid_busy);
36397 reject = FC_RJT_RX_ID;
36398 goto rel;
36399 }
36400 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36401 }
36402 xid = ep->xid; /* get our XID */
36403 } else if (!ep) {
36404 - atomic_inc(&mp->stats.xid_not_found);
36405 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36406 reject = FC_RJT_RX_ID; /* XID not found */
36407 goto out;
36408 }
36409 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36410 } else {
36411 sp = &ep->seq;
36412 if (sp->id != fh->fh_seq_id) {
36413 - atomic_inc(&mp->stats.seq_not_found);
36414 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36415 if (f_ctl & FC_FC_END_SEQ) {
36416 /*
36417 * Update sequence_id based on incoming last
36418 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36419
36420 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36421 if (!ep) {
36422 - atomic_inc(&mp->stats.xid_not_found);
36423 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36424 goto out;
36425 }
36426 if (ep->esb_stat & ESB_ST_COMPLETE) {
36427 - atomic_inc(&mp->stats.xid_not_found);
36428 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36429 goto rel;
36430 }
36431 if (ep->rxid == FC_XID_UNKNOWN)
36432 ep->rxid = ntohs(fh->fh_rx_id);
36433 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36434 - atomic_inc(&mp->stats.xid_not_found);
36435 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36436 goto rel;
36437 }
36438 if (ep->did != ntoh24(fh->fh_s_id) &&
36439 ep->did != FC_FID_FLOGI) {
36440 - atomic_inc(&mp->stats.xid_not_found);
36441 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36442 goto rel;
36443 }
36444 sof = fr_sof(fp);
36445 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36446 sp->ssb_stat |= SSB_ST_RESP;
36447 sp->id = fh->fh_seq_id;
36448 } else if (sp->id != fh->fh_seq_id) {
36449 - atomic_inc(&mp->stats.seq_not_found);
36450 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36451 goto rel;
36452 }
36453
36454 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36455 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36456
36457 if (!sp)
36458 - atomic_inc(&mp->stats.xid_not_found);
36459 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36460 else
36461 - atomic_inc(&mp->stats.non_bls_resp);
36462 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36463
36464 fc_frame_free(fp);
36465 }
36466 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36467 index d109cc3..09f4e7d 100644
36468 --- a/drivers/scsi/libsas/sas_ata.c
36469 +++ b/drivers/scsi/libsas/sas_ata.c
36470 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36471 .postreset = ata_std_postreset,
36472 .error_handler = ata_std_error_handler,
36473 .post_internal_cmd = sas_ata_post_internal,
36474 - .qc_defer = ata_std_qc_defer,
36475 + .qc_defer = ata_std_qc_defer,
36476 .qc_prep = ata_noop_qc_prep,
36477 .qc_issue = sas_ata_qc_issue,
36478 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36479 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36480 index 3a1ffdd..8eb7c71 100644
36481 --- a/drivers/scsi/lpfc/lpfc.h
36482 +++ b/drivers/scsi/lpfc/lpfc.h
36483 @@ -413,7 +413,7 @@ struct lpfc_vport {
36484 struct dentry *debug_nodelist;
36485 struct dentry *vport_debugfs_root;
36486 struct lpfc_debugfs_trc *disc_trc;
36487 - atomic_t disc_trc_cnt;
36488 + atomic_unchecked_t disc_trc_cnt;
36489 #endif
36490 uint8_t stat_data_enabled;
36491 uint8_t stat_data_blocked;
36492 @@ -826,8 +826,8 @@ struct lpfc_hba {
36493 struct timer_list fabric_block_timer;
36494 unsigned long bit_flags;
36495 #define FABRIC_COMANDS_BLOCKED 0
36496 - atomic_t num_rsrc_err;
36497 - atomic_t num_cmd_success;
36498 + atomic_unchecked_t num_rsrc_err;
36499 + atomic_unchecked_t num_cmd_success;
36500 unsigned long last_rsrc_error_time;
36501 unsigned long last_ramp_down_time;
36502 unsigned long last_ramp_up_time;
36503 @@ -863,7 +863,7 @@ struct lpfc_hba {
36504
36505 struct dentry *debug_slow_ring_trc;
36506 struct lpfc_debugfs_trc *slow_ring_trc;
36507 - atomic_t slow_ring_trc_cnt;
36508 + atomic_unchecked_t slow_ring_trc_cnt;
36509 /* iDiag debugfs sub-directory */
36510 struct dentry *idiag_root;
36511 struct dentry *idiag_pci_cfg;
36512 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36513 index af04b0d..8f1a97e 100644
36514 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36515 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36516 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36517
36518 #include <linux/debugfs.h>
36519
36520 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36521 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36522 static unsigned long lpfc_debugfs_start_time = 0L;
36523
36524 /* iDiag */
36525 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36526 lpfc_debugfs_enable = 0;
36527
36528 len = 0;
36529 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36530 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36531 (lpfc_debugfs_max_disc_trc - 1);
36532 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36533 dtp = vport->disc_trc + i;
36534 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36535 lpfc_debugfs_enable = 0;
36536
36537 len = 0;
36538 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36539 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36540 (lpfc_debugfs_max_slow_ring_trc - 1);
36541 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36542 dtp = phba->slow_ring_trc + i;
36543 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36544 !vport || !vport->disc_trc)
36545 return;
36546
36547 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36548 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36549 (lpfc_debugfs_max_disc_trc - 1);
36550 dtp = vport->disc_trc + index;
36551 dtp->fmt = fmt;
36552 dtp->data1 = data1;
36553 dtp->data2 = data2;
36554 dtp->data3 = data3;
36555 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36556 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36557 dtp->jif = jiffies;
36558 #endif
36559 return;
36560 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36561 !phba || !phba->slow_ring_trc)
36562 return;
36563
36564 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36565 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36566 (lpfc_debugfs_max_slow_ring_trc - 1);
36567 dtp = phba->slow_ring_trc + index;
36568 dtp->fmt = fmt;
36569 dtp->data1 = data1;
36570 dtp->data2 = data2;
36571 dtp->data3 = data3;
36572 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36573 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36574 dtp->jif = jiffies;
36575 #endif
36576 return;
36577 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36578 "slow_ring buffer\n");
36579 goto debug_failed;
36580 }
36581 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36582 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36583 memset(phba->slow_ring_trc, 0,
36584 (sizeof(struct lpfc_debugfs_trc) *
36585 lpfc_debugfs_max_slow_ring_trc));
36586 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36587 "buffer\n");
36588 goto debug_failed;
36589 }
36590 - atomic_set(&vport->disc_trc_cnt, 0);
36591 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36592
36593 snprintf(name, sizeof(name), "discovery_trace");
36594 vport->debug_disc_trc =
36595 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36596 index 9598fdc..7e9f3d9 100644
36597 --- a/drivers/scsi/lpfc/lpfc_init.c
36598 +++ b/drivers/scsi/lpfc/lpfc_init.c
36599 @@ -10266,8 +10266,10 @@ lpfc_init(void)
36600 "misc_register returned with status %d", error);
36601
36602 if (lpfc_enable_npiv) {
36603 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36604 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36605 + pax_open_kernel();
36606 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36607 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36608 + pax_close_kernel();
36609 }
36610 lpfc_transport_template =
36611 fc_attach_transport(&lpfc_transport_functions);
36612 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36613 index 88f3a83..686d3fa 100644
36614 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36615 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36616 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36617 uint32_t evt_posted;
36618
36619 spin_lock_irqsave(&phba->hbalock, flags);
36620 - atomic_inc(&phba->num_rsrc_err);
36621 + atomic_inc_unchecked(&phba->num_rsrc_err);
36622 phba->last_rsrc_error_time = jiffies;
36623
36624 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36625 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36626 unsigned long flags;
36627 struct lpfc_hba *phba = vport->phba;
36628 uint32_t evt_posted;
36629 - atomic_inc(&phba->num_cmd_success);
36630 + atomic_inc_unchecked(&phba->num_cmd_success);
36631
36632 if (vport->cfg_lun_queue_depth <= queue_depth)
36633 return;
36634 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36635 unsigned long num_rsrc_err, num_cmd_success;
36636 int i;
36637
36638 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36639 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36640 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36641 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36642
36643 vports = lpfc_create_vport_work_array(phba);
36644 if (vports != NULL)
36645 @@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36646 }
36647 }
36648 lpfc_destroy_vport_work_array(phba, vports);
36649 - atomic_set(&phba->num_rsrc_err, 0);
36650 - atomic_set(&phba->num_cmd_success, 0);
36651 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36652 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36653 }
36654
36655 /**
36656 @@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36657 }
36658 }
36659 lpfc_destroy_vport_work_array(phba, vports);
36660 - atomic_set(&phba->num_rsrc_err, 0);
36661 - atomic_set(&phba->num_cmd_success, 0);
36662 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36663 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36664 }
36665
36666 /**
36667 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36668 index ea8a0b4..812a124 100644
36669 --- a/drivers/scsi/pmcraid.c
36670 +++ b/drivers/scsi/pmcraid.c
36671 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36672 res->scsi_dev = scsi_dev;
36673 scsi_dev->hostdata = res;
36674 res->change_detected = 0;
36675 - atomic_set(&res->read_failures, 0);
36676 - atomic_set(&res->write_failures, 0);
36677 + atomic_set_unchecked(&res->read_failures, 0);
36678 + atomic_set_unchecked(&res->write_failures, 0);
36679 rc = 0;
36680 }
36681 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36682 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36683
36684 /* If this was a SCSI read/write command keep count of errors */
36685 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36686 - atomic_inc(&res->read_failures);
36687 + atomic_inc_unchecked(&res->read_failures);
36688 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36689 - atomic_inc(&res->write_failures);
36690 + atomic_inc_unchecked(&res->write_failures);
36691
36692 if (!RES_IS_GSCSI(res->cfg_entry) &&
36693 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36694 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36695 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36696 * hrrq_id assigned here in queuecommand
36697 */
36698 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36699 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36700 pinstance->num_hrrq;
36701 cmd->cmd_done = pmcraid_io_done;
36702
36703 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36704 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36705 * hrrq_id assigned here in queuecommand
36706 */
36707 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36708 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36709 pinstance->num_hrrq;
36710
36711 if (request_size) {
36712 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36713
36714 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36715 /* add resources only after host is added into system */
36716 - if (!atomic_read(&pinstance->expose_resources))
36717 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36718 return;
36719
36720 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36721 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36722 init_waitqueue_head(&pinstance->reset_wait_q);
36723
36724 atomic_set(&pinstance->outstanding_cmds, 0);
36725 - atomic_set(&pinstance->last_message_id, 0);
36726 - atomic_set(&pinstance->expose_resources, 0);
36727 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36728 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36729
36730 INIT_LIST_HEAD(&pinstance->free_res_q);
36731 INIT_LIST_HEAD(&pinstance->used_res_q);
36732 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36733 /* Schedule worker thread to handle CCN and take care of adding and
36734 * removing devices to OS
36735 */
36736 - atomic_set(&pinstance->expose_resources, 1);
36737 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36738 schedule_work(&pinstance->worker_q);
36739 return rc;
36740
36741 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36742 index e1d150f..6c6df44 100644
36743 --- a/drivers/scsi/pmcraid.h
36744 +++ b/drivers/scsi/pmcraid.h
36745 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36746 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36747
36748 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36749 - atomic_t last_message_id;
36750 + atomic_unchecked_t last_message_id;
36751
36752 /* configuration table */
36753 struct pmcraid_config_table *cfg_table;
36754 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36755 atomic_t outstanding_cmds;
36756
36757 /* should add/delete resources to mid-layer now ?*/
36758 - atomic_t expose_resources;
36759 + atomic_unchecked_t expose_resources;
36760
36761
36762
36763 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36764 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36765 };
36766 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36767 - atomic_t read_failures; /* count of failed READ commands */
36768 - atomic_t write_failures; /* count of failed WRITE commands */
36769 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36770 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36771
36772 /* To indicate add/delete/modify during CCN */
36773 u8 change_detected;
36774 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36775 index a244303..6015eb7 100644
36776 --- a/drivers/scsi/qla2xxx/qla_def.h
36777 +++ b/drivers/scsi/qla2xxx/qla_def.h
36778 @@ -2264,7 +2264,7 @@ struct isp_operations {
36779 int (*start_scsi) (srb_t *);
36780 int (*abort_isp) (struct scsi_qla_host *);
36781 int (*iospace_config)(struct qla_hw_data*);
36782 -};
36783 +} __no_const;
36784
36785 /* MSI-X Support *************************************************************/
36786
36787 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36788 index 7f2492e..5113877 100644
36789 --- a/drivers/scsi/qla4xxx/ql4_def.h
36790 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36791 @@ -268,7 +268,7 @@ struct ddb_entry {
36792 * (4000 only) */
36793 atomic_t relogin_timer; /* Max Time to wait for
36794 * relogin to complete */
36795 - atomic_t relogin_retry_count; /* Num of times relogin has been
36796 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36797 * retried */
36798 uint32_t default_time2wait; /* Default Min time between
36799 * relogins (+aens) */
36800 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36801 index ee47820..a83b1f4 100644
36802 --- a/drivers/scsi/qla4xxx/ql4_os.c
36803 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36804 @@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36805 */
36806 if (!iscsi_is_session_online(cls_sess)) {
36807 /* Reset retry relogin timer */
36808 - atomic_inc(&ddb_entry->relogin_retry_count);
36809 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36810 DEBUG2(ql4_printk(KERN_INFO, ha,
36811 "%s: index[%d] relogin timed out-retrying"
36812 " relogin (%d), retry (%d)\n", __func__,
36813 ddb_entry->fw_ddb_index,
36814 - atomic_read(&ddb_entry->relogin_retry_count),
36815 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36816 ddb_entry->default_time2wait + 4));
36817 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36818 atomic_set(&ddb_entry->retry_relogin_timer,
36819 @@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36820
36821 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36822 atomic_set(&ddb_entry->relogin_timer, 0);
36823 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36824 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36825 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36826 ddb_entry->default_relogin_timeout =
36827 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36828 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36829 index 07322ec..91ccc23 100644
36830 --- a/drivers/scsi/scsi.c
36831 +++ b/drivers/scsi/scsi.c
36832 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36833 unsigned long timeout;
36834 int rtn = 0;
36835
36836 - atomic_inc(&cmd->device->iorequest_cnt);
36837 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36838
36839 /* check if the device is still usable */
36840 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36841 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36842 index 4037fd5..a19fcc7 100644
36843 --- a/drivers/scsi/scsi_lib.c
36844 +++ b/drivers/scsi/scsi_lib.c
36845 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36846 shost = sdev->host;
36847 scsi_init_cmd_errh(cmd);
36848 cmd->result = DID_NO_CONNECT << 16;
36849 - atomic_inc(&cmd->device->iorequest_cnt);
36850 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36851
36852 /*
36853 * SCSI request completion path will do scsi_device_unbusy(),
36854 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36855
36856 INIT_LIST_HEAD(&cmd->eh_entry);
36857
36858 - atomic_inc(&cmd->device->iodone_cnt);
36859 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36860 if (cmd->result)
36861 - atomic_inc(&cmd->device->ioerr_cnt);
36862 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36863
36864 disposition = scsi_decide_disposition(cmd);
36865 if (disposition != SUCCESS &&
36866 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36867 index 04c2a27..9d8bd66 100644
36868 --- a/drivers/scsi/scsi_sysfs.c
36869 +++ b/drivers/scsi/scsi_sysfs.c
36870 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36871 char *buf) \
36872 { \
36873 struct scsi_device *sdev = to_scsi_device(dev); \
36874 - unsigned long long count = atomic_read(&sdev->field); \
36875 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36876 return snprintf(buf, 20, "0x%llx\n", count); \
36877 } \
36878 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36879 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36880 index 84a1fdf..693b0d6 100644
36881 --- a/drivers/scsi/scsi_tgt_lib.c
36882 +++ b/drivers/scsi/scsi_tgt_lib.c
36883 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36884 int err;
36885
36886 dprintk("%lx %u\n", uaddr, len);
36887 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36888 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36889 if (err) {
36890 /*
36891 * TODO: need to fixup sg_tablesize, max_segment_size,
36892 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36893 index 80fbe2a..efa223b 100644
36894 --- a/drivers/scsi/scsi_transport_fc.c
36895 +++ b/drivers/scsi/scsi_transport_fc.c
36896 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36897 * Netlink Infrastructure
36898 */
36899
36900 -static atomic_t fc_event_seq;
36901 +static atomic_unchecked_t fc_event_seq;
36902
36903 /**
36904 * fc_get_event_number - Obtain the next sequential FC event number
36905 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36906 u32
36907 fc_get_event_number(void)
36908 {
36909 - return atomic_add_return(1, &fc_event_seq);
36910 + return atomic_add_return_unchecked(1, &fc_event_seq);
36911 }
36912 EXPORT_SYMBOL(fc_get_event_number);
36913
36914 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36915 {
36916 int error;
36917
36918 - atomic_set(&fc_event_seq, 0);
36919 + atomic_set_unchecked(&fc_event_seq, 0);
36920
36921 error = transport_class_register(&fc_host_class);
36922 if (error)
36923 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36924 char *cp;
36925
36926 *val = simple_strtoul(buf, &cp, 0);
36927 - if ((*cp && (*cp != '\n')) || (*val < 0))
36928 + if (*cp && (*cp != '\n'))
36929 return -EINVAL;
36930 /*
36931 * Check for overflow; dev_loss_tmo is u32
36932 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36933 index 1cf640e..78e9014 100644
36934 --- a/drivers/scsi/scsi_transport_iscsi.c
36935 +++ b/drivers/scsi/scsi_transport_iscsi.c
36936 @@ -79,7 +79,7 @@ struct iscsi_internal {
36937 struct transport_container session_cont;
36938 };
36939
36940 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36941 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36942 static struct workqueue_struct *iscsi_eh_timer_workq;
36943
36944 static DEFINE_IDA(iscsi_sess_ida);
36945 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36946 int err;
36947
36948 ihost = shost->shost_data;
36949 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36950 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36951
36952 if (target_id == ISCSI_MAX_TARGET) {
36953 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
36954 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
36955 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36956 ISCSI_TRANSPORT_VERSION);
36957
36958 - atomic_set(&iscsi_session_nr, 0);
36959 + atomic_set_unchecked(&iscsi_session_nr, 0);
36960
36961 err = class_register(&iscsi_transport_class);
36962 if (err)
36963 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36964 index 21a045e..ec89e03 100644
36965 --- a/drivers/scsi/scsi_transport_srp.c
36966 +++ b/drivers/scsi/scsi_transport_srp.c
36967 @@ -33,7 +33,7 @@
36968 #include "scsi_transport_srp_internal.h"
36969
36970 struct srp_host_attrs {
36971 - atomic_t next_port_id;
36972 + atomic_unchecked_t next_port_id;
36973 };
36974 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36975
36976 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36977 struct Scsi_Host *shost = dev_to_shost(dev);
36978 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36979
36980 - atomic_set(&srp_host->next_port_id, 0);
36981 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36982 return 0;
36983 }
36984
36985 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36986 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36987 rport->roles = ids->roles;
36988
36989 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36990 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36991 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36992
36993 transport_setup_device(&rport->dev);
36994 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36995 index eacd46b..e3f4d62 100644
36996 --- a/drivers/scsi/sg.c
36997 +++ b/drivers/scsi/sg.c
36998 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36999 sdp->disk->disk_name,
37000 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37001 NULL,
37002 - (char *)arg);
37003 + (char __user *)arg);
37004 case BLKTRACESTART:
37005 return blk_trace_startstop(sdp->device->request_queue, 1);
37006 case BLKTRACESTOP:
37007 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37008 const struct file_operations * fops;
37009 };
37010
37011 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37012 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37013 {"allow_dio", &adio_fops},
37014 {"debug", &debug_fops},
37015 {"def_reserved_size", &dressz_fops},
37016 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37017 if (!sg_proc_sgp)
37018 return 1;
37019 for (k = 0; k < num_leaves; ++k) {
37020 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37021 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37022 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37023 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37024 }
37025 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37026 index 3d8f662..070f1a5 100644
37027 --- a/drivers/spi/spi.c
37028 +++ b/drivers/spi/spi.c
37029 @@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37030 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37031
37032 /* portable code must never pass more than 32 bytes */
37033 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37034 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37035
37036 static u8 *buf;
37037
37038 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37039 index d91751f..a3a9e36 100644
37040 --- a/drivers/staging/octeon/ethernet-rx.c
37041 +++ b/drivers/staging/octeon/ethernet-rx.c
37042 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37043 /* Increment RX stats for virtual ports */
37044 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37045 #ifdef CONFIG_64BIT
37046 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37047 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37048 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37049 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37050 #else
37051 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37052 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37053 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37054 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37055 #endif
37056 }
37057 netif_receive_skb(skb);
37058 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37059 dev->name);
37060 */
37061 #ifdef CONFIG_64BIT
37062 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37063 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37064 #else
37065 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37066 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37067 #endif
37068 dev_kfree_skb_irq(skb);
37069 }
37070 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37071 index 60cba81..71eb239 100644
37072 --- a/drivers/staging/octeon/ethernet.c
37073 +++ b/drivers/staging/octeon/ethernet.c
37074 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37075 * since the RX tasklet also increments it.
37076 */
37077 #ifdef CONFIG_64BIT
37078 - atomic64_add(rx_status.dropped_packets,
37079 - (atomic64_t *)&priv->stats.rx_dropped);
37080 + atomic64_add_unchecked(rx_status.dropped_packets,
37081 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37082 #else
37083 - atomic_add(rx_status.dropped_packets,
37084 - (atomic_t *)&priv->stats.rx_dropped);
37085 + atomic_add_unchecked(rx_status.dropped_packets,
37086 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37087 #endif
37088 }
37089
37090 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37091 index d3d8727..f9327bb8 100644
37092 --- a/drivers/staging/rtl8712/rtl871x_io.h
37093 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37094 @@ -108,7 +108,7 @@ struct _io_ops {
37095 u8 *pmem);
37096 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37097 u8 *pmem);
37098 -};
37099 +} __no_const;
37100
37101 struct io_req {
37102 struct list_head list;
37103 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37104 index c7b5e8b..783d6cb 100644
37105 --- a/drivers/staging/sbe-2t3e3/netdev.c
37106 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37107 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37108 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37109
37110 if (rlen)
37111 - if (copy_to_user(data, &resp, rlen))
37112 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37113 return -EFAULT;
37114
37115 return 0;
37116 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37117 index 42cdafe..2769103 100644
37118 --- a/drivers/staging/speakup/speakup_soft.c
37119 +++ b/drivers/staging/speakup/speakup_soft.c
37120 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37121 break;
37122 } else if (!initialized) {
37123 if (*init) {
37124 - ch = *init;
37125 init++;
37126 } else {
37127 initialized = 1;
37128 }
37129 + ch = *init;
37130 } else {
37131 ch = synth_buffer_getc();
37132 }
37133 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37134 index c7b888c..c94be93 100644
37135 --- a/drivers/staging/usbip/usbip_common.h
37136 +++ b/drivers/staging/usbip/usbip_common.h
37137 @@ -289,7 +289,7 @@ struct usbip_device {
37138 void (*shutdown)(struct usbip_device *);
37139 void (*reset)(struct usbip_device *);
37140 void (*unusable)(struct usbip_device *);
37141 - } eh_ops;
37142 + } __no_const eh_ops;
37143 };
37144
37145 /* usbip_common.c */
37146 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37147 index 88b3298..3783eee 100644
37148 --- a/drivers/staging/usbip/vhci.h
37149 +++ b/drivers/staging/usbip/vhci.h
37150 @@ -88,7 +88,7 @@ struct vhci_hcd {
37151 unsigned resuming:1;
37152 unsigned long re_timeout;
37153
37154 - atomic_t seqnum;
37155 + atomic_unchecked_t seqnum;
37156
37157 /*
37158 * NOTE:
37159 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37160 index dca9bf1..80735c9 100644
37161 --- a/drivers/staging/usbip/vhci_hcd.c
37162 +++ b/drivers/staging/usbip/vhci_hcd.c
37163 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37164 return;
37165 }
37166
37167 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37168 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37169 if (priv->seqnum == 0xffff)
37170 dev_info(&urb->dev->dev, "seqnum max\n");
37171
37172 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37173 return -ENOMEM;
37174 }
37175
37176 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37177 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37178 if (unlink->seqnum == 0xffff)
37179 pr_info("seqnum max\n");
37180
37181 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37182 vdev->rhport = rhport;
37183 }
37184
37185 - atomic_set(&vhci->seqnum, 0);
37186 + atomic_set_unchecked(&vhci->seqnum, 0);
37187 spin_lock_init(&vhci->lock);
37188
37189 hcd->power_budget = 0; /* no limit */
37190 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37191 index f5fba732..210a16c 100644
37192 --- a/drivers/staging/usbip/vhci_rx.c
37193 +++ b/drivers/staging/usbip/vhci_rx.c
37194 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37195 if (!urb) {
37196 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37197 pr_info("max seqnum %d\n",
37198 - atomic_read(&the_controller->seqnum));
37199 + atomic_read_unchecked(&the_controller->seqnum));
37200 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37201 return;
37202 }
37203 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37204 index 7735027..30eed13 100644
37205 --- a/drivers/staging/vt6655/hostap.c
37206 +++ b/drivers/staging/vt6655/hostap.c
37207 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37208 *
37209 */
37210
37211 +static net_device_ops_no_const apdev_netdev_ops;
37212 +
37213 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37214 {
37215 PSDevice apdev_priv;
37216 struct net_device *dev = pDevice->dev;
37217 int ret;
37218 - const struct net_device_ops apdev_netdev_ops = {
37219 - .ndo_start_xmit = pDevice->tx_80211,
37220 - };
37221
37222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37223
37224 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37225 *apdev_priv = *pDevice;
37226 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37227
37228 + /* only half broken now */
37229 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37230 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37231
37232 pDevice->apdev->type = ARPHRD_IEEE80211;
37233 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37234 index 51b5adf..098e320 100644
37235 --- a/drivers/staging/vt6656/hostap.c
37236 +++ b/drivers/staging/vt6656/hostap.c
37237 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37238 *
37239 */
37240
37241 +static net_device_ops_no_const apdev_netdev_ops;
37242 +
37243 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37244 {
37245 PSDevice apdev_priv;
37246 struct net_device *dev = pDevice->dev;
37247 int ret;
37248 - const struct net_device_ops apdev_netdev_ops = {
37249 - .ndo_start_xmit = pDevice->tx_80211,
37250 - };
37251
37252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37253
37254 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37255 *apdev_priv = *pDevice;
37256 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37257
37258 + /* only half broken now */
37259 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37260 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37261
37262 pDevice->apdev->type = ARPHRD_IEEE80211;
37263 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37264 index 7843dfd..3db105f 100644
37265 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37266 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37267 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37268
37269 struct usbctlx_completor {
37270 int (*complete) (struct usbctlx_completor *);
37271 -};
37272 +} __no_const;
37273
37274 static int
37275 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37276 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37277 index 1ca66ea..76f1343 100644
37278 --- a/drivers/staging/zcache/tmem.c
37279 +++ b/drivers/staging/zcache/tmem.c
37280 @@ -39,7 +39,7 @@
37281 * A tmem host implementation must use this function to register callbacks
37282 * for memory allocation.
37283 */
37284 -static struct tmem_hostops tmem_hostops;
37285 +static tmem_hostops_no_const tmem_hostops;
37286
37287 static void tmem_objnode_tree_init(void);
37288
37289 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37290 * A tmem host implementation must use this function to register
37291 * callbacks for a page-accessible memory (PAM) implementation
37292 */
37293 -static struct tmem_pamops tmem_pamops;
37294 +static tmem_pamops_no_const tmem_pamops;
37295
37296 void tmem_register_pamops(struct tmem_pamops *m)
37297 {
37298 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37299 index 0d4aa82..f7832d4 100644
37300 --- a/drivers/staging/zcache/tmem.h
37301 +++ b/drivers/staging/zcache/tmem.h
37302 @@ -180,6 +180,7 @@ struct tmem_pamops {
37303 void (*new_obj)(struct tmem_obj *);
37304 int (*replace_in_obj)(void *, struct tmem_obj *);
37305 };
37306 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37307 extern void tmem_register_pamops(struct tmem_pamops *m);
37308
37309 /* memory allocation methods provided by the host implementation */
37310 @@ -189,6 +190,7 @@ struct tmem_hostops {
37311 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37312 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37313 };
37314 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37315 extern void tmem_register_hostops(struct tmem_hostops *m);
37316
37317 /* core tmem accessor functions */
37318 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37319 index f015839..b15dfc4 100644
37320 --- a/drivers/target/target_core_tmr.c
37321 +++ b/drivers/target/target_core_tmr.c
37322 @@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37323 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37324 cmd->t_task_list_num,
37325 atomic_read(&cmd->t_task_cdbs_left),
37326 - atomic_read(&cmd->t_task_cdbs_sent),
37327 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37328 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37329 (cmd->transport_state & CMD_T_STOP) != 0,
37330 (cmd->transport_state & CMD_T_SENT) != 0);
37331 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37332 index 443704f..92d3517 100644
37333 --- a/drivers/target/target_core_transport.c
37334 +++ b/drivers/target/target_core_transport.c
37335 @@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37336 spin_lock_init(&dev->se_port_lock);
37337 spin_lock_init(&dev->se_tmr_lock);
37338 spin_lock_init(&dev->qf_cmd_lock);
37339 - atomic_set(&dev->dev_ordered_id, 0);
37340 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37341
37342 se_dev_set_default_attribs(dev, dev_limits);
37343
37344 @@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37345 * Used to determine when ORDERED commands should go from
37346 * Dormant to Active status.
37347 */
37348 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37349 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37350 smp_mb__after_atomic_inc();
37351 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37352 cmd->se_ordered_id, cmd->sam_task_attr,
37353 @@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37354 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37355 cmd->t_task_list_num,
37356 atomic_read(&cmd->t_task_cdbs_left),
37357 - atomic_read(&cmd->t_task_cdbs_sent),
37358 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37359 atomic_read(&cmd->t_task_cdbs_ex_left),
37360 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37361 (cmd->transport_state & CMD_T_STOP) != 0,
37362 @@ -2216,9 +2216,9 @@ check_depth:
37363 cmd = task->task_se_cmd;
37364 spin_lock_irqsave(&cmd->t_state_lock, flags);
37365 task->task_flags |= (TF_ACTIVE | TF_SENT);
37366 - atomic_inc(&cmd->t_task_cdbs_sent);
37367 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37368
37369 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37370 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37371 cmd->t_task_list_num)
37372 cmd->transport_state |= CMD_T_SENT;
37373
37374 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37375 index 3436436..772237b 100644
37376 --- a/drivers/tty/hvc/hvcs.c
37377 +++ b/drivers/tty/hvc/hvcs.c
37378 @@ -83,6 +83,7 @@
37379 #include <asm/hvcserver.h>
37380 #include <asm/uaccess.h>
37381 #include <asm/vio.h>
37382 +#include <asm/local.h>
37383
37384 /*
37385 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37386 @@ -270,7 +271,7 @@ struct hvcs_struct {
37387 unsigned int index;
37388
37389 struct tty_struct *tty;
37390 - int open_count;
37391 + local_t open_count;
37392
37393 /*
37394 * Used to tell the driver kernel_thread what operations need to take
37395 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37396
37397 spin_lock_irqsave(&hvcsd->lock, flags);
37398
37399 - if (hvcsd->open_count > 0) {
37400 + if (local_read(&hvcsd->open_count) > 0) {
37401 spin_unlock_irqrestore(&hvcsd->lock, flags);
37402 printk(KERN_INFO "HVCS: vterm state unchanged. "
37403 "The hvcs device node is still in use.\n");
37404 @@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37405 if ((retval = hvcs_partner_connect(hvcsd)))
37406 goto error_release;
37407
37408 - hvcsd->open_count = 1;
37409 + local_set(&hvcsd->open_count, 1);
37410 hvcsd->tty = tty;
37411 tty->driver_data = hvcsd;
37412
37413 @@ -1172,7 +1173,7 @@ fast_open:
37414
37415 spin_lock_irqsave(&hvcsd->lock, flags);
37416 kref_get(&hvcsd->kref);
37417 - hvcsd->open_count++;
37418 + local_inc(&hvcsd->open_count);
37419 hvcsd->todo_mask |= HVCS_SCHED_READ;
37420 spin_unlock_irqrestore(&hvcsd->lock, flags);
37421
37422 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37423 hvcsd = tty->driver_data;
37424
37425 spin_lock_irqsave(&hvcsd->lock, flags);
37426 - if (--hvcsd->open_count == 0) {
37427 + if (local_dec_and_test(&hvcsd->open_count)) {
37428
37429 vio_disable_interrupts(hvcsd->vdev);
37430
37431 @@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37432 free_irq(irq, hvcsd);
37433 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37434 return;
37435 - } else if (hvcsd->open_count < 0) {
37436 + } else if (local_read(&hvcsd->open_count) < 0) {
37437 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37438 " is missmanaged.\n",
37439 - hvcsd->vdev->unit_address, hvcsd->open_count);
37440 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37441 }
37442
37443 spin_unlock_irqrestore(&hvcsd->lock, flags);
37444 @@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37445
37446 spin_lock_irqsave(&hvcsd->lock, flags);
37447 /* Preserve this so that we know how many kref refs to put */
37448 - temp_open_count = hvcsd->open_count;
37449 + temp_open_count = local_read(&hvcsd->open_count);
37450
37451 /*
37452 * Don't kref put inside the spinlock because the destruction
37453 @@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37454 hvcsd->tty->driver_data = NULL;
37455 hvcsd->tty = NULL;
37456
37457 - hvcsd->open_count = 0;
37458 + local_set(&hvcsd->open_count, 0);
37459
37460 /* This will drop any buffered data on the floor which is OK in a hangup
37461 * scenario. */
37462 @@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37463 * the middle of a write operation? This is a crummy place to do this
37464 * but we want to keep it all in the spinlock.
37465 */
37466 - if (hvcsd->open_count <= 0) {
37467 + if (local_read(&hvcsd->open_count) <= 0) {
37468 spin_unlock_irqrestore(&hvcsd->lock, flags);
37469 return -ENODEV;
37470 }
37471 @@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37472 {
37473 struct hvcs_struct *hvcsd = tty->driver_data;
37474
37475 - if (!hvcsd || hvcsd->open_count <= 0)
37476 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37477 return 0;
37478
37479 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37480 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37481 index 4daf962..b4a2281 100644
37482 --- a/drivers/tty/ipwireless/tty.c
37483 +++ b/drivers/tty/ipwireless/tty.c
37484 @@ -29,6 +29,7 @@
37485 #include <linux/tty_driver.h>
37486 #include <linux/tty_flip.h>
37487 #include <linux/uaccess.h>
37488 +#include <asm/local.h>
37489
37490 #include "tty.h"
37491 #include "network.h"
37492 @@ -51,7 +52,7 @@ struct ipw_tty {
37493 int tty_type;
37494 struct ipw_network *network;
37495 struct tty_struct *linux_tty;
37496 - int open_count;
37497 + local_t open_count;
37498 unsigned int control_lines;
37499 struct mutex ipw_tty_mutex;
37500 int tx_bytes_queued;
37501 @@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37502 mutex_unlock(&tty->ipw_tty_mutex);
37503 return -ENODEV;
37504 }
37505 - if (tty->open_count == 0)
37506 + if (local_read(&tty->open_count) == 0)
37507 tty->tx_bytes_queued = 0;
37508
37509 - tty->open_count++;
37510 + local_inc(&tty->open_count);
37511
37512 tty->linux_tty = linux_tty;
37513 linux_tty->driver_data = tty;
37514 @@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37515
37516 static void do_ipw_close(struct ipw_tty *tty)
37517 {
37518 - tty->open_count--;
37519 -
37520 - if (tty->open_count == 0) {
37521 + if (local_dec_return(&tty->open_count) == 0) {
37522 struct tty_struct *linux_tty = tty->linux_tty;
37523
37524 if (linux_tty != NULL) {
37525 @@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37526 return;
37527
37528 mutex_lock(&tty->ipw_tty_mutex);
37529 - if (tty->open_count == 0) {
37530 + if (local_read(&tty->open_count) == 0) {
37531 mutex_unlock(&tty->ipw_tty_mutex);
37532 return;
37533 }
37534 @@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37535 return;
37536 }
37537
37538 - if (!tty->open_count) {
37539 + if (!local_read(&tty->open_count)) {
37540 mutex_unlock(&tty->ipw_tty_mutex);
37541 return;
37542 }
37543 @@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37544 return -ENODEV;
37545
37546 mutex_lock(&tty->ipw_tty_mutex);
37547 - if (!tty->open_count) {
37548 + if (!local_read(&tty->open_count)) {
37549 mutex_unlock(&tty->ipw_tty_mutex);
37550 return -EINVAL;
37551 }
37552 @@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37553 if (!tty)
37554 return -ENODEV;
37555
37556 - if (!tty->open_count)
37557 + if (!local_read(&tty->open_count))
37558 return -EINVAL;
37559
37560 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37561 @@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37562 if (!tty)
37563 return 0;
37564
37565 - if (!tty->open_count)
37566 + if (!local_read(&tty->open_count))
37567 return 0;
37568
37569 return tty->tx_bytes_queued;
37570 @@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37571 if (!tty)
37572 return -ENODEV;
37573
37574 - if (!tty->open_count)
37575 + if (!local_read(&tty->open_count))
37576 return -EINVAL;
37577
37578 return get_control_lines(tty);
37579 @@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37580 if (!tty)
37581 return -ENODEV;
37582
37583 - if (!tty->open_count)
37584 + if (!local_read(&tty->open_count))
37585 return -EINVAL;
37586
37587 return set_control_lines(tty, set, clear);
37588 @@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37589 if (!tty)
37590 return -ENODEV;
37591
37592 - if (!tty->open_count)
37593 + if (!local_read(&tty->open_count))
37594 return -EINVAL;
37595
37596 /* FIXME: Exactly how is the tty object locked here .. */
37597 @@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37598 against a parallel ioctl etc */
37599 mutex_lock(&ttyj->ipw_tty_mutex);
37600 }
37601 - while (ttyj->open_count)
37602 + while (local_read(&ttyj->open_count))
37603 do_ipw_close(ttyj);
37604 ipwireless_disassociate_network_ttys(network,
37605 ttyj->channel_idx);
37606 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37607 index c43b683..0a88f1c 100644
37608 --- a/drivers/tty/n_gsm.c
37609 +++ b/drivers/tty/n_gsm.c
37610 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37611 kref_init(&dlci->ref);
37612 mutex_init(&dlci->mutex);
37613 dlci->fifo = &dlci->_fifo;
37614 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37615 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37616 kfree(dlci);
37617 return NULL;
37618 }
37619 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37620 index 94b6eda..15f7cec 100644
37621 --- a/drivers/tty/n_tty.c
37622 +++ b/drivers/tty/n_tty.c
37623 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37624 {
37625 *ops = tty_ldisc_N_TTY;
37626 ops->owner = NULL;
37627 - ops->refcount = ops->flags = 0;
37628 + atomic_set(&ops->refcount, 0);
37629 + ops->flags = 0;
37630 }
37631 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37632 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37633 index eeae7fa..177a743 100644
37634 --- a/drivers/tty/pty.c
37635 +++ b/drivers/tty/pty.c
37636 @@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37637 panic("Couldn't register Unix98 pts driver");
37638
37639 /* Now create the /dev/ptmx special device */
37640 + pax_open_kernel();
37641 tty_default_fops(&ptmx_fops);
37642 - ptmx_fops.open = ptmx_open;
37643 + *(void **)&ptmx_fops.open = ptmx_open;
37644 + pax_close_kernel();
37645
37646 cdev_init(&ptmx_cdev, &ptmx_fops);
37647 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37648 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37649 index 2b42a01..32a2ed3 100644
37650 --- a/drivers/tty/serial/kgdboc.c
37651 +++ b/drivers/tty/serial/kgdboc.c
37652 @@ -24,8 +24,9 @@
37653 #define MAX_CONFIG_LEN 40
37654
37655 static struct kgdb_io kgdboc_io_ops;
37656 +static struct kgdb_io kgdboc_io_ops_console;
37657
37658 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37659 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37660 static int configured = -1;
37661
37662 static char config[MAX_CONFIG_LEN];
37663 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37664 kgdboc_unregister_kbd();
37665 if (configured == 1)
37666 kgdb_unregister_io_module(&kgdboc_io_ops);
37667 + else if (configured == 2)
37668 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37669 }
37670
37671 static int configure_kgdboc(void)
37672 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37673 int err;
37674 char *cptr = config;
37675 struct console *cons;
37676 + int is_console = 0;
37677
37678 err = kgdboc_option_setup(config);
37679 if (err || !strlen(config) || isspace(config[0]))
37680 goto noconfig;
37681
37682 err = -ENODEV;
37683 - kgdboc_io_ops.is_console = 0;
37684 kgdb_tty_driver = NULL;
37685
37686 kgdboc_use_kms = 0;
37687 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37688 int idx;
37689 if (cons->device && cons->device(cons, &idx) == p &&
37690 idx == tty_line) {
37691 - kgdboc_io_ops.is_console = 1;
37692 + is_console = 1;
37693 break;
37694 }
37695 cons = cons->next;
37696 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37697 kgdb_tty_line = tty_line;
37698
37699 do_register:
37700 - err = kgdb_register_io_module(&kgdboc_io_ops);
37701 + if (is_console) {
37702 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37703 + configured = 2;
37704 + } else {
37705 + err = kgdb_register_io_module(&kgdboc_io_ops);
37706 + configured = 1;
37707 + }
37708 if (err)
37709 goto noconfig;
37710
37711 - configured = 1;
37712 -
37713 return 0;
37714
37715 noconfig:
37716 @@ -213,7 +220,7 @@ noconfig:
37717 static int __init init_kgdboc(void)
37718 {
37719 /* Already configured? */
37720 - if (configured == 1)
37721 + if (configured >= 1)
37722 return 0;
37723
37724 return configure_kgdboc();
37725 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37726 if (config[len - 1] == '\n')
37727 config[len - 1] = '\0';
37728
37729 - if (configured == 1)
37730 + if (configured >= 1)
37731 cleanup_kgdboc();
37732
37733 /* Go and configure with the new params. */
37734 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37735 .post_exception = kgdboc_post_exp_handler,
37736 };
37737
37738 +static struct kgdb_io kgdboc_io_ops_console = {
37739 + .name = "kgdboc",
37740 + .read_char = kgdboc_get_char,
37741 + .write_char = kgdboc_put_char,
37742 + .pre_exception = kgdboc_pre_exp_handler,
37743 + .post_exception = kgdboc_post_exp_handler,
37744 + .is_console = 1
37745 +};
37746 +
37747 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37748 /* This is only available if kgdboc is a built in for early debugging */
37749 static int __init kgdboc_early_init(char *opt)
37750 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37751 index 05728894..b9d44c6 100644
37752 --- a/drivers/tty/sysrq.c
37753 +++ b/drivers/tty/sysrq.c
37754 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37755 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37756 size_t count, loff_t *ppos)
37757 {
37758 - if (count) {
37759 + if (count && capable(CAP_SYS_ADMIN)) {
37760 char c;
37761
37762 if (get_user(c, buf))
37763 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37764 index d939bd7..33d92cd 100644
37765 --- a/drivers/tty/tty_io.c
37766 +++ b/drivers/tty/tty_io.c
37767 @@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37768
37769 void tty_default_fops(struct file_operations *fops)
37770 {
37771 - *fops = tty_fops;
37772 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37773 }
37774
37775 /*
37776 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37777 index 24b95db..9c078d0 100644
37778 --- a/drivers/tty/tty_ldisc.c
37779 +++ b/drivers/tty/tty_ldisc.c
37780 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37781 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37782 struct tty_ldisc_ops *ldo = ld->ops;
37783
37784 - ldo->refcount--;
37785 + atomic_dec(&ldo->refcount);
37786 module_put(ldo->owner);
37787 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37788
37789 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37790 spin_lock_irqsave(&tty_ldisc_lock, flags);
37791 tty_ldiscs[disc] = new_ldisc;
37792 new_ldisc->num = disc;
37793 - new_ldisc->refcount = 0;
37794 + atomic_set(&new_ldisc->refcount, 0);
37795 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37796
37797 return ret;
37798 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37799 return -EINVAL;
37800
37801 spin_lock_irqsave(&tty_ldisc_lock, flags);
37802 - if (tty_ldiscs[disc]->refcount)
37803 + if (atomic_read(&tty_ldiscs[disc]->refcount))
37804 ret = -EBUSY;
37805 else
37806 tty_ldiscs[disc] = NULL;
37807 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37808 if (ldops) {
37809 ret = ERR_PTR(-EAGAIN);
37810 if (try_module_get(ldops->owner)) {
37811 - ldops->refcount++;
37812 + atomic_inc(&ldops->refcount);
37813 ret = ldops;
37814 }
37815 }
37816 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37817 unsigned long flags;
37818
37819 spin_lock_irqsave(&tty_ldisc_lock, flags);
37820 - ldops->refcount--;
37821 + atomic_dec(&ldops->refcount);
37822 module_put(ldops->owner);
37823 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37824 }
37825 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37826 index 3b0c4e3..f98a992 100644
37827 --- a/drivers/tty/vt/keyboard.c
37828 +++ b/drivers/tty/vt/keyboard.c
37829 @@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37830 kbd->kbdmode == VC_OFF) &&
37831 value != KVAL(K_SAK))
37832 return; /* SAK is allowed even in raw mode */
37833 +
37834 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37835 + {
37836 + void *func = fn_handler[value];
37837 + if (func == fn_show_state || func == fn_show_ptregs ||
37838 + func == fn_show_mem)
37839 + return;
37840 + }
37841 +#endif
37842 +
37843 fn_handler[value](vc);
37844 }
37845
37846 @@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37847 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37848 return -EFAULT;
37849
37850 - if (!capable(CAP_SYS_TTY_CONFIG))
37851 - perm = 0;
37852 -
37853 switch (cmd) {
37854 case KDGKBENT:
37855 /* Ensure another thread doesn't free it under us */
37856 @@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37857 spin_unlock_irqrestore(&kbd_event_lock, flags);
37858 return put_user(val, &user_kbe->kb_value);
37859 case KDSKBENT:
37860 + if (!capable(CAP_SYS_TTY_CONFIG))
37861 + perm = 0;
37862 +
37863 if (!perm)
37864 return -EPERM;
37865 if (!i && v == K_NOSUCHMAP) {
37866 @@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37867 int i, j, k;
37868 int ret;
37869
37870 - if (!capable(CAP_SYS_TTY_CONFIG))
37871 - perm = 0;
37872 -
37873 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37874 if (!kbs) {
37875 ret = -ENOMEM;
37876 @@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37877 kfree(kbs);
37878 return ((p && *p) ? -EOVERFLOW : 0);
37879 case KDSKBSENT:
37880 + if (!capable(CAP_SYS_TTY_CONFIG))
37881 + perm = 0;
37882 +
37883 if (!perm) {
37884 ret = -EPERM;
37885 goto reterr;
37886 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37887 index a783d53..cb30d94 100644
37888 --- a/drivers/uio/uio.c
37889 +++ b/drivers/uio/uio.c
37890 @@ -25,6 +25,7 @@
37891 #include <linux/kobject.h>
37892 #include <linux/cdev.h>
37893 #include <linux/uio_driver.h>
37894 +#include <asm/local.h>
37895
37896 #define UIO_MAX_DEVICES (1U << MINORBITS)
37897
37898 @@ -32,10 +33,10 @@ struct uio_device {
37899 struct module *owner;
37900 struct device *dev;
37901 int minor;
37902 - atomic_t event;
37903 + atomic_unchecked_t event;
37904 struct fasync_struct *async_queue;
37905 wait_queue_head_t wait;
37906 - int vma_count;
37907 + local_t vma_count;
37908 struct uio_info *info;
37909 struct kobject *map_dir;
37910 struct kobject *portio_dir;
37911 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37912 struct device_attribute *attr, char *buf)
37913 {
37914 struct uio_device *idev = dev_get_drvdata(dev);
37915 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37916 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37917 }
37918
37919 static struct device_attribute uio_class_attributes[] = {
37920 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37921 {
37922 struct uio_device *idev = info->uio_dev;
37923
37924 - atomic_inc(&idev->event);
37925 + atomic_inc_unchecked(&idev->event);
37926 wake_up_interruptible(&idev->wait);
37927 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37928 }
37929 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37930 }
37931
37932 listener->dev = idev;
37933 - listener->event_count = atomic_read(&idev->event);
37934 + listener->event_count = atomic_read_unchecked(&idev->event);
37935 filep->private_data = listener;
37936
37937 if (idev->info->open) {
37938 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37939 return -EIO;
37940
37941 poll_wait(filep, &idev->wait, wait);
37942 - if (listener->event_count != atomic_read(&idev->event))
37943 + if (listener->event_count != atomic_read_unchecked(&idev->event))
37944 return POLLIN | POLLRDNORM;
37945 return 0;
37946 }
37947 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
37948 do {
37949 set_current_state(TASK_INTERRUPTIBLE);
37950
37951 - event_count = atomic_read(&idev->event);
37952 + event_count = atomic_read_unchecked(&idev->event);
37953 if (event_count != listener->event_count) {
37954 if (copy_to_user(buf, &event_count, count))
37955 retval = -EFAULT;
37956 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
37957 static void uio_vma_open(struct vm_area_struct *vma)
37958 {
37959 struct uio_device *idev = vma->vm_private_data;
37960 - idev->vma_count++;
37961 + local_inc(&idev->vma_count);
37962 }
37963
37964 static void uio_vma_close(struct vm_area_struct *vma)
37965 {
37966 struct uio_device *idev = vma->vm_private_data;
37967 - idev->vma_count--;
37968 + local_dec(&idev->vma_count);
37969 }
37970
37971 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37972 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
37973 idev->owner = owner;
37974 idev->info = info;
37975 init_waitqueue_head(&idev->wait);
37976 - atomic_set(&idev->event, 0);
37977 + atomic_set_unchecked(&idev->event, 0);
37978
37979 ret = uio_get_minor(idev);
37980 if (ret)
37981 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
37982 index 98b89fe..aff824e 100644
37983 --- a/drivers/usb/atm/cxacru.c
37984 +++ b/drivers/usb/atm/cxacru.c
37985 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
37986 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
37987 if (ret < 2)
37988 return -EINVAL;
37989 - if (index < 0 || index > 0x7f)
37990 + if (index > 0x7f)
37991 return -EINVAL;
37992 pos += tmp;
37993
37994 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
37995 index d3448ca..d2864ca 100644
37996 --- a/drivers/usb/atm/usbatm.c
37997 +++ b/drivers/usb/atm/usbatm.c
37998 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37999 if (printk_ratelimit())
38000 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38001 __func__, vpi, vci);
38002 - atomic_inc(&vcc->stats->rx_err);
38003 + atomic_inc_unchecked(&vcc->stats->rx_err);
38004 return;
38005 }
38006
38007 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38008 if (length > ATM_MAX_AAL5_PDU) {
38009 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38010 __func__, length, vcc);
38011 - atomic_inc(&vcc->stats->rx_err);
38012 + atomic_inc_unchecked(&vcc->stats->rx_err);
38013 goto out;
38014 }
38015
38016 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38017 if (sarb->len < pdu_length) {
38018 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38019 __func__, pdu_length, sarb->len, vcc);
38020 - atomic_inc(&vcc->stats->rx_err);
38021 + atomic_inc_unchecked(&vcc->stats->rx_err);
38022 goto out;
38023 }
38024
38025 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38026 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38027 __func__, vcc);
38028 - atomic_inc(&vcc->stats->rx_err);
38029 + atomic_inc_unchecked(&vcc->stats->rx_err);
38030 goto out;
38031 }
38032
38033 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38034 if (printk_ratelimit())
38035 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38036 __func__, length);
38037 - atomic_inc(&vcc->stats->rx_drop);
38038 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38039 goto out;
38040 }
38041
38042 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38043
38044 vcc->push(vcc, skb);
38045
38046 - atomic_inc(&vcc->stats->rx);
38047 + atomic_inc_unchecked(&vcc->stats->rx);
38048 out:
38049 skb_trim(sarb, 0);
38050 }
38051 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38052 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38053
38054 usbatm_pop(vcc, skb);
38055 - atomic_inc(&vcc->stats->tx);
38056 + atomic_inc_unchecked(&vcc->stats->tx);
38057
38058 skb = skb_dequeue(&instance->sndqueue);
38059 }
38060 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38061 if (!left--)
38062 return sprintf(page,
38063 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38064 - atomic_read(&atm_dev->stats.aal5.tx),
38065 - atomic_read(&atm_dev->stats.aal5.tx_err),
38066 - atomic_read(&atm_dev->stats.aal5.rx),
38067 - atomic_read(&atm_dev->stats.aal5.rx_err),
38068 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38069 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38070 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38071 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38072 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38073 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38074
38075 if (!left--) {
38076 if (instance->disconnected)
38077 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38078 index d956965..4179a77 100644
38079 --- a/drivers/usb/core/devices.c
38080 +++ b/drivers/usb/core/devices.c
38081 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38082 * time it gets called.
38083 */
38084 static struct device_connect_event {
38085 - atomic_t count;
38086 + atomic_unchecked_t count;
38087 wait_queue_head_t wait;
38088 } device_event = {
38089 .count = ATOMIC_INIT(1),
38090 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38091
38092 void usbfs_conn_disc_event(void)
38093 {
38094 - atomic_add(2, &device_event.count);
38095 + atomic_add_unchecked(2, &device_event.count);
38096 wake_up(&device_event.wait);
38097 }
38098
38099 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38100
38101 poll_wait(file, &device_event.wait, wait);
38102
38103 - event_count = atomic_read(&device_event.count);
38104 + event_count = atomic_read_unchecked(&device_event.count);
38105 if (file->f_version != event_count) {
38106 file->f_version = event_count;
38107 return POLLIN | POLLRDNORM;
38108 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38109 index 1fc8f12..20647c1 100644
38110 --- a/drivers/usb/early/ehci-dbgp.c
38111 +++ b/drivers/usb/early/ehci-dbgp.c
38112 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38113
38114 #ifdef CONFIG_KGDB
38115 static struct kgdb_io kgdbdbgp_io_ops;
38116 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38117 +static struct kgdb_io kgdbdbgp_io_ops_console;
38118 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38119 #else
38120 #define dbgp_kgdb_mode (0)
38121 #endif
38122 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38123 .write_char = kgdbdbgp_write_char,
38124 };
38125
38126 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38127 + .name = "kgdbdbgp",
38128 + .read_char = kgdbdbgp_read_char,
38129 + .write_char = kgdbdbgp_write_char,
38130 + .is_console = 1
38131 +};
38132 +
38133 static int kgdbdbgp_wait_time;
38134
38135 static int __init kgdbdbgp_parse_config(char *str)
38136 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38137 ptr++;
38138 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38139 }
38140 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38141 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38142 + if (early_dbgp_console.index != -1)
38143 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38144 + else
38145 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38146
38147 return 0;
38148 }
38149 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38150 index d6bea3e..60b250e 100644
38151 --- a/drivers/usb/wusbcore/wa-hc.h
38152 +++ b/drivers/usb/wusbcore/wa-hc.h
38153 @@ -192,7 +192,7 @@ struct wahc {
38154 struct list_head xfer_delayed_list;
38155 spinlock_t xfer_list_lock;
38156 struct work_struct xfer_work;
38157 - atomic_t xfer_id_count;
38158 + atomic_unchecked_t xfer_id_count;
38159 };
38160
38161
38162 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38163 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38164 spin_lock_init(&wa->xfer_list_lock);
38165 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38166 - atomic_set(&wa->xfer_id_count, 1);
38167 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38168 }
38169
38170 /**
38171 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38172 index 57c01ab..8a05959 100644
38173 --- a/drivers/usb/wusbcore/wa-xfer.c
38174 +++ b/drivers/usb/wusbcore/wa-xfer.c
38175 @@ -296,7 +296,7 @@ out:
38176 */
38177 static void wa_xfer_id_init(struct wa_xfer *xfer)
38178 {
38179 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38180 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38181 }
38182
38183 /*
38184 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38185 index 51e4c1e..9d87e2a 100644
38186 --- a/drivers/vhost/vhost.c
38187 +++ b/drivers/vhost/vhost.c
38188 @@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38189 return 0;
38190 }
38191
38192 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38193 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38194 {
38195 struct file *eventfp, *filep = NULL,
38196 *pollstart = NULL, *pollstop = NULL;
38197 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38198 index b0b2ac3..89a4399 100644
38199 --- a/drivers/video/aty/aty128fb.c
38200 +++ b/drivers/video/aty/aty128fb.c
38201 @@ -148,7 +148,7 @@ enum {
38202 };
38203
38204 /* Must match above enum */
38205 -static const char *r128_family[] __devinitdata = {
38206 +static const char *r128_family[] __devinitconst = {
38207 "AGP",
38208 "PCI",
38209 "PRO AGP",
38210 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38211 index 5c3960d..15cf8fc 100644
38212 --- a/drivers/video/fbcmap.c
38213 +++ b/drivers/video/fbcmap.c
38214 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38215 rc = -ENODEV;
38216 goto out;
38217 }
38218 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38219 - !info->fbops->fb_setcmap)) {
38220 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38221 rc = -EINVAL;
38222 goto out1;
38223 }
38224 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38225 index c6ce416..3b9b642 100644
38226 --- a/drivers/video/fbmem.c
38227 +++ b/drivers/video/fbmem.c
38228 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38229 image->dx += image->width + 8;
38230 }
38231 } else if (rotate == FB_ROTATE_UD) {
38232 - for (x = 0; x < num && image->dx >= 0; x++) {
38233 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38234 info->fbops->fb_imageblit(info, image);
38235 image->dx -= image->width + 8;
38236 }
38237 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38238 image->dy += image->height + 8;
38239 }
38240 } else if (rotate == FB_ROTATE_CCW) {
38241 - for (x = 0; x < num && image->dy >= 0; x++) {
38242 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38243 info->fbops->fb_imageblit(info, image);
38244 image->dy -= image->height + 8;
38245 }
38246 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38247 return -EFAULT;
38248 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38249 return -EINVAL;
38250 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38251 + if (con2fb.framebuffer >= FB_MAX)
38252 return -EINVAL;
38253 if (!registered_fb[con2fb.framebuffer])
38254 request_module("fb%d", con2fb.framebuffer);
38255 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38256 index 5a5d092..265c5ed 100644
38257 --- a/drivers/video/geode/gx1fb_core.c
38258 +++ b/drivers/video/geode/gx1fb_core.c
38259 @@ -29,7 +29,7 @@ static int crt_option = 1;
38260 static char panel_option[32] = "";
38261
38262 /* Modes relevant to the GX1 (taken from modedb.c) */
38263 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38264 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38265 /* 640x480-60 VESA */
38266 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38267 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38268 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38269 index 0fad23f..0e9afa4 100644
38270 --- a/drivers/video/gxt4500.c
38271 +++ b/drivers/video/gxt4500.c
38272 @@ -156,7 +156,7 @@ struct gxt4500_par {
38273 static char *mode_option;
38274
38275 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38276 -static const struct fb_videomode defaultmode __devinitdata = {
38277 +static const struct fb_videomode defaultmode __devinitconst = {
38278 .refresh = 60,
38279 .xres = 1280,
38280 .yres = 1024,
38281 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38282 return 0;
38283 }
38284
38285 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38286 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38287 .id = "IBM GXT4500P",
38288 .type = FB_TYPE_PACKED_PIXELS,
38289 .visual = FB_VISUAL_PSEUDOCOLOR,
38290 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38291 index 7672d2e..b56437f 100644
38292 --- a/drivers/video/i810/i810_accel.c
38293 +++ b/drivers/video/i810/i810_accel.c
38294 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38295 }
38296 }
38297 printk("ringbuffer lockup!!!\n");
38298 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38299 i810_report_error(mmio);
38300 par->dev_flags |= LOCKUP;
38301 info->pixmap.scan_align = 1;
38302 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38303 index b83f361..2b05a91 100644
38304 --- a/drivers/video/i810/i810_main.c
38305 +++ b/drivers/video/i810/i810_main.c
38306 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38307 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38308
38309 /* PCI */
38310 -static const char *i810_pci_list[] __devinitdata = {
38311 +static const char *i810_pci_list[] __devinitconst = {
38312 "Intel(R) 810 Framebuffer Device" ,
38313 "Intel(R) 810-DC100 Framebuffer Device" ,
38314 "Intel(R) 810E Framebuffer Device" ,
38315 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38316 index de36693..3c63fc2 100644
38317 --- a/drivers/video/jz4740_fb.c
38318 +++ b/drivers/video/jz4740_fb.c
38319 @@ -136,7 +136,7 @@ struct jzfb {
38320 uint32_t pseudo_palette[16];
38321 };
38322
38323 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38324 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38325 .id = "JZ4740 FB",
38326 .type = FB_TYPE_PACKED_PIXELS,
38327 .visual = FB_VISUAL_TRUECOLOR,
38328 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38329 index 3c14e43..eafa544 100644
38330 --- a/drivers/video/logo/logo_linux_clut224.ppm
38331 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38332 @@ -1,1604 +1,1123 @@
38333 P3
38334 -# Standard 224-color Linux logo
38335 80 80
38336 255
38337 - 0 0 0 0 0 0 0 0 0 0 0 0
38338 - 0 0 0 0 0 0 0 0 0 0 0 0
38339 - 0 0 0 0 0 0 0 0 0 0 0 0
38340 - 0 0 0 0 0 0 0 0 0 0 0 0
38341 - 0 0 0 0 0 0 0 0 0 0 0 0
38342 - 0 0 0 0 0 0 0 0 0 0 0 0
38343 - 0 0 0 0 0 0 0 0 0 0 0 0
38344 - 0 0 0 0 0 0 0 0 0 0 0 0
38345 - 0 0 0 0 0 0 0 0 0 0 0 0
38346 - 6 6 6 6 6 6 10 10 10 10 10 10
38347 - 10 10 10 6 6 6 6 6 6 6 6 6
38348 - 0 0 0 0 0 0 0 0 0 0 0 0
38349 - 0 0 0 0 0 0 0 0 0 0 0 0
38350 - 0 0 0 0 0 0 0 0 0 0 0 0
38351 - 0 0 0 0 0 0 0 0 0 0 0 0
38352 - 0 0 0 0 0 0 0 0 0 0 0 0
38353 - 0 0 0 0 0 0 0 0 0 0 0 0
38354 - 0 0 0 0 0 0 0 0 0 0 0 0
38355 - 0 0 0 0 0 0 0 0 0 0 0 0
38356 - 0 0 0 0 0 0 0 0 0 0 0 0
38357 - 0 0 0 0 0 0 0 0 0 0 0 0
38358 - 0 0 0 0 0 0 0 0 0 0 0 0
38359 - 0 0 0 0 0 0 0 0 0 0 0 0
38360 - 0 0 0 0 0 0 0 0 0 0 0 0
38361 - 0 0 0 0 0 0 0 0 0 0 0 0
38362 - 0 0 0 0 0 0 0 0 0 0 0 0
38363 - 0 0 0 0 0 0 0 0 0 0 0 0
38364 - 0 0 0 0 0 0 0 0 0 0 0 0
38365 - 0 0 0 6 6 6 10 10 10 14 14 14
38366 - 22 22 22 26 26 26 30 30 30 34 34 34
38367 - 30 30 30 30 30 30 26 26 26 18 18 18
38368 - 14 14 14 10 10 10 6 6 6 0 0 0
38369 - 0 0 0 0 0 0 0 0 0 0 0 0
38370 - 0 0 0 0 0 0 0 0 0 0 0 0
38371 - 0 0 0 0 0 0 0 0 0 0 0 0
38372 - 0 0 0 0 0 0 0 0 0 0 0 0
38373 - 0 0 0 0 0 0 0 0 0 0 0 0
38374 - 0 0 0 0 0 0 0 0 0 0 0 0
38375 - 0 0 0 0 0 0 0 0 0 0 0 0
38376 - 0 0 0 0 0 0 0 0 0 0 0 0
38377 - 0 0 0 0 0 0 0 0 0 0 0 0
38378 - 0 0 0 0 0 1 0 0 1 0 0 0
38379 - 0 0 0 0 0 0 0 0 0 0 0 0
38380 - 0 0 0 0 0 0 0 0 0 0 0 0
38381 - 0 0 0 0 0 0 0 0 0 0 0 0
38382 - 0 0 0 0 0 0 0 0 0 0 0 0
38383 - 0 0 0 0 0 0 0 0 0 0 0 0
38384 - 0 0 0 0 0 0 0 0 0 0 0 0
38385 - 6 6 6 14 14 14 26 26 26 42 42 42
38386 - 54 54 54 66 66 66 78 78 78 78 78 78
38387 - 78 78 78 74 74 74 66 66 66 54 54 54
38388 - 42 42 42 26 26 26 18 18 18 10 10 10
38389 - 6 6 6 0 0 0 0 0 0 0 0 0
38390 - 0 0 0 0 0 0 0 0 0 0 0 0
38391 - 0 0 0 0 0 0 0 0 0 0 0 0
38392 - 0 0 0 0 0 0 0 0 0 0 0 0
38393 - 0 0 0 0 0 0 0 0 0 0 0 0
38394 - 0 0 0 0 0 0 0 0 0 0 0 0
38395 - 0 0 0 0 0 0 0 0 0 0 0 0
38396 - 0 0 0 0 0 0 0 0 0 0 0 0
38397 - 0 0 0 0 0 0 0 0 0 0 0 0
38398 - 0 0 1 0 0 0 0 0 0 0 0 0
38399 - 0 0 0 0 0 0 0 0 0 0 0 0
38400 - 0 0 0 0 0 0 0 0 0 0 0 0
38401 - 0 0 0 0 0 0 0 0 0 0 0 0
38402 - 0 0 0 0 0 0 0 0 0 0 0 0
38403 - 0 0 0 0 0 0 0 0 0 0 0 0
38404 - 0 0 0 0 0 0 0 0 0 10 10 10
38405 - 22 22 22 42 42 42 66 66 66 86 86 86
38406 - 66 66 66 38 38 38 38 38 38 22 22 22
38407 - 26 26 26 34 34 34 54 54 54 66 66 66
38408 - 86 86 86 70 70 70 46 46 46 26 26 26
38409 - 14 14 14 6 6 6 0 0 0 0 0 0
38410 - 0 0 0 0 0 0 0 0 0 0 0 0
38411 - 0 0 0 0 0 0 0 0 0 0 0 0
38412 - 0 0 0 0 0 0 0 0 0 0 0 0
38413 - 0 0 0 0 0 0 0 0 0 0 0 0
38414 - 0 0 0 0 0 0 0 0 0 0 0 0
38415 - 0 0 0 0 0 0 0 0 0 0 0 0
38416 - 0 0 0 0 0 0 0 0 0 0 0 0
38417 - 0 0 0 0 0 0 0 0 0 0 0 0
38418 - 0 0 1 0 0 1 0 0 1 0 0 0
38419 - 0 0 0 0 0 0 0 0 0 0 0 0
38420 - 0 0 0 0 0 0 0 0 0 0 0 0
38421 - 0 0 0 0 0 0 0 0 0 0 0 0
38422 - 0 0 0 0 0 0 0 0 0 0 0 0
38423 - 0 0 0 0 0 0 0 0 0 0 0 0
38424 - 0 0 0 0 0 0 10 10 10 26 26 26
38425 - 50 50 50 82 82 82 58 58 58 6 6 6
38426 - 2 2 6 2 2 6 2 2 6 2 2 6
38427 - 2 2 6 2 2 6 2 2 6 2 2 6
38428 - 6 6 6 54 54 54 86 86 86 66 66 66
38429 - 38 38 38 18 18 18 6 6 6 0 0 0
38430 - 0 0 0 0 0 0 0 0 0 0 0 0
38431 - 0 0 0 0 0 0 0 0 0 0 0 0
38432 - 0 0 0 0 0 0 0 0 0 0 0 0
38433 - 0 0 0 0 0 0 0 0 0 0 0 0
38434 - 0 0 0 0 0 0 0 0 0 0 0 0
38435 - 0 0 0 0 0 0 0 0 0 0 0 0
38436 - 0 0 0 0 0 0 0 0 0 0 0 0
38437 - 0 0 0 0 0 0 0 0 0 0 0 0
38438 - 0 0 0 0 0 0 0 0 0 0 0 0
38439 - 0 0 0 0 0 0 0 0 0 0 0 0
38440 - 0 0 0 0 0 0 0 0 0 0 0 0
38441 - 0 0 0 0 0 0 0 0 0 0 0 0
38442 - 0 0 0 0 0 0 0 0 0 0 0 0
38443 - 0 0 0 0 0 0 0 0 0 0 0 0
38444 - 0 0 0 6 6 6 22 22 22 50 50 50
38445 - 78 78 78 34 34 34 2 2 6 2 2 6
38446 - 2 2 6 2 2 6 2 2 6 2 2 6
38447 - 2 2 6 2 2 6 2 2 6 2 2 6
38448 - 2 2 6 2 2 6 6 6 6 70 70 70
38449 - 78 78 78 46 46 46 22 22 22 6 6 6
38450 - 0 0 0 0 0 0 0 0 0 0 0 0
38451 - 0 0 0 0 0 0 0 0 0 0 0 0
38452 - 0 0 0 0 0 0 0 0 0 0 0 0
38453 - 0 0 0 0 0 0 0 0 0 0 0 0
38454 - 0 0 0 0 0 0 0 0 0 0 0 0
38455 - 0 0 0 0 0 0 0 0 0 0 0 0
38456 - 0 0 0 0 0 0 0 0 0 0 0 0
38457 - 0 0 0 0 0 0 0 0 0 0 0 0
38458 - 0 0 1 0 0 1 0 0 1 0 0 0
38459 - 0 0 0 0 0 0 0 0 0 0 0 0
38460 - 0 0 0 0 0 0 0 0 0 0 0 0
38461 - 0 0 0 0 0 0 0 0 0 0 0 0
38462 - 0 0 0 0 0 0 0 0 0 0 0 0
38463 - 0 0 0 0 0 0 0 0 0 0 0 0
38464 - 6 6 6 18 18 18 42 42 42 82 82 82
38465 - 26 26 26 2 2 6 2 2 6 2 2 6
38466 - 2 2 6 2 2 6 2 2 6 2 2 6
38467 - 2 2 6 2 2 6 2 2 6 14 14 14
38468 - 46 46 46 34 34 34 6 6 6 2 2 6
38469 - 42 42 42 78 78 78 42 42 42 18 18 18
38470 - 6 6 6 0 0 0 0 0 0 0 0 0
38471 - 0 0 0 0 0 0 0 0 0 0 0 0
38472 - 0 0 0 0 0 0 0 0 0 0 0 0
38473 - 0 0 0 0 0 0 0 0 0 0 0 0
38474 - 0 0 0 0 0 0 0 0 0 0 0 0
38475 - 0 0 0 0 0 0 0 0 0 0 0 0
38476 - 0 0 0 0 0 0 0 0 0 0 0 0
38477 - 0 0 0 0 0 0 0 0 0 0 0 0
38478 - 0 0 1 0 0 0 0 0 1 0 0 0
38479 - 0 0 0 0 0 0 0 0 0 0 0 0
38480 - 0 0 0 0 0 0 0 0 0 0 0 0
38481 - 0 0 0 0 0 0 0 0 0 0 0 0
38482 - 0 0 0 0 0 0 0 0 0 0 0 0
38483 - 0 0 0 0 0 0 0 0 0 0 0 0
38484 - 10 10 10 30 30 30 66 66 66 58 58 58
38485 - 2 2 6 2 2 6 2 2 6 2 2 6
38486 - 2 2 6 2 2 6 2 2 6 2 2 6
38487 - 2 2 6 2 2 6 2 2 6 26 26 26
38488 - 86 86 86 101 101 101 46 46 46 10 10 10
38489 - 2 2 6 58 58 58 70 70 70 34 34 34
38490 - 10 10 10 0 0 0 0 0 0 0 0 0
38491 - 0 0 0 0 0 0 0 0 0 0 0 0
38492 - 0 0 0 0 0 0 0 0 0 0 0 0
38493 - 0 0 0 0 0 0 0 0 0 0 0 0
38494 - 0 0 0 0 0 0 0 0 0 0 0 0
38495 - 0 0 0 0 0 0 0 0 0 0 0 0
38496 - 0 0 0 0 0 0 0 0 0 0 0 0
38497 - 0 0 0 0 0 0 0 0 0 0 0 0
38498 - 0 0 1 0 0 1 0 0 1 0 0 0
38499 - 0 0 0 0 0 0 0 0 0 0 0 0
38500 - 0 0 0 0 0 0 0 0 0 0 0 0
38501 - 0 0 0 0 0 0 0 0 0 0 0 0
38502 - 0 0 0 0 0 0 0 0 0 0 0 0
38503 - 0 0 0 0 0 0 0 0 0 0 0 0
38504 - 14 14 14 42 42 42 86 86 86 10 10 10
38505 - 2 2 6 2 2 6 2 2 6 2 2 6
38506 - 2 2 6 2 2 6 2 2 6 2 2 6
38507 - 2 2 6 2 2 6 2 2 6 30 30 30
38508 - 94 94 94 94 94 94 58 58 58 26 26 26
38509 - 2 2 6 6 6 6 78 78 78 54 54 54
38510 - 22 22 22 6 6 6 0 0 0 0 0 0
38511 - 0 0 0 0 0 0 0 0 0 0 0 0
38512 - 0 0 0 0 0 0 0 0 0 0 0 0
38513 - 0 0 0 0 0 0 0 0 0 0 0 0
38514 - 0 0 0 0 0 0 0 0 0 0 0 0
38515 - 0 0 0 0 0 0 0 0 0 0 0 0
38516 - 0 0 0 0 0 0 0 0 0 0 0 0
38517 - 0 0 0 0 0 0 0 0 0 0 0 0
38518 - 0 0 0 0 0 0 0 0 0 0 0 0
38519 - 0 0 0 0 0 0 0 0 0 0 0 0
38520 - 0 0 0 0 0 0 0 0 0 0 0 0
38521 - 0 0 0 0 0 0 0 0 0 0 0 0
38522 - 0 0 0 0 0 0 0 0 0 0 0 0
38523 - 0 0 0 0 0 0 0 0 0 6 6 6
38524 - 22 22 22 62 62 62 62 62 62 2 2 6
38525 - 2 2 6 2 2 6 2 2 6 2 2 6
38526 - 2 2 6 2 2 6 2 2 6 2 2 6
38527 - 2 2 6 2 2 6 2 2 6 26 26 26
38528 - 54 54 54 38 38 38 18 18 18 10 10 10
38529 - 2 2 6 2 2 6 34 34 34 82 82 82
38530 - 38 38 38 14 14 14 0 0 0 0 0 0
38531 - 0 0 0 0 0 0 0 0 0 0 0 0
38532 - 0 0 0 0 0 0 0 0 0 0 0 0
38533 - 0 0 0 0 0 0 0 0 0 0 0 0
38534 - 0 0 0 0 0 0 0 0 0 0 0 0
38535 - 0 0 0 0 0 0 0 0 0 0 0 0
38536 - 0 0 0 0 0 0 0 0 0 0 0 0
38537 - 0 0 0 0 0 0 0 0 0 0 0 0
38538 - 0 0 0 0 0 1 0 0 1 0 0 0
38539 - 0 0 0 0 0 0 0 0 0 0 0 0
38540 - 0 0 0 0 0 0 0 0 0 0 0 0
38541 - 0 0 0 0 0 0 0 0 0 0 0 0
38542 - 0 0 0 0 0 0 0 0 0 0 0 0
38543 - 0 0 0 0 0 0 0 0 0 6 6 6
38544 - 30 30 30 78 78 78 30 30 30 2 2 6
38545 - 2 2 6 2 2 6 2 2 6 2 2 6
38546 - 2 2 6 2 2 6 2 2 6 2 2 6
38547 - 2 2 6 2 2 6 2 2 6 10 10 10
38548 - 10 10 10 2 2 6 2 2 6 2 2 6
38549 - 2 2 6 2 2 6 2 2 6 78 78 78
38550 - 50 50 50 18 18 18 6 6 6 0 0 0
38551 - 0 0 0 0 0 0 0 0 0 0 0 0
38552 - 0 0 0 0 0 0 0 0 0 0 0 0
38553 - 0 0 0 0 0 0 0 0 0 0 0 0
38554 - 0 0 0 0 0 0 0 0 0 0 0 0
38555 - 0 0 0 0 0 0 0 0 0 0 0 0
38556 - 0 0 0 0 0 0 0 0 0 0 0 0
38557 - 0 0 0 0 0 0 0 0 0 0 0 0
38558 - 0 0 1 0 0 0 0 0 0 0 0 0
38559 - 0 0 0 0 0 0 0 0 0 0 0 0
38560 - 0 0 0 0 0 0 0 0 0 0 0 0
38561 - 0 0 0 0 0 0 0 0 0 0 0 0
38562 - 0 0 0 0 0 0 0 0 0 0 0 0
38563 - 0 0 0 0 0 0 0 0 0 10 10 10
38564 - 38 38 38 86 86 86 14 14 14 2 2 6
38565 - 2 2 6 2 2 6 2 2 6 2 2 6
38566 - 2 2 6 2 2 6 2 2 6 2 2 6
38567 - 2 2 6 2 2 6 2 2 6 2 2 6
38568 - 2 2 6 2 2 6 2 2 6 2 2 6
38569 - 2 2 6 2 2 6 2 2 6 54 54 54
38570 - 66 66 66 26 26 26 6 6 6 0 0 0
38571 - 0 0 0 0 0 0 0 0 0 0 0 0
38572 - 0 0 0 0 0 0 0 0 0 0 0 0
38573 - 0 0 0 0 0 0 0 0 0 0 0 0
38574 - 0 0 0 0 0 0 0 0 0 0 0 0
38575 - 0 0 0 0 0 0 0 0 0 0 0 0
38576 - 0 0 0 0 0 0 0 0 0 0 0 0
38577 - 0 0 0 0 0 0 0 0 0 0 0 0
38578 - 0 0 0 0 0 1 0 0 1 0 0 0
38579 - 0 0 0 0 0 0 0 0 0 0 0 0
38580 - 0 0 0 0 0 0 0 0 0 0 0 0
38581 - 0 0 0 0 0 0 0 0 0 0 0 0
38582 - 0 0 0 0 0 0 0 0 0 0 0 0
38583 - 0 0 0 0 0 0 0 0 0 14 14 14
38584 - 42 42 42 82 82 82 2 2 6 2 2 6
38585 - 2 2 6 6 6 6 10 10 10 2 2 6
38586 - 2 2 6 2 2 6 2 2 6 2 2 6
38587 - 2 2 6 2 2 6 2 2 6 6 6 6
38588 - 14 14 14 10 10 10 2 2 6 2 2 6
38589 - 2 2 6 2 2 6 2 2 6 18 18 18
38590 - 82 82 82 34 34 34 10 10 10 0 0 0
38591 - 0 0 0 0 0 0 0 0 0 0 0 0
38592 - 0 0 0 0 0 0 0 0 0 0 0 0
38593 - 0 0 0 0 0 0 0 0 0 0 0 0
38594 - 0 0 0 0 0 0 0 0 0 0 0 0
38595 - 0 0 0 0 0 0 0 0 0 0 0 0
38596 - 0 0 0 0 0 0 0 0 0 0 0 0
38597 - 0 0 0 0 0 0 0 0 0 0 0 0
38598 - 0 0 1 0 0 0 0 0 0 0 0 0
38599 - 0 0 0 0 0 0 0 0 0 0 0 0
38600 - 0 0 0 0 0 0 0 0 0 0 0 0
38601 - 0 0 0 0 0 0 0 0 0 0 0 0
38602 - 0 0 0 0 0 0 0 0 0 0 0 0
38603 - 0 0 0 0 0 0 0 0 0 14 14 14
38604 - 46 46 46 86 86 86 2 2 6 2 2 6
38605 - 6 6 6 6 6 6 22 22 22 34 34 34
38606 - 6 6 6 2 2 6 2 2 6 2 2 6
38607 - 2 2 6 2 2 6 18 18 18 34 34 34
38608 - 10 10 10 50 50 50 22 22 22 2 2 6
38609 - 2 2 6 2 2 6 2 2 6 10 10 10
38610 - 86 86 86 42 42 42 14 14 14 0 0 0
38611 - 0 0 0 0 0 0 0 0 0 0 0 0
38612 - 0 0 0 0 0 0 0 0 0 0 0 0
38613 - 0 0 0 0 0 0 0 0 0 0 0 0
38614 - 0 0 0 0 0 0 0 0 0 0 0 0
38615 - 0 0 0 0 0 0 0 0 0 0 0 0
38616 - 0 0 0 0 0 0 0 0 0 0 0 0
38617 - 0 0 0 0 0 0 0 0 0 0 0 0
38618 - 0 0 1 0 0 1 0 0 1 0 0 0
38619 - 0 0 0 0 0 0 0 0 0 0 0 0
38620 - 0 0 0 0 0 0 0 0 0 0 0 0
38621 - 0 0 0 0 0 0 0 0 0 0 0 0
38622 - 0 0 0 0 0 0 0 0 0 0 0 0
38623 - 0 0 0 0 0 0 0 0 0 14 14 14
38624 - 46 46 46 86 86 86 2 2 6 2 2 6
38625 - 38 38 38 116 116 116 94 94 94 22 22 22
38626 - 22 22 22 2 2 6 2 2 6 2 2 6
38627 - 14 14 14 86 86 86 138 138 138 162 162 162
38628 -154 154 154 38 38 38 26 26 26 6 6 6
38629 - 2 2 6 2 2 6 2 2 6 2 2 6
38630 - 86 86 86 46 46 46 14 14 14 0 0 0
38631 - 0 0 0 0 0 0 0 0 0 0 0 0
38632 - 0 0 0 0 0 0 0 0 0 0 0 0
38633 - 0 0 0 0 0 0 0 0 0 0 0 0
38634 - 0 0 0 0 0 0 0 0 0 0 0 0
38635 - 0 0 0 0 0 0 0 0 0 0 0 0
38636 - 0 0 0 0 0 0 0 0 0 0 0 0
38637 - 0 0 0 0 0 0 0 0 0 0 0 0
38638 - 0 0 0 0 0 0 0 0 0 0 0 0
38639 - 0 0 0 0 0 0 0 0 0 0 0 0
38640 - 0 0 0 0 0 0 0 0 0 0 0 0
38641 - 0 0 0 0 0 0 0 0 0 0 0 0
38642 - 0 0 0 0 0 0 0 0 0 0 0 0
38643 - 0 0 0 0 0 0 0 0 0 14 14 14
38644 - 46 46 46 86 86 86 2 2 6 14 14 14
38645 -134 134 134 198 198 198 195 195 195 116 116 116
38646 - 10 10 10 2 2 6 2 2 6 6 6 6
38647 -101 98 89 187 187 187 210 210 210 218 218 218
38648 -214 214 214 134 134 134 14 14 14 6 6 6
38649 - 2 2 6 2 2 6 2 2 6 2 2 6
38650 - 86 86 86 50 50 50 18 18 18 6 6 6
38651 - 0 0 0 0 0 0 0 0 0 0 0 0
38652 - 0 0 0 0 0 0 0 0 0 0 0 0
38653 - 0 0 0 0 0 0 0 0 0 0 0 0
38654 - 0 0 0 0 0 0 0 0 0 0 0 0
38655 - 0 0 0 0 0 0 0 0 0 0 0 0
38656 - 0 0 0 0 0 0 0 0 0 0 0 0
38657 - 0 0 0 0 0 0 0 0 1 0 0 0
38658 - 0 0 1 0 0 1 0 0 1 0 0 0
38659 - 0 0 0 0 0 0 0 0 0 0 0 0
38660 - 0 0 0 0 0 0 0 0 0 0 0 0
38661 - 0 0 0 0 0 0 0 0 0 0 0 0
38662 - 0 0 0 0 0 0 0 0 0 0 0 0
38663 - 0 0 0 0 0 0 0 0 0 14 14 14
38664 - 46 46 46 86 86 86 2 2 6 54 54 54
38665 -218 218 218 195 195 195 226 226 226 246 246 246
38666 - 58 58 58 2 2 6 2 2 6 30 30 30
38667 -210 210 210 253 253 253 174 174 174 123 123 123
38668 -221 221 221 234 234 234 74 74 74 2 2 6
38669 - 2 2 6 2 2 6 2 2 6 2 2 6
38670 - 70 70 70 58 58 58 22 22 22 6 6 6
38671 - 0 0 0 0 0 0 0 0 0 0 0 0
38672 - 0 0 0 0 0 0 0 0 0 0 0 0
38673 - 0 0 0 0 0 0 0 0 0 0 0 0
38674 - 0 0 0 0 0 0 0 0 0 0 0 0
38675 - 0 0 0 0 0 0 0 0 0 0 0 0
38676 - 0 0 0 0 0 0 0 0 0 0 0 0
38677 - 0 0 0 0 0 0 0 0 0 0 0 0
38678 - 0 0 0 0 0 0 0 0 0 0 0 0
38679 - 0 0 0 0 0 0 0 0 0 0 0 0
38680 - 0 0 0 0 0 0 0 0 0 0 0 0
38681 - 0 0 0 0 0 0 0 0 0 0 0 0
38682 - 0 0 0 0 0 0 0 0 0 0 0 0
38683 - 0 0 0 0 0 0 0 0 0 14 14 14
38684 - 46 46 46 82 82 82 2 2 6 106 106 106
38685 -170 170 170 26 26 26 86 86 86 226 226 226
38686 -123 123 123 10 10 10 14 14 14 46 46 46
38687 -231 231 231 190 190 190 6 6 6 70 70 70
38688 - 90 90 90 238 238 238 158 158 158 2 2 6
38689 - 2 2 6 2 2 6 2 2 6 2 2 6
38690 - 70 70 70 58 58 58 22 22 22 6 6 6
38691 - 0 0 0 0 0 0 0 0 0 0 0 0
38692 - 0 0 0 0 0 0 0 0 0 0 0 0
38693 - 0 0 0 0 0 0 0 0 0 0 0 0
38694 - 0 0 0 0 0 0 0 0 0 0 0 0
38695 - 0 0 0 0 0 0 0 0 0 0 0 0
38696 - 0 0 0 0 0 0 0 0 0 0 0 0
38697 - 0 0 0 0 0 0 0 0 1 0 0 0
38698 - 0 0 1 0 0 1 0 0 1 0 0 0
38699 - 0 0 0 0 0 0 0 0 0 0 0 0
38700 - 0 0 0 0 0 0 0 0 0 0 0 0
38701 - 0 0 0 0 0 0 0 0 0 0 0 0
38702 - 0 0 0 0 0 0 0 0 0 0 0 0
38703 - 0 0 0 0 0 0 0 0 0 14 14 14
38704 - 42 42 42 86 86 86 6 6 6 116 116 116
38705 -106 106 106 6 6 6 70 70 70 149 149 149
38706 -128 128 128 18 18 18 38 38 38 54 54 54
38707 -221 221 221 106 106 106 2 2 6 14 14 14
38708 - 46 46 46 190 190 190 198 198 198 2 2 6
38709 - 2 2 6 2 2 6 2 2 6 2 2 6
38710 - 74 74 74 62 62 62 22 22 22 6 6 6
38711 - 0 0 0 0 0 0 0 0 0 0 0 0
38712 - 0 0 0 0 0 0 0 0 0 0 0 0
38713 - 0 0 0 0 0 0 0 0 0 0 0 0
38714 - 0 0 0 0 0 0 0 0 0 0 0 0
38715 - 0 0 0 0 0 0 0 0 0 0 0 0
38716 - 0 0 0 0 0 0 0 0 0 0 0 0
38717 - 0 0 0 0 0 0 0 0 1 0 0 0
38718 - 0 0 1 0 0 0 0 0 1 0 0 0
38719 - 0 0 0 0 0 0 0 0 0 0 0 0
38720 - 0 0 0 0 0 0 0 0 0 0 0 0
38721 - 0 0 0 0 0 0 0 0 0 0 0 0
38722 - 0 0 0 0 0 0 0 0 0 0 0 0
38723 - 0 0 0 0 0 0 0 0 0 14 14 14
38724 - 42 42 42 94 94 94 14 14 14 101 101 101
38725 -128 128 128 2 2 6 18 18 18 116 116 116
38726 -118 98 46 121 92 8 121 92 8 98 78 10
38727 -162 162 162 106 106 106 2 2 6 2 2 6
38728 - 2 2 6 195 195 195 195 195 195 6 6 6
38729 - 2 2 6 2 2 6 2 2 6 2 2 6
38730 - 74 74 74 62 62 62 22 22 22 6 6 6
38731 - 0 0 0 0 0 0 0 0 0 0 0 0
38732 - 0 0 0 0 0 0 0 0 0 0 0 0
38733 - 0 0 0 0 0 0 0 0 0 0 0 0
38734 - 0 0 0 0 0 0 0 0 0 0 0 0
38735 - 0 0 0 0 0 0 0 0 0 0 0 0
38736 - 0 0 0 0 0 0 0 0 0 0 0 0
38737 - 0 0 0 0 0 0 0 0 1 0 0 1
38738 - 0 0 1 0 0 0 0 0 1 0 0 0
38739 - 0 0 0 0 0 0 0 0 0 0 0 0
38740 - 0 0 0 0 0 0 0 0 0 0 0 0
38741 - 0 0 0 0 0 0 0 0 0 0 0 0
38742 - 0 0 0 0 0 0 0 0 0 0 0 0
38743 - 0 0 0 0 0 0 0 0 0 10 10 10
38744 - 38 38 38 90 90 90 14 14 14 58 58 58
38745 -210 210 210 26 26 26 54 38 6 154 114 10
38746 -226 170 11 236 186 11 225 175 15 184 144 12
38747 -215 174 15 175 146 61 37 26 9 2 2 6
38748 - 70 70 70 246 246 246 138 138 138 2 2 6
38749 - 2 2 6 2 2 6 2 2 6 2 2 6
38750 - 70 70 70 66 66 66 26 26 26 6 6 6
38751 - 0 0 0 0 0 0 0 0 0 0 0 0
38752 - 0 0 0 0 0 0 0 0 0 0 0 0
38753 - 0 0 0 0 0 0 0 0 0 0 0 0
38754 - 0 0 0 0 0 0 0 0 0 0 0 0
38755 - 0 0 0 0 0 0 0 0 0 0 0 0
38756 - 0 0 0 0 0 0 0 0 0 0 0 0
38757 - 0 0 0 0 0 0 0 0 0 0 0 0
38758 - 0 0 0 0 0 0 0 0 0 0 0 0
38759 - 0 0 0 0 0 0 0 0 0 0 0 0
38760 - 0 0 0 0 0 0 0 0 0 0 0 0
38761 - 0 0 0 0 0 0 0 0 0 0 0 0
38762 - 0 0 0 0 0 0 0 0 0 0 0 0
38763 - 0 0 0 0 0 0 0 0 0 10 10 10
38764 - 38 38 38 86 86 86 14 14 14 10 10 10
38765 -195 195 195 188 164 115 192 133 9 225 175 15
38766 -239 182 13 234 190 10 232 195 16 232 200 30
38767 -245 207 45 241 208 19 232 195 16 184 144 12
38768 -218 194 134 211 206 186 42 42 42 2 2 6
38769 - 2 2 6 2 2 6 2 2 6 2 2 6
38770 - 50 50 50 74 74 74 30 30 30 6 6 6
38771 - 0 0 0 0 0 0 0 0 0 0 0 0
38772 - 0 0 0 0 0 0 0 0 0 0 0 0
38773 - 0 0 0 0 0 0 0 0 0 0 0 0
38774 - 0 0 0 0 0 0 0 0 0 0 0 0
38775 - 0 0 0 0 0 0 0 0 0 0 0 0
38776 - 0 0 0 0 0 0 0 0 0 0 0 0
38777 - 0 0 0 0 0 0 0 0 0 0 0 0
38778 - 0 0 0 0 0 0 0 0 0 0 0 0
38779 - 0 0 0 0 0 0 0 0 0 0 0 0
38780 - 0 0 0 0 0 0 0 0 0 0 0 0
38781 - 0 0 0 0 0 0 0 0 0 0 0 0
38782 - 0 0 0 0 0 0 0 0 0 0 0 0
38783 - 0 0 0 0 0 0 0 0 0 10 10 10
38784 - 34 34 34 86 86 86 14 14 14 2 2 6
38785 -121 87 25 192 133 9 219 162 10 239 182 13
38786 -236 186 11 232 195 16 241 208 19 244 214 54
38787 -246 218 60 246 218 38 246 215 20 241 208 19
38788 -241 208 19 226 184 13 121 87 25 2 2 6
38789 - 2 2 6 2 2 6 2 2 6 2 2 6
38790 - 50 50 50 82 82 82 34 34 34 10 10 10
38791 - 0 0 0 0 0 0 0 0 0 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 0 0 0
38793 - 0 0 0 0 0 0 0 0 0 0 0 0
38794 - 0 0 0 0 0 0 0 0 0 0 0 0
38795 - 0 0 0 0 0 0 0 0 0 0 0 0
38796 - 0 0 0 0 0 0 0 0 0 0 0 0
38797 - 0 0 0 0 0 0 0 0 0 0 0 0
38798 - 0 0 0 0 0 0 0 0 0 0 0 0
38799 - 0 0 0 0 0 0 0 0 0 0 0 0
38800 - 0 0 0 0 0 0 0 0 0 0 0 0
38801 - 0 0 0 0 0 0 0 0 0 0 0 0
38802 - 0 0 0 0 0 0 0 0 0 0 0 0
38803 - 0 0 0 0 0 0 0 0 0 10 10 10
38804 - 34 34 34 82 82 82 30 30 30 61 42 6
38805 -180 123 7 206 145 10 230 174 11 239 182 13
38806 -234 190 10 238 202 15 241 208 19 246 218 74
38807 -246 218 38 246 215 20 246 215 20 246 215 20
38808 -226 184 13 215 174 15 184 144 12 6 6 6
38809 - 2 2 6 2 2 6 2 2 6 2 2 6
38810 - 26 26 26 94 94 94 42 42 42 14 14 14
38811 - 0 0 0 0 0 0 0 0 0 0 0 0
38812 - 0 0 0 0 0 0 0 0 0 0 0 0
38813 - 0 0 0 0 0 0 0 0 0 0 0 0
38814 - 0 0 0 0 0 0 0 0 0 0 0 0
38815 - 0 0 0 0 0 0 0 0 0 0 0 0
38816 - 0 0 0 0 0 0 0 0 0 0 0 0
38817 - 0 0 0 0 0 0 0 0 0 0 0 0
38818 - 0 0 0 0 0 0 0 0 0 0 0 0
38819 - 0 0 0 0 0 0 0 0 0 0 0 0
38820 - 0 0 0 0 0 0 0 0 0 0 0 0
38821 - 0 0 0 0 0 0 0 0 0 0 0 0
38822 - 0 0 0 0 0 0 0 0 0 0 0 0
38823 - 0 0 0 0 0 0 0 0 0 10 10 10
38824 - 30 30 30 78 78 78 50 50 50 104 69 6
38825 -192 133 9 216 158 10 236 178 12 236 186 11
38826 -232 195 16 241 208 19 244 214 54 245 215 43
38827 -246 215 20 246 215 20 241 208 19 198 155 10
38828 -200 144 11 216 158 10 156 118 10 2 2 6
38829 - 2 2 6 2 2 6 2 2 6 2 2 6
38830 - 6 6 6 90 90 90 54 54 54 18 18 18
38831 - 6 6 6 0 0 0 0 0 0 0 0 0
38832 - 0 0 0 0 0 0 0 0 0 0 0 0
38833 - 0 0 0 0 0 0 0 0 0 0 0 0
38834 - 0 0 0 0 0 0 0 0 0 0 0 0
38835 - 0 0 0 0 0 0 0 0 0 0 0 0
38836 - 0 0 0 0 0 0 0 0 0 0 0 0
38837 - 0 0 0 0 0 0 0 0 0 0 0 0
38838 - 0 0 0 0 0 0 0 0 0 0 0 0
38839 - 0 0 0 0 0 0 0 0 0 0 0 0
38840 - 0 0 0 0 0 0 0 0 0 0 0 0
38841 - 0 0 0 0 0 0 0 0 0 0 0 0
38842 - 0 0 0 0 0 0 0 0 0 0 0 0
38843 - 0 0 0 0 0 0 0 0 0 10 10 10
38844 - 30 30 30 78 78 78 46 46 46 22 22 22
38845 -137 92 6 210 162 10 239 182 13 238 190 10
38846 -238 202 15 241 208 19 246 215 20 246 215 20
38847 -241 208 19 203 166 17 185 133 11 210 150 10
38848 -216 158 10 210 150 10 102 78 10 2 2 6
38849 - 6 6 6 54 54 54 14 14 14 2 2 6
38850 - 2 2 6 62 62 62 74 74 74 30 30 30
38851 - 10 10 10 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 0 0 0
38854 - 0 0 0 0 0 0 0 0 0 0 0 0
38855 - 0 0 0 0 0 0 0 0 0 0 0 0
38856 - 0 0 0 0 0 0 0 0 0 0 0 0
38857 - 0 0 0 0 0 0 0 0 0 0 0 0
38858 - 0 0 0 0 0 0 0 0 0 0 0 0
38859 - 0 0 0 0 0 0 0 0 0 0 0 0
38860 - 0 0 0 0 0 0 0 0 0 0 0 0
38861 - 0 0 0 0 0 0 0 0 0 0 0 0
38862 - 0 0 0 0 0 0 0 0 0 0 0 0
38863 - 0 0 0 0 0 0 0 0 0 10 10 10
38864 - 34 34 34 78 78 78 50 50 50 6 6 6
38865 - 94 70 30 139 102 15 190 146 13 226 184 13
38866 -232 200 30 232 195 16 215 174 15 190 146 13
38867 -168 122 10 192 133 9 210 150 10 213 154 11
38868 -202 150 34 182 157 106 101 98 89 2 2 6
38869 - 2 2 6 78 78 78 116 116 116 58 58 58
38870 - 2 2 6 22 22 22 90 90 90 46 46 46
38871 - 18 18 18 6 6 6 0 0 0 0 0 0
38872 - 0 0 0 0 0 0 0 0 0 0 0 0
38873 - 0 0 0 0 0 0 0 0 0 0 0 0
38874 - 0 0 0 0 0 0 0 0 0 0 0 0
38875 - 0 0 0 0 0 0 0 0 0 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 0 0 0
38877 - 0 0 0 0 0 0 0 0 0 0 0 0
38878 - 0 0 0 0 0 0 0 0 0 0 0 0
38879 - 0 0 0 0 0 0 0 0 0 0 0 0
38880 - 0 0 0 0 0 0 0 0 0 0 0 0
38881 - 0 0 0 0 0 0 0 0 0 0 0 0
38882 - 0 0 0 0 0 0 0 0 0 0 0 0
38883 - 0 0 0 0 0 0 0 0 0 10 10 10
38884 - 38 38 38 86 86 86 50 50 50 6 6 6
38885 -128 128 128 174 154 114 156 107 11 168 122 10
38886 -198 155 10 184 144 12 197 138 11 200 144 11
38887 -206 145 10 206 145 10 197 138 11 188 164 115
38888 -195 195 195 198 198 198 174 174 174 14 14 14
38889 - 2 2 6 22 22 22 116 116 116 116 116 116
38890 - 22 22 22 2 2 6 74 74 74 70 70 70
38891 - 30 30 30 10 10 10 0 0 0 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 0 0 0
38894 - 0 0 0 0 0 0 0 0 0 0 0 0
38895 - 0 0 0 0 0 0 0 0 0 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 0 0 0
38897 - 0 0 0 0 0 0 0 0 0 0 0 0
38898 - 0 0 0 0 0 0 0 0 0 0 0 0
38899 - 0 0 0 0 0 0 0 0 0 0 0 0
38900 - 0 0 0 0 0 0 0 0 0 0 0 0
38901 - 0 0 0 0 0 0 0 0 0 0 0 0
38902 - 0 0 0 0 0 0 0 0 0 0 0 0
38903 - 0 0 0 0 0 0 6 6 6 18 18 18
38904 - 50 50 50 101 101 101 26 26 26 10 10 10
38905 -138 138 138 190 190 190 174 154 114 156 107 11
38906 -197 138 11 200 144 11 197 138 11 192 133 9
38907 -180 123 7 190 142 34 190 178 144 187 187 187
38908 -202 202 202 221 221 221 214 214 214 66 66 66
38909 - 2 2 6 2 2 6 50 50 50 62 62 62
38910 - 6 6 6 2 2 6 10 10 10 90 90 90
38911 - 50 50 50 18 18 18 6 6 6 0 0 0
38912 - 0 0 0 0 0 0 0 0 0 0 0 0
38913 - 0 0 0 0 0 0 0 0 0 0 0 0
38914 - 0 0 0 0 0 0 0 0 0 0 0 0
38915 - 0 0 0 0 0 0 0 0 0 0 0 0
38916 - 0 0 0 0 0 0 0 0 0 0 0 0
38917 - 0 0 0 0 0 0 0 0 0 0 0 0
38918 - 0 0 0 0 0 0 0 0 0 0 0 0
38919 - 0 0 0 0 0 0 0 0 0 0 0 0
38920 - 0 0 0 0 0 0 0 0 0 0 0 0
38921 - 0 0 0 0 0 0 0 0 0 0 0 0
38922 - 0 0 0 0 0 0 0 0 0 0 0 0
38923 - 0 0 0 0 0 0 10 10 10 34 34 34
38924 - 74 74 74 74 74 74 2 2 6 6 6 6
38925 -144 144 144 198 198 198 190 190 190 178 166 146
38926 -154 121 60 156 107 11 156 107 11 168 124 44
38927 -174 154 114 187 187 187 190 190 190 210 210 210
38928 -246 246 246 253 253 253 253 253 253 182 182 182
38929 - 6 6 6 2 2 6 2 2 6 2 2 6
38930 - 2 2 6 2 2 6 2 2 6 62 62 62
38931 - 74 74 74 34 34 34 14 14 14 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 0 0 0 0 0 0 0 0 0 0 0 0
38936 - 0 0 0 0 0 0 0 0 0 0 0 0
38937 - 0 0 0 0 0 0 0 0 0 0 0 0
38938 - 0 0 0 0 0 0 0 0 0 0 0 0
38939 - 0 0 0 0 0 0 0 0 0 0 0 0
38940 - 0 0 0 0 0 0 0 0 0 0 0 0
38941 - 0 0 0 0 0 0 0 0 0 0 0 0
38942 - 0 0 0 0 0 0 0 0 0 0 0 0
38943 - 0 0 0 10 10 10 22 22 22 54 54 54
38944 - 94 94 94 18 18 18 2 2 6 46 46 46
38945 -234 234 234 221 221 221 190 190 190 190 190 190
38946 -190 190 190 187 187 187 187 187 187 190 190 190
38947 -190 190 190 195 195 195 214 214 214 242 242 242
38948 -253 253 253 253 253 253 253 253 253 253 253 253
38949 - 82 82 82 2 2 6 2 2 6 2 2 6
38950 - 2 2 6 2 2 6 2 2 6 14 14 14
38951 - 86 86 86 54 54 54 22 22 22 6 6 6
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 0 0 0
38954 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 0 0 0 0 0 0 0 0 0 0 0 0
38956 - 0 0 0 0 0 0 0 0 0 0 0 0
38957 - 0 0 0 0 0 0 0 0 0 0 0 0
38958 - 0 0 0 0 0 0 0 0 0 0 0 0
38959 - 0 0 0 0 0 0 0 0 0 0 0 0
38960 - 0 0 0 0 0 0 0 0 0 0 0 0
38961 - 0 0 0 0 0 0 0 0 0 0 0 0
38962 - 0 0 0 0 0 0 0 0 0 0 0 0
38963 - 6 6 6 18 18 18 46 46 46 90 90 90
38964 - 46 46 46 18 18 18 6 6 6 182 182 182
38965 -253 253 253 246 246 246 206 206 206 190 190 190
38966 -190 190 190 190 190 190 190 190 190 190 190 190
38967 -206 206 206 231 231 231 250 250 250 253 253 253
38968 -253 253 253 253 253 253 253 253 253 253 253 253
38969 -202 202 202 14 14 14 2 2 6 2 2 6
38970 - 2 2 6 2 2 6 2 2 6 2 2 6
38971 - 42 42 42 86 86 86 42 42 42 18 18 18
38972 - 6 6 6 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 0 0 0 0 0 0
38974 - 0 0 0 0 0 0 0 0 0 0 0 0
38975 - 0 0 0 0 0 0 0 0 0 0 0 0
38976 - 0 0 0 0 0 0 0 0 0 0 0 0
38977 - 0 0 0 0 0 0 0 0 0 0 0 0
38978 - 0 0 0 0 0 0 0 0 0 0 0 0
38979 - 0 0 0 0 0 0 0 0 0 0 0 0
38980 - 0 0 0 0 0 0 0 0 0 0 0 0
38981 - 0 0 0 0 0 0 0 0 0 0 0 0
38982 - 0 0 0 0 0 0 0 0 0 6 6 6
38983 - 14 14 14 38 38 38 74 74 74 66 66 66
38984 - 2 2 6 6 6 6 90 90 90 250 250 250
38985 -253 253 253 253 253 253 238 238 238 198 198 198
38986 -190 190 190 190 190 190 195 195 195 221 221 221
38987 -246 246 246 253 253 253 253 253 253 253 253 253
38988 -253 253 253 253 253 253 253 253 253 253 253 253
38989 -253 253 253 82 82 82 2 2 6 2 2 6
38990 - 2 2 6 2 2 6 2 2 6 2 2 6
38991 - 2 2 6 78 78 78 70 70 70 34 34 34
38992 - 14 14 14 6 6 6 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 0 0 0 0 0 0 0 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 0 0 0
38997 - 0 0 0 0 0 0 0 0 0 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 0 0 0 0 0 0 0 0 0 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 14 14 14
39003 - 34 34 34 66 66 66 78 78 78 6 6 6
39004 - 2 2 6 18 18 18 218 218 218 253 253 253
39005 -253 253 253 253 253 253 253 253 253 246 246 246
39006 -226 226 226 231 231 231 246 246 246 253 253 253
39007 -253 253 253 253 253 253 253 253 253 253 253 253
39008 -253 253 253 253 253 253 253 253 253 253 253 253
39009 -253 253 253 178 178 178 2 2 6 2 2 6
39010 - 2 2 6 2 2 6 2 2 6 2 2 6
39011 - 2 2 6 18 18 18 90 90 90 62 62 62
39012 - 30 30 30 10 10 10 0 0 0 0 0 0
39013 - 0 0 0 0 0 0 0 0 0 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 0 0 0
39017 - 0 0 0 0 0 0 0 0 0 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 0 0 0
39021 - 0 0 0 0 0 0 0 0 0 0 0 0
39022 - 0 0 0 0 0 0 10 10 10 26 26 26
39023 - 58 58 58 90 90 90 18 18 18 2 2 6
39024 - 2 2 6 110 110 110 253 253 253 253 253 253
39025 -253 253 253 253 253 253 253 253 253 253 253 253
39026 -250 250 250 253 253 253 253 253 253 253 253 253
39027 -253 253 253 253 253 253 253 253 253 253 253 253
39028 -253 253 253 253 253 253 253 253 253 253 253 253
39029 -253 253 253 231 231 231 18 18 18 2 2 6
39030 - 2 2 6 2 2 6 2 2 6 2 2 6
39031 - 2 2 6 2 2 6 18 18 18 94 94 94
39032 - 54 54 54 26 26 26 10 10 10 0 0 0
39033 - 0 0 0 0 0 0 0 0 0 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 0 0 0 0 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 0 0 0
39041 - 0 0 0 0 0 0 0 0 0 0 0 0
39042 - 0 0 0 6 6 6 22 22 22 50 50 50
39043 - 90 90 90 26 26 26 2 2 6 2 2 6
39044 - 14 14 14 195 195 195 250 250 250 253 253 253
39045 -253 253 253 253 253 253 253 253 253 253 253 253
39046 -253 253 253 253 253 253 253 253 253 253 253 253
39047 -253 253 253 253 253 253 253 253 253 253 253 253
39048 -253 253 253 253 253 253 253 253 253 253 253 253
39049 -250 250 250 242 242 242 54 54 54 2 2 6
39050 - 2 2 6 2 2 6 2 2 6 2 2 6
39051 - 2 2 6 2 2 6 2 2 6 38 38 38
39052 - 86 86 86 50 50 50 22 22 22 6 6 6
39053 - 0 0 0 0 0 0 0 0 0 0 0 0
39054 - 0 0 0 0 0 0 0 0 0 0 0 0
39055 - 0 0 0 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 0 0 0
39057 - 0 0 0 0 0 0 0 0 0 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 0 0 0
39061 - 0 0 0 0 0 0 0 0 0 0 0 0
39062 - 6 6 6 14 14 14 38 38 38 82 82 82
39063 - 34 34 34 2 2 6 2 2 6 2 2 6
39064 - 42 42 42 195 195 195 246 246 246 253 253 253
39065 -253 253 253 253 253 253 253 253 253 250 250 250
39066 -242 242 242 242 242 242 250 250 250 253 253 253
39067 -253 253 253 253 253 253 253 253 253 253 253 253
39068 -253 253 253 250 250 250 246 246 246 238 238 238
39069 -226 226 226 231 231 231 101 101 101 6 6 6
39070 - 2 2 6 2 2 6 2 2 6 2 2 6
39071 - 2 2 6 2 2 6 2 2 6 2 2 6
39072 - 38 38 38 82 82 82 42 42 42 14 14 14
39073 - 6 6 6 0 0 0 0 0 0 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 10 10 10 26 26 26 62 62 62 66 66 66
39083 - 2 2 6 2 2 6 2 2 6 6 6 6
39084 - 70 70 70 170 170 170 206 206 206 234 234 234
39085 -246 246 246 250 250 250 250 250 250 238 238 238
39086 -226 226 226 231 231 231 238 238 238 250 250 250
39087 -250 250 250 250 250 250 246 246 246 231 231 231
39088 -214 214 214 206 206 206 202 202 202 202 202 202
39089 -198 198 198 202 202 202 182 182 182 18 18 18
39090 - 2 2 6 2 2 6 2 2 6 2 2 6
39091 - 2 2 6 2 2 6 2 2 6 2 2 6
39092 - 2 2 6 62 62 62 66 66 66 30 30 30
39093 - 10 10 10 0 0 0 0 0 0 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 0 0 0
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 0 0 0
39097 - 0 0 0 0 0 0 0 0 0 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 0 0 0
39101 - 0 0 0 0 0 0 0 0 0 0 0 0
39102 - 14 14 14 42 42 42 82 82 82 18 18 18
39103 - 2 2 6 2 2 6 2 2 6 10 10 10
39104 - 94 94 94 182 182 182 218 218 218 242 242 242
39105 -250 250 250 253 253 253 253 253 253 250 250 250
39106 -234 234 234 253 253 253 253 253 253 253 253 253
39107 -253 253 253 253 253 253 253 253 253 246 246 246
39108 -238 238 238 226 226 226 210 210 210 202 202 202
39109 -195 195 195 195 195 195 210 210 210 158 158 158
39110 - 6 6 6 14 14 14 50 50 50 14 14 14
39111 - 2 2 6 2 2 6 2 2 6 2 2 6
39112 - 2 2 6 6 6 6 86 86 86 46 46 46
39113 - 18 18 18 6 6 6 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 0 0 0 0 0 0 0 0 0 0 0 0
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 0 0 0
39121 - 0 0 0 0 0 0 0 0 0 6 6 6
39122 - 22 22 22 54 54 54 70 70 70 2 2 6
39123 - 2 2 6 10 10 10 2 2 6 22 22 22
39124 -166 166 166 231 231 231 250 250 250 253 253 253
39125 -253 253 253 253 253 253 253 253 253 250 250 250
39126 -242 242 242 253 253 253 253 253 253 253 253 253
39127 -253 253 253 253 253 253 253 253 253 253 253 253
39128 -253 253 253 253 253 253 253 253 253 246 246 246
39129 -231 231 231 206 206 206 198 198 198 226 226 226
39130 - 94 94 94 2 2 6 6 6 6 38 38 38
39131 - 30 30 30 2 2 6 2 2 6 2 2 6
39132 - 2 2 6 2 2 6 62 62 62 66 66 66
39133 - 26 26 26 10 10 10 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 0 0 0
39137 - 0 0 0 0 0 0 0 0 0 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 0 0 0
39141 - 0 0 0 0 0 0 0 0 0 10 10 10
39142 - 30 30 30 74 74 74 50 50 50 2 2 6
39143 - 26 26 26 26 26 26 2 2 6 106 106 106
39144 -238 238 238 253 253 253 253 253 253 253 253 253
39145 -253 253 253 253 253 253 253 253 253 253 253 253
39146 -253 253 253 253 253 253 253 253 253 253 253 253
39147 -253 253 253 253 253 253 253 253 253 253 253 253
39148 -253 253 253 253 253 253 253 253 253 253 253 253
39149 -253 253 253 246 246 246 218 218 218 202 202 202
39150 -210 210 210 14 14 14 2 2 6 2 2 6
39151 - 30 30 30 22 22 22 2 2 6 2 2 6
39152 - 2 2 6 2 2 6 18 18 18 86 86 86
39153 - 42 42 42 14 14 14 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 0 0 0 0 0 0
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 0 0 0 0 0 0 0 0 0
39161 - 0 0 0 0 0 0 0 0 0 14 14 14
39162 - 42 42 42 90 90 90 22 22 22 2 2 6
39163 - 42 42 42 2 2 6 18 18 18 218 218 218
39164 -253 253 253 253 253 253 253 253 253 253 253 253
39165 -253 253 253 253 253 253 253 253 253 253 253 253
39166 -253 253 253 253 253 253 253 253 253 253 253 253
39167 -253 253 253 253 253 253 253 253 253 253 253 253
39168 -253 253 253 253 253 253 253 253 253 253 253 253
39169 -253 253 253 253 253 253 250 250 250 221 221 221
39170 -218 218 218 101 101 101 2 2 6 14 14 14
39171 - 18 18 18 38 38 38 10 10 10 2 2 6
39172 - 2 2 6 2 2 6 2 2 6 78 78 78
39173 - 58 58 58 22 22 22 6 6 6 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 0 0 0 0 0 0 0 0 0
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 0 0 0
39181 - 0 0 0 0 0 0 6 6 6 18 18 18
39182 - 54 54 54 82 82 82 2 2 6 26 26 26
39183 - 22 22 22 2 2 6 123 123 123 253 253 253
39184 -253 253 253 253 253 253 253 253 253 253 253 253
39185 -253 253 253 253 253 253 253 253 253 253 253 253
39186 -253 253 253 253 253 253 253 253 253 253 253 253
39187 -253 253 253 253 253 253 253 253 253 253 253 253
39188 -253 253 253 253 253 253 253 253 253 253 253 253
39189 -253 253 253 253 253 253 253 253 253 250 250 250
39190 -238 238 238 198 198 198 6 6 6 38 38 38
39191 - 58 58 58 26 26 26 38 38 38 2 2 6
39192 - 2 2 6 2 2 6 2 2 6 46 46 46
39193 - 78 78 78 30 30 30 10 10 10 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 0 0 0 0 0 0 0
39196 - 0 0 0 0 0 0 0 0 0 0 0 0
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 0 0 0
39201 - 0 0 0 0 0 0 10 10 10 30 30 30
39202 - 74 74 74 58 58 58 2 2 6 42 42 42
39203 - 2 2 6 22 22 22 231 231 231 253 253 253
39204 -253 253 253 253 253 253 253 253 253 253 253 253
39205 -253 253 253 253 253 253 253 253 253 250 250 250
39206 -253 253 253 253 253 253 253 253 253 253 253 253
39207 -253 253 253 253 253 253 253 253 253 253 253 253
39208 -253 253 253 253 253 253 253 253 253 253 253 253
39209 -253 253 253 253 253 253 253 253 253 253 253 253
39210 -253 253 253 246 246 246 46 46 46 38 38 38
39211 - 42 42 42 14 14 14 38 38 38 14 14 14
39212 - 2 2 6 2 2 6 2 2 6 6 6 6
39213 - 86 86 86 46 46 46 14 14 14 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 0 0 0 0 0 0 0 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 6 6 6 14 14 14 42 42 42
39222 - 90 90 90 18 18 18 18 18 18 26 26 26
39223 - 2 2 6 116 116 116 253 253 253 253 253 253
39224 -253 253 253 253 253 253 253 253 253 253 253 253
39225 -253 253 253 253 253 253 250 250 250 238 238 238
39226 -253 253 253 253 253 253 253 253 253 253 253 253
39227 -253 253 253 253 253 253 253 253 253 253 253 253
39228 -253 253 253 253 253 253 253 253 253 253 253 253
39229 -253 253 253 253 253 253 253 253 253 253 253 253
39230 -253 253 253 253 253 253 94 94 94 6 6 6
39231 - 2 2 6 2 2 6 10 10 10 34 34 34
39232 - 2 2 6 2 2 6 2 2 6 2 2 6
39233 - 74 74 74 58 58 58 22 22 22 6 6 6
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 0 0 0 0 0 0 0 0 0 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 10 10 10 26 26 26 66 66 66
39242 - 82 82 82 2 2 6 38 38 38 6 6 6
39243 - 14 14 14 210 210 210 253 253 253 253 253 253
39244 -253 253 253 253 253 253 253 253 253 253 253 253
39245 -253 253 253 253 253 253 246 246 246 242 242 242
39246 -253 253 253 253 253 253 253 253 253 253 253 253
39247 -253 253 253 253 253 253 253 253 253 253 253 253
39248 -253 253 253 253 253 253 253 253 253 253 253 253
39249 -253 253 253 253 253 253 253 253 253 253 253 253
39250 -253 253 253 253 253 253 144 144 144 2 2 6
39251 - 2 2 6 2 2 6 2 2 6 46 46 46
39252 - 2 2 6 2 2 6 2 2 6 2 2 6
39253 - 42 42 42 74 74 74 30 30 30 10 10 10
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 0 0 0 0 0 0 0 0 0 0 0 0
39256 - 0 0 0 0 0 0 0 0 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 6 6 6 14 14 14 42 42 42 90 90 90
39262 - 26 26 26 6 6 6 42 42 42 2 2 6
39263 - 74 74 74 250 250 250 253 253 253 253 253 253
39264 -253 253 253 253 253 253 253 253 253 253 253 253
39265 -253 253 253 253 253 253 242 242 242 242 242 242
39266 -253 253 253 253 253 253 253 253 253 253 253 253
39267 -253 253 253 253 253 253 253 253 253 253 253 253
39268 -253 253 253 253 253 253 253 253 253 253 253 253
39269 -253 253 253 253 253 253 253 253 253 253 253 253
39270 -253 253 253 253 253 253 182 182 182 2 2 6
39271 - 2 2 6 2 2 6 2 2 6 46 46 46
39272 - 2 2 6 2 2 6 2 2 6 2 2 6
39273 - 10 10 10 86 86 86 38 38 38 10 10 10
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 0 0 0 0 0 0 0 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 10 10 10 26 26 26 66 66 66 82 82 82
39282 - 2 2 6 22 22 22 18 18 18 2 2 6
39283 -149 149 149 253 253 253 253 253 253 253 253 253
39284 -253 253 253 253 253 253 253 253 253 253 253 253
39285 -253 253 253 253 253 253 234 234 234 242 242 242
39286 -253 253 253 253 253 253 253 253 253 253 253 253
39287 -253 253 253 253 253 253 253 253 253 253 253 253
39288 -253 253 253 253 253 253 253 253 253 253 253 253
39289 -253 253 253 253 253 253 253 253 253 253 253 253
39290 -253 253 253 253 253 253 206 206 206 2 2 6
39291 - 2 2 6 2 2 6 2 2 6 38 38 38
39292 - 2 2 6 2 2 6 2 2 6 2 2 6
39293 - 6 6 6 86 86 86 46 46 46 14 14 14
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
39296 - 0 0 0 0 0 0 0 0 0 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 6 6 6
39301 - 18 18 18 46 46 46 86 86 86 18 18 18
39302 - 2 2 6 34 34 34 10 10 10 6 6 6
39303 -210 210 210 253 253 253 253 253 253 253 253 253
39304 -253 253 253 253 253 253 253 253 253 253 253 253
39305 -253 253 253 253 253 253 234 234 234 242 242 242
39306 -253 253 253 253 253 253 253 253 253 253 253 253
39307 -253 253 253 253 253 253 253 253 253 253 253 253
39308 -253 253 253 253 253 253 253 253 253 253 253 253
39309 -253 253 253 253 253 253 253 253 253 253 253 253
39310 -253 253 253 253 253 253 221 221 221 6 6 6
39311 - 2 2 6 2 2 6 6 6 6 30 30 30
39312 - 2 2 6 2 2 6 2 2 6 2 2 6
39313 - 2 2 6 82 82 82 54 54 54 18 18 18
39314 - 6 6 6 0 0 0 0 0 0 0 0 0
39315 - 0 0 0 0 0 0 0 0 0 0 0 0
39316 - 0 0 0 0 0 0 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 10 10 10
39321 - 26 26 26 66 66 66 62 62 62 2 2 6
39322 - 2 2 6 38 38 38 10 10 10 26 26 26
39323 -238 238 238 253 253 253 253 253 253 253 253 253
39324 -253 253 253 253 253 253 253 253 253 253 253 253
39325 -253 253 253 253 253 253 231 231 231 238 238 238
39326 -253 253 253 253 253 253 253 253 253 253 253 253
39327 -253 253 253 253 253 253 253 253 253 253 253 253
39328 -253 253 253 253 253 253 253 253 253 253 253 253
39329 -253 253 253 253 253 253 253 253 253 253 253 253
39330 -253 253 253 253 253 253 231 231 231 6 6 6
39331 - 2 2 6 2 2 6 10 10 10 30 30 30
39332 - 2 2 6 2 2 6 2 2 6 2 2 6
39333 - 2 2 6 66 66 66 58 58 58 22 22 22
39334 - 6 6 6 0 0 0 0 0 0 0 0 0
39335 - 0 0 0 0 0 0 0 0 0 0 0 0
39336 - 0 0 0 0 0 0 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 10 10 10
39341 - 38 38 38 78 78 78 6 6 6 2 2 6
39342 - 2 2 6 46 46 46 14 14 14 42 42 42
39343 -246 246 246 253 253 253 253 253 253 253 253 253
39344 -253 253 253 253 253 253 253 253 253 253 253 253
39345 -253 253 253 253 253 253 231 231 231 242 242 242
39346 -253 253 253 253 253 253 253 253 253 253 253 253
39347 -253 253 253 253 253 253 253 253 253 253 253 253
39348 -253 253 253 253 253 253 253 253 253 253 253 253
39349 -253 253 253 253 253 253 253 253 253 253 253 253
39350 -253 253 253 253 253 253 234 234 234 10 10 10
39351 - 2 2 6 2 2 6 22 22 22 14 14 14
39352 - 2 2 6 2 2 6 2 2 6 2 2 6
39353 - 2 2 6 66 66 66 62 62 62 22 22 22
39354 - 6 6 6 0 0 0 0 0 0 0 0 0
39355 - 0 0 0 0 0 0 0 0 0 0 0 0
39356 - 0 0 0 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 6 6 6 18 18 18
39361 - 50 50 50 74 74 74 2 2 6 2 2 6
39362 - 14 14 14 70 70 70 34 34 34 62 62 62
39363 -250 250 250 253 253 253 253 253 253 253 253 253
39364 -253 253 253 253 253 253 253 253 253 253 253 253
39365 -253 253 253 253 253 253 231 231 231 246 246 246
39366 -253 253 253 253 253 253 253 253 253 253 253 253
39367 -253 253 253 253 253 253 253 253 253 253 253 253
39368 -253 253 253 253 253 253 253 253 253 253 253 253
39369 -253 253 253 253 253 253 253 253 253 253 253 253
39370 -253 253 253 253 253 253 234 234 234 14 14 14
39371 - 2 2 6 2 2 6 30 30 30 2 2 6
39372 - 2 2 6 2 2 6 2 2 6 2 2 6
39373 - 2 2 6 66 66 66 62 62 62 22 22 22
39374 - 6 6 6 0 0 0 0 0 0 0 0 0
39375 - 0 0 0 0 0 0 0 0 0 0 0 0
39376 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 6 6 6 18 18 18
39381 - 54 54 54 62 62 62 2 2 6 2 2 6
39382 - 2 2 6 30 30 30 46 46 46 70 70 70
39383 -250 250 250 253 253 253 253 253 253 253 253 253
39384 -253 253 253 253 253 253 253 253 253 253 253 253
39385 -253 253 253 253 253 253 231 231 231 246 246 246
39386 -253 253 253 253 253 253 253 253 253 253 253 253
39387 -253 253 253 253 253 253 253 253 253 253 253 253
39388 -253 253 253 253 253 253 253 253 253 253 253 253
39389 -253 253 253 253 253 253 253 253 253 253 253 253
39390 -253 253 253 253 253 253 226 226 226 10 10 10
39391 - 2 2 6 6 6 6 30 30 30 2 2 6
39392 - 2 2 6 2 2 6 2 2 6 2 2 6
39393 - 2 2 6 66 66 66 58 58 58 22 22 22
39394 - 6 6 6 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 0 0 0
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 6 6 6 22 22 22
39401 - 58 58 58 62 62 62 2 2 6 2 2 6
39402 - 2 2 6 2 2 6 30 30 30 78 78 78
39403 -250 250 250 253 253 253 253 253 253 253 253 253
39404 -253 253 253 253 253 253 253 253 253 253 253 253
39405 -253 253 253 253 253 253 231 231 231 246 246 246
39406 -253 253 253 253 253 253 253 253 253 253 253 253
39407 -253 253 253 253 253 253 253 253 253 253 253 253
39408 -253 253 253 253 253 253 253 253 253 253 253 253
39409 -253 253 253 253 253 253 253 253 253 253 253 253
39410 -253 253 253 253 253 253 206 206 206 2 2 6
39411 - 22 22 22 34 34 34 18 14 6 22 22 22
39412 - 26 26 26 18 18 18 6 6 6 2 2 6
39413 - 2 2 6 82 82 82 54 54 54 18 18 18
39414 - 6 6 6 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 0 0 0
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 6 6 6 26 26 26
39421 - 62 62 62 106 106 106 74 54 14 185 133 11
39422 -210 162 10 121 92 8 6 6 6 62 62 62
39423 -238 238 238 253 253 253 253 253 253 253 253 253
39424 -253 253 253 253 253 253 253 253 253 253 253 253
39425 -253 253 253 253 253 253 231 231 231 246 246 246
39426 -253 253 253 253 253 253 253 253 253 253 253 253
39427 -253 253 253 253 253 253 253 253 253 253 253 253
39428 -253 253 253 253 253 253 253 253 253 253 253 253
39429 -253 253 253 253 253 253 253 253 253 253 253 253
39430 -253 253 253 253 253 253 158 158 158 18 18 18
39431 - 14 14 14 2 2 6 2 2 6 2 2 6
39432 - 6 6 6 18 18 18 66 66 66 38 38 38
39433 - 6 6 6 94 94 94 50 50 50 18 18 18
39434 - 6 6 6 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 0 0 0 0 0 0
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 6 6 6
39440 - 10 10 10 10 10 10 18 18 18 38 38 38
39441 - 78 78 78 142 134 106 216 158 10 242 186 14
39442 -246 190 14 246 190 14 156 118 10 10 10 10
39443 - 90 90 90 238 238 238 253 253 253 253 253 253
39444 -253 253 253 253 253 253 253 253 253 253 253 253
39445 -253 253 253 253 253 253 231 231 231 250 250 250
39446 -253 253 253 253 253 253 253 253 253 253 253 253
39447 -253 253 253 253 253 253 253 253 253 253 253 253
39448 -253 253 253 253 253 253 253 253 253 253 253 253
39449 -253 253 253 253 253 253 253 253 253 246 230 190
39450 -238 204 91 238 204 91 181 142 44 37 26 9
39451 - 2 2 6 2 2 6 2 2 6 2 2 6
39452 - 2 2 6 2 2 6 38 38 38 46 46 46
39453 - 26 26 26 106 106 106 54 54 54 18 18 18
39454 - 6 6 6 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 0 0 0 0 0 0 0 0 0
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 6 6 6 14 14 14 22 22 22
39460 - 30 30 30 38 38 38 50 50 50 70 70 70
39461 -106 106 106 190 142 34 226 170 11 242 186 14
39462 -246 190 14 246 190 14 246 190 14 154 114 10
39463 - 6 6 6 74 74 74 226 226 226 253 253 253
39464 -253 253 253 253 253 253 253 253 253 253 253 253
39465 -253 253 253 253 253 253 231 231 231 250 250 250
39466 -253 253 253 253 253 253 253 253 253 253 253 253
39467 -253 253 253 253 253 253 253 253 253 253 253 253
39468 -253 253 253 253 253 253 253 253 253 253 253 253
39469 -253 253 253 253 253 253 253 253 253 228 184 62
39470 -241 196 14 241 208 19 232 195 16 38 30 10
39471 - 2 2 6 2 2 6 2 2 6 2 2 6
39472 - 2 2 6 6 6 6 30 30 30 26 26 26
39473 -203 166 17 154 142 90 66 66 66 26 26 26
39474 - 6 6 6 0 0 0 0 0 0 0 0 0
39475 - 0 0 0 0 0 0 0 0 0 0 0 0
39476 - 0 0 0 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 6 6 6 18 18 18 38 38 38 58 58 58
39480 - 78 78 78 86 86 86 101 101 101 123 123 123
39481 -175 146 61 210 150 10 234 174 13 246 186 14
39482 -246 190 14 246 190 14 246 190 14 238 190 10
39483 -102 78 10 2 2 6 46 46 46 198 198 198
39484 -253 253 253 253 253 253 253 253 253 253 253 253
39485 -253 253 253 253 253 253 234 234 234 242 242 242
39486 -253 253 253 253 253 253 253 253 253 253 253 253
39487 -253 253 253 253 253 253 253 253 253 253 253 253
39488 -253 253 253 253 253 253 253 253 253 253 253 253
39489 -253 253 253 253 253 253 253 253 253 224 178 62
39490 -242 186 14 241 196 14 210 166 10 22 18 6
39491 - 2 2 6 2 2 6 2 2 6 2 2 6
39492 - 2 2 6 2 2 6 6 6 6 121 92 8
39493 -238 202 15 232 195 16 82 82 82 34 34 34
39494 - 10 10 10 0 0 0 0 0 0 0 0 0
39495 - 0 0 0 0 0 0 0 0 0 0 0 0
39496 - 0 0 0 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 14 14 14 38 38 38 70 70 70 154 122 46
39500 -190 142 34 200 144 11 197 138 11 197 138 11
39501 -213 154 11 226 170 11 242 186 14 246 190 14
39502 -246 190 14 246 190 14 246 190 14 246 190 14
39503 -225 175 15 46 32 6 2 2 6 22 22 22
39504 -158 158 158 250 250 250 253 253 253 253 253 253
39505 -253 253 253 253 253 253 253 253 253 253 253 253
39506 -253 253 253 253 253 253 253 253 253 253 253 253
39507 -253 253 253 253 253 253 253 253 253 253 253 253
39508 -253 253 253 253 253 253 253 253 253 253 253 253
39509 -253 253 253 250 250 250 242 242 242 224 178 62
39510 -239 182 13 236 186 11 213 154 11 46 32 6
39511 - 2 2 6 2 2 6 2 2 6 2 2 6
39512 - 2 2 6 2 2 6 61 42 6 225 175 15
39513 -238 190 10 236 186 11 112 100 78 42 42 42
39514 - 14 14 14 0 0 0 0 0 0 0 0 0
39515 - 0 0 0 0 0 0 0 0 0 0 0 0
39516 - 0 0 0 0 0 0 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 6 6 6
39519 - 22 22 22 54 54 54 154 122 46 213 154 11
39520 -226 170 11 230 174 11 226 170 11 226 170 11
39521 -236 178 12 242 186 14 246 190 14 246 190 14
39522 -246 190 14 246 190 14 246 190 14 246 190 14
39523 -241 196 14 184 144 12 10 10 10 2 2 6
39524 - 6 6 6 116 116 116 242 242 242 253 253 253
39525 -253 253 253 253 253 253 253 253 253 253 253 253
39526 -253 253 253 253 253 253 253 253 253 253 253 253
39527 -253 253 253 253 253 253 253 253 253 253 253 253
39528 -253 253 253 253 253 253 253 253 253 253 253 253
39529 -253 253 253 231 231 231 198 198 198 214 170 54
39530 -236 178 12 236 178 12 210 150 10 137 92 6
39531 - 18 14 6 2 2 6 2 2 6 2 2 6
39532 - 6 6 6 70 47 6 200 144 11 236 178 12
39533 -239 182 13 239 182 13 124 112 88 58 58 58
39534 - 22 22 22 6 6 6 0 0 0 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 10 10 10
39539 - 30 30 30 70 70 70 180 133 36 226 170 11
39540 -239 182 13 242 186 14 242 186 14 246 186 14
39541 -246 190 14 246 190 14 246 190 14 246 190 14
39542 -246 190 14 246 190 14 246 190 14 246 190 14
39543 -246 190 14 232 195 16 98 70 6 2 2 6
39544 - 2 2 6 2 2 6 66 66 66 221 221 221
39545 -253 253 253 253 253 253 253 253 253 253 253 253
39546 -253 253 253 253 253 253 253 253 253 253 253 253
39547 -253 253 253 253 253 253 253 253 253 253 253 253
39548 -253 253 253 253 253 253 253 253 253 253 253 253
39549 -253 253 253 206 206 206 198 198 198 214 166 58
39550 -230 174 11 230 174 11 216 158 10 192 133 9
39551 -163 110 8 116 81 8 102 78 10 116 81 8
39552 -167 114 7 197 138 11 226 170 11 239 182 13
39553 -242 186 14 242 186 14 162 146 94 78 78 78
39554 - 34 34 34 14 14 14 6 6 6 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 6 6 6
39559 - 30 30 30 78 78 78 190 142 34 226 170 11
39560 -239 182 13 246 190 14 246 190 14 246 190 14
39561 -246 190 14 246 190 14 246 190 14 246 190 14
39562 -246 190 14 246 190 14 246 190 14 246 190 14
39563 -246 190 14 241 196 14 203 166 17 22 18 6
39564 - 2 2 6 2 2 6 2 2 6 38 38 38
39565 -218 218 218 253 253 253 253 253 253 253 253 253
39566 -253 253 253 253 253 253 253 253 253 253 253 253
39567 -253 253 253 253 253 253 253 253 253 253 253 253
39568 -253 253 253 253 253 253 253 253 253 253 253 253
39569 -250 250 250 206 206 206 198 198 198 202 162 69
39570 -226 170 11 236 178 12 224 166 10 210 150 10
39571 -200 144 11 197 138 11 192 133 9 197 138 11
39572 -210 150 10 226 170 11 242 186 14 246 190 14
39573 -246 190 14 246 186 14 225 175 15 124 112 88
39574 - 62 62 62 30 30 30 14 14 14 6 6 6
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 10 10 10
39579 - 30 30 30 78 78 78 174 135 50 224 166 10
39580 -239 182 13 246 190 14 246 190 14 246 190 14
39581 -246 190 14 246 190 14 246 190 14 246 190 14
39582 -246 190 14 246 190 14 246 190 14 246 190 14
39583 -246 190 14 246 190 14 241 196 14 139 102 15
39584 - 2 2 6 2 2 6 2 2 6 2 2 6
39585 - 78 78 78 250 250 250 253 253 253 253 253 253
39586 -253 253 253 253 253 253 253 253 253 253 253 253
39587 -253 253 253 253 253 253 253 253 253 253 253 253
39588 -253 253 253 253 253 253 253 253 253 253 253 253
39589 -250 250 250 214 214 214 198 198 198 190 150 46
39590 -219 162 10 236 178 12 234 174 13 224 166 10
39591 -216 158 10 213 154 11 213 154 11 216 158 10
39592 -226 170 11 239 182 13 246 190 14 246 190 14
39593 -246 190 14 246 190 14 242 186 14 206 162 42
39594 -101 101 101 58 58 58 30 30 30 14 14 14
39595 - 6 6 6 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 10 10 10
39599 - 30 30 30 74 74 74 174 135 50 216 158 10
39600 -236 178 12 246 190 14 246 190 14 246 190 14
39601 -246 190 14 246 190 14 246 190 14 246 190 14
39602 -246 190 14 246 190 14 246 190 14 246 190 14
39603 -246 190 14 246 190 14 241 196 14 226 184 13
39604 - 61 42 6 2 2 6 2 2 6 2 2 6
39605 - 22 22 22 238 238 238 253 253 253 253 253 253
39606 -253 253 253 253 253 253 253 253 253 253 253 253
39607 -253 253 253 253 253 253 253 253 253 253 253 253
39608 -253 253 253 253 253 253 253 253 253 253 253 253
39609 -253 253 253 226 226 226 187 187 187 180 133 36
39610 -216 158 10 236 178 12 239 182 13 236 178 12
39611 -230 174 11 226 170 11 226 170 11 230 174 11
39612 -236 178 12 242 186 14 246 190 14 246 190 14
39613 -246 190 14 246 190 14 246 186 14 239 182 13
39614 -206 162 42 106 106 106 66 66 66 34 34 34
39615 - 14 14 14 6 6 6 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 6 6 6
39619 - 26 26 26 70 70 70 163 133 67 213 154 11
39620 -236 178 12 246 190 14 246 190 14 246 190 14
39621 -246 190 14 246 190 14 246 190 14 246 190 14
39622 -246 190 14 246 190 14 246 190 14 246 190 14
39623 -246 190 14 246 190 14 246 190 14 241 196 14
39624 -190 146 13 18 14 6 2 2 6 2 2 6
39625 - 46 46 46 246 246 246 253 253 253 253 253 253
39626 -253 253 253 253 253 253 253 253 253 253 253 253
39627 -253 253 253 253 253 253 253 253 253 253 253 253
39628 -253 253 253 253 253 253 253 253 253 253 253 253
39629 -253 253 253 221 221 221 86 86 86 156 107 11
39630 -216 158 10 236 178 12 242 186 14 246 186 14
39631 -242 186 14 239 182 13 239 182 13 242 186 14
39632 -242 186 14 246 186 14 246 190 14 246 190 14
39633 -246 190 14 246 190 14 246 190 14 246 190 14
39634 -242 186 14 225 175 15 142 122 72 66 66 66
39635 - 30 30 30 10 10 10 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 6 6 6
39639 - 26 26 26 70 70 70 163 133 67 210 150 10
39640 -236 178 12 246 190 14 246 190 14 246 190 14
39641 -246 190 14 246 190 14 246 190 14 246 190 14
39642 -246 190 14 246 190 14 246 190 14 246 190 14
39643 -246 190 14 246 190 14 246 190 14 246 190 14
39644 -232 195 16 121 92 8 34 34 34 106 106 106
39645 -221 221 221 253 253 253 253 253 253 253 253 253
39646 -253 253 253 253 253 253 253 253 253 253 253 253
39647 -253 253 253 253 253 253 253 253 253 253 253 253
39648 -253 253 253 253 253 253 253 253 253 253 253 253
39649 -242 242 242 82 82 82 18 14 6 163 110 8
39650 -216 158 10 236 178 12 242 186 14 246 190 14
39651 -246 190 14 246 190 14 246 190 14 246 190 14
39652 -246 190 14 246 190 14 246 190 14 246 190 14
39653 -246 190 14 246 190 14 246 190 14 246 190 14
39654 -246 190 14 246 190 14 242 186 14 163 133 67
39655 - 46 46 46 18 18 18 6 6 6 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 10 10 10
39659 - 30 30 30 78 78 78 163 133 67 210 150 10
39660 -236 178 12 246 186 14 246 190 14 246 190 14
39661 -246 190 14 246 190 14 246 190 14 246 190 14
39662 -246 190 14 246 190 14 246 190 14 246 190 14
39663 -246 190 14 246 190 14 246 190 14 246 190 14
39664 -241 196 14 215 174 15 190 178 144 253 253 253
39665 -253 253 253 253 253 253 253 253 253 253 253 253
39666 -253 253 253 253 253 253 253 253 253 253 253 253
39667 -253 253 253 253 253 253 253 253 253 253 253 253
39668 -253 253 253 253 253 253 253 253 253 218 218 218
39669 - 58 58 58 2 2 6 22 18 6 167 114 7
39670 -216 158 10 236 178 12 246 186 14 246 190 14
39671 -246 190 14 246 190 14 246 190 14 246 190 14
39672 -246 190 14 246 190 14 246 190 14 246 190 14
39673 -246 190 14 246 190 14 246 190 14 246 190 14
39674 -246 190 14 246 186 14 242 186 14 190 150 46
39675 - 54 54 54 22 22 22 6 6 6 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 14 14 14
39679 - 38 38 38 86 86 86 180 133 36 213 154 11
39680 -236 178 12 246 186 14 246 190 14 246 190 14
39681 -246 190 14 246 190 14 246 190 14 246 190 14
39682 -246 190 14 246 190 14 246 190 14 246 190 14
39683 -246 190 14 246 190 14 246 190 14 246 190 14
39684 -246 190 14 232 195 16 190 146 13 214 214 214
39685 -253 253 253 253 253 253 253 253 253 253 253 253
39686 -253 253 253 253 253 253 253 253 253 253 253 253
39687 -253 253 253 253 253 253 253 253 253 253 253 253
39688 -253 253 253 250 250 250 170 170 170 26 26 26
39689 - 2 2 6 2 2 6 37 26 9 163 110 8
39690 -219 162 10 239 182 13 246 186 14 246 190 14
39691 -246 190 14 246 190 14 246 190 14 246 190 14
39692 -246 190 14 246 190 14 246 190 14 246 190 14
39693 -246 190 14 246 190 14 246 190 14 246 190 14
39694 -246 186 14 236 178 12 224 166 10 142 122 72
39695 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
39699 - 50 50 50 109 106 95 192 133 9 224 166 10
39700 -242 186 14 246 190 14 246 190 14 246 190 14
39701 -246 190 14 246 190 14 246 190 14 246 190 14
39702 -246 190 14 246 190 14 246 190 14 246 190 14
39703 -246 190 14 246 190 14 246 190 14 246 190 14
39704 -242 186 14 226 184 13 210 162 10 142 110 46
39705 -226 226 226 253 253 253 253 253 253 253 253 253
39706 -253 253 253 253 253 253 253 253 253 253 253 253
39707 -253 253 253 253 253 253 253 253 253 253 253 253
39708 -198 198 198 66 66 66 2 2 6 2 2 6
39709 - 2 2 6 2 2 6 50 34 6 156 107 11
39710 -219 162 10 239 182 13 246 186 14 246 190 14
39711 -246 190 14 246 190 14 246 190 14 246 190 14
39712 -246 190 14 246 190 14 246 190 14 246 190 14
39713 -246 190 14 246 190 14 246 190 14 242 186 14
39714 -234 174 13 213 154 11 154 122 46 66 66 66
39715 - 30 30 30 10 10 10 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 6 6 6 22 22 22
39719 - 58 58 58 154 121 60 206 145 10 234 174 13
39720 -242 186 14 246 186 14 246 190 14 246 190 14
39721 -246 190 14 246 190 14 246 190 14 246 190 14
39722 -246 190 14 246 190 14 246 190 14 246 190 14
39723 -246 190 14 246 190 14 246 190 14 246 190 14
39724 -246 186 14 236 178 12 210 162 10 163 110 8
39725 - 61 42 6 138 138 138 218 218 218 250 250 250
39726 -253 253 253 253 253 253 253 253 253 250 250 250
39727 -242 242 242 210 210 210 144 144 144 66 66 66
39728 - 6 6 6 2 2 6 2 2 6 2 2 6
39729 - 2 2 6 2 2 6 61 42 6 163 110 8
39730 -216 158 10 236 178 12 246 190 14 246 190 14
39731 -246 190 14 246 190 14 246 190 14 246 190 14
39732 -246 190 14 246 190 14 246 190 14 246 190 14
39733 -246 190 14 239 182 13 230 174 11 216 158 10
39734 -190 142 34 124 112 88 70 70 70 38 38 38
39735 - 18 18 18 6 6 6 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 6 6 6 22 22 22
39739 - 62 62 62 168 124 44 206 145 10 224 166 10
39740 -236 178 12 239 182 13 242 186 14 242 186 14
39741 -246 186 14 246 190 14 246 190 14 246 190 14
39742 -246 190 14 246 190 14 246 190 14 246 190 14
39743 -246 190 14 246 190 14 246 190 14 246 190 14
39744 -246 190 14 236 178 12 216 158 10 175 118 6
39745 - 80 54 7 2 2 6 6 6 6 30 30 30
39746 - 54 54 54 62 62 62 50 50 50 38 38 38
39747 - 14 14 14 2 2 6 2 2 6 2 2 6
39748 - 2 2 6 2 2 6 2 2 6 2 2 6
39749 - 2 2 6 6 6 6 80 54 7 167 114 7
39750 -213 154 11 236 178 12 246 190 14 246 190 14
39751 -246 190 14 246 190 14 246 190 14 246 190 14
39752 -246 190 14 242 186 14 239 182 13 239 182 13
39753 -230 174 11 210 150 10 174 135 50 124 112 88
39754 - 82 82 82 54 54 54 34 34 34 18 18 18
39755 - 6 6 6 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 6 6 6 18 18 18
39759 - 50 50 50 158 118 36 192 133 9 200 144 11
39760 -216 158 10 219 162 10 224 166 10 226 170 11
39761 -230 174 11 236 178 12 239 182 13 239 182 13
39762 -242 186 14 246 186 14 246 190 14 246 190 14
39763 -246 190 14 246 190 14 246 190 14 246 190 14
39764 -246 186 14 230 174 11 210 150 10 163 110 8
39765 -104 69 6 10 10 10 2 2 6 2 2 6
39766 - 2 2 6 2 2 6 2 2 6 2 2 6
39767 - 2 2 6 2 2 6 2 2 6 2 2 6
39768 - 2 2 6 2 2 6 2 2 6 2 2 6
39769 - 2 2 6 6 6 6 91 60 6 167 114 7
39770 -206 145 10 230 174 11 242 186 14 246 190 14
39771 -246 190 14 246 190 14 246 186 14 242 186 14
39772 -239 182 13 230 174 11 224 166 10 213 154 11
39773 -180 133 36 124 112 88 86 86 86 58 58 58
39774 - 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
39779 - 34 34 34 70 70 70 138 110 50 158 118 36
39780 -167 114 7 180 123 7 192 133 9 197 138 11
39781 -200 144 11 206 145 10 213 154 11 219 162 10
39782 -224 166 10 230 174 11 239 182 13 242 186 14
39783 -246 186 14 246 186 14 246 186 14 246 186 14
39784 -239 182 13 216 158 10 185 133 11 152 99 6
39785 -104 69 6 18 14 6 2 2 6 2 2 6
39786 - 2 2 6 2 2 6 2 2 6 2 2 6
39787 - 2 2 6 2 2 6 2 2 6 2 2 6
39788 - 2 2 6 2 2 6 2 2 6 2 2 6
39789 - 2 2 6 6 6 6 80 54 7 152 99 6
39790 -192 133 9 219 162 10 236 178 12 239 182 13
39791 -246 186 14 242 186 14 239 182 13 236 178 12
39792 -224 166 10 206 145 10 192 133 9 154 121 60
39793 - 94 94 94 62 62 62 42 42 42 22 22 22
39794 - 14 14 14 6 6 6 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 6 6 6
39799 - 18 18 18 34 34 34 58 58 58 78 78 78
39800 -101 98 89 124 112 88 142 110 46 156 107 11
39801 -163 110 8 167 114 7 175 118 6 180 123 7
39802 -185 133 11 197 138 11 210 150 10 219 162 10
39803 -226 170 11 236 178 12 236 178 12 234 174 13
39804 -219 162 10 197 138 11 163 110 8 130 83 6
39805 - 91 60 6 10 10 10 2 2 6 2 2 6
39806 - 18 18 18 38 38 38 38 38 38 38 38 38
39807 - 38 38 38 38 38 38 38 38 38 38 38 38
39808 - 38 38 38 38 38 38 26 26 26 2 2 6
39809 - 2 2 6 6 6 6 70 47 6 137 92 6
39810 -175 118 6 200 144 11 219 162 10 230 174 11
39811 -234 174 13 230 174 11 219 162 10 210 150 10
39812 -192 133 9 163 110 8 124 112 88 82 82 82
39813 - 50 50 50 30 30 30 14 14 14 6 6 6
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 6 6 6 14 14 14 22 22 22 34 34 34
39820 - 42 42 42 58 58 58 74 74 74 86 86 86
39821 -101 98 89 122 102 70 130 98 46 121 87 25
39822 -137 92 6 152 99 6 163 110 8 180 123 7
39823 -185 133 11 197 138 11 206 145 10 200 144 11
39824 -180 123 7 156 107 11 130 83 6 104 69 6
39825 - 50 34 6 54 54 54 110 110 110 101 98 89
39826 - 86 86 86 82 82 82 78 78 78 78 78 78
39827 - 78 78 78 78 78 78 78 78 78 78 78 78
39828 - 78 78 78 82 82 82 86 86 86 94 94 94
39829 -106 106 106 101 101 101 86 66 34 124 80 6
39830 -156 107 11 180 123 7 192 133 9 200 144 11
39831 -206 145 10 200 144 11 192 133 9 175 118 6
39832 -139 102 15 109 106 95 70 70 70 42 42 42
39833 - 22 22 22 10 10 10 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 6 6 6 10 10 10
39840 - 14 14 14 22 22 22 30 30 30 38 38 38
39841 - 50 50 50 62 62 62 74 74 74 90 90 90
39842 -101 98 89 112 100 78 121 87 25 124 80 6
39843 -137 92 6 152 99 6 152 99 6 152 99 6
39844 -138 86 6 124 80 6 98 70 6 86 66 30
39845 -101 98 89 82 82 82 58 58 58 46 46 46
39846 - 38 38 38 34 34 34 34 34 34 34 34 34
39847 - 34 34 34 34 34 34 34 34 34 34 34 34
39848 - 34 34 34 34 34 34 38 38 38 42 42 42
39849 - 54 54 54 82 82 82 94 86 76 91 60 6
39850 -134 86 6 156 107 11 167 114 7 175 118 6
39851 -175 118 6 167 114 7 152 99 6 121 87 25
39852 -101 98 89 62 62 62 34 34 34 18 18 18
39853 - 6 6 6 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 6 6 6 6 6 6 10 10 10
39861 - 18 18 18 22 22 22 30 30 30 42 42 42
39862 - 50 50 50 66 66 66 86 86 86 101 98 89
39863 -106 86 58 98 70 6 104 69 6 104 69 6
39864 -104 69 6 91 60 6 82 62 34 90 90 90
39865 - 62 62 62 38 38 38 22 22 22 14 14 14
39866 - 10 10 10 10 10 10 10 10 10 10 10 10
39867 - 10 10 10 10 10 10 6 6 6 10 10 10
39868 - 10 10 10 10 10 10 10 10 10 14 14 14
39869 - 22 22 22 42 42 42 70 70 70 89 81 66
39870 - 80 54 7 104 69 6 124 80 6 137 92 6
39871 -134 86 6 116 81 8 100 82 52 86 86 86
39872 - 58 58 58 30 30 30 14 14 14 6 6 6
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 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 6 6 6 10 10 10 14 14 14
39882 - 18 18 18 26 26 26 38 38 38 54 54 54
39883 - 70 70 70 86 86 86 94 86 76 89 81 66
39884 - 89 81 66 86 86 86 74 74 74 50 50 50
39885 - 30 30 30 14 14 14 6 6 6 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 6 6 6 18 18 18 34 34 34 58 58 58
39890 - 82 82 82 89 81 66 89 81 66 89 81 66
39891 - 94 86 66 94 86 76 74 74 74 50 50 50
39892 - 26 26 26 14 14 14 6 6 6 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 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 - 6 6 6 6 6 6 14 14 14 18 18 18
39903 - 30 30 30 38 38 38 46 46 46 54 54 54
39904 - 50 50 50 42 42 42 30 30 30 18 18 18
39905 - 10 10 10 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 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 6 6 6 14 14 14 26 26 26
39910 - 38 38 38 50 50 50 58 58 58 58 58 58
39911 - 54 54 54 42 42 42 30 30 30 18 18 18
39912 - 10 10 10 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 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 0 0 0 0 6 6 6
39923 - 6 6 6 10 10 10 14 14 14 18 18 18
39924 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 6 6 6
39930 - 14 14 14 18 18 18 22 22 22 22 22 22
39931 - 18 18 18 14 14 14 10 10 10 6 6 6
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39950 +4 4 4 4 4 4
39951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39964 +4 4 4 4 4 4
39965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39978 +4 4 4 4 4 4
39979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39992 +4 4 4 4 4 4
39993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40006 +4 4 4 4 4 4
40007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40020 +4 4 4 4 4 4
40021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40025 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40026 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40030 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40031 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40032 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40034 +4 4 4 4 4 4
40035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40039 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40040 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40041 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40044 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40045 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40046 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40047 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40048 +4 4 4 4 4 4
40049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40053 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40054 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40055 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40058 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40059 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40060 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40061 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40062 +4 4 4 4 4 4
40063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40066 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40067 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40068 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40069 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40071 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40072 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40073 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40074 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40075 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40076 +4 4 4 4 4 4
40077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40080 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40081 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40082 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40083 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40084 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40085 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40086 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40087 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40088 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40089 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40090 +4 4 4 4 4 4
40091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40094 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40095 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40096 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40097 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40098 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40099 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40100 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40101 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40102 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40103 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40104 +4 4 4 4 4 4
40105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40107 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40108 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40109 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40110 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40111 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40112 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40113 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40114 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40115 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40116 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40117 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40118 +4 4 4 4 4 4
40119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40121 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40122 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40123 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40124 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40125 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40126 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40127 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40128 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40129 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40130 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40131 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40132 +4 4 4 4 4 4
40133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40135 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40136 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40137 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40138 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40139 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40140 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40141 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40142 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40143 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40144 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40145 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40146 +4 4 4 4 4 4
40147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40149 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40150 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40151 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40152 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40153 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40154 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40155 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40156 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40157 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40158 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40159 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40160 +4 4 4 4 4 4
40161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40162 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40163 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40164 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40165 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40166 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40167 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40168 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40169 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40170 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40171 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40172 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40173 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40174 +4 4 4 4 4 4
40175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40176 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40177 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40178 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40179 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40180 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40181 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40182 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40183 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40184 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40185 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40186 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40187 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40188 +0 0 0 4 4 4
40189 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40190 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40191 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40192 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40193 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40194 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40195 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40196 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40197 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40198 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40199 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40200 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40201 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40202 +2 0 0 0 0 0
40203 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40204 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40205 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40206 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40207 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40208 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40209 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40210 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40211 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40212 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40213 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40214 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40215 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40216 +37 38 37 0 0 0
40217 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40218 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40219 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40220 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40221 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40222 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40223 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40224 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40225 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40226 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40227 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40228 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40229 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40230 +85 115 134 4 0 0
40231 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40232 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40233 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40234 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40235 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40236 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40237 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40238 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40239 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40240 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40241 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40242 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40243 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40244 +60 73 81 4 0 0
40245 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40246 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40247 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40248 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40249 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40250 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40251 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40252 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40253 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40254 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40255 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40256 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40257 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40258 +16 19 21 4 0 0
40259 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40260 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40261 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40262 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40263 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40264 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40265 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40266 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40267 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40268 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40269 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40270 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40271 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40272 +4 0 0 4 3 3
40273 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40274 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40275 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40277 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40278 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40279 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40280 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40281 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40282 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40283 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40284 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40285 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40286 +3 2 2 4 4 4
40287 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40288 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40289 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40290 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40291 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40292 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40293 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40294 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40295 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40296 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40297 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40298 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40299 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40300 +4 4 4 4 4 4
40301 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40302 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40303 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40304 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40305 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40306 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40307 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40308 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40309 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40310 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40311 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40312 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40313 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40314 +4 4 4 4 4 4
40315 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40316 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40317 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40318 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40319 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40320 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40321 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40322 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40323 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40324 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40325 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40326 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40327 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40328 +5 5 5 5 5 5
40329 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40330 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40331 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40332 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40333 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40334 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40335 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40336 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40337 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40338 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40339 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40340 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40341 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40342 +5 5 5 4 4 4
40343 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40344 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40345 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40346 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40347 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40348 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40349 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40350 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40351 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40352 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40353 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40354 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40356 +4 4 4 4 4 4
40357 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40358 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40359 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40360 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40361 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40362 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40363 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40364 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40365 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40366 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40367 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40368 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40370 +4 4 4 4 4 4
40371 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40372 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40373 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40374 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40375 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40376 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40377 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40378 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40379 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40380 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40381 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40384 +4 4 4 4 4 4
40385 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40386 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40387 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40388 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40389 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40390 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40391 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40392 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40393 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40394 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40395 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398 +4 4 4 4 4 4
40399 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40400 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40401 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40402 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40403 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40404 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40405 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40406 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40407 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40408 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40409 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4
40413 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40414 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40415 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40416 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40417 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40418 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40419 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40420 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40421 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40422 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40423 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4
40427 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40428 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40429 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40430 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40431 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40432 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40433 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40434 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40435 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40436 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40437 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440 +4 4 4 4 4 4
40441 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40442 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40443 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40444 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40445 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40446 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40447 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40448 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40449 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40450 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40451 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454 +4 4 4 4 4 4
40455 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40456 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40457 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40458 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40459 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40460 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40461 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40462 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40463 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40464 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40465 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40468 +4 4 4 4 4 4
40469 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40470 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40471 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40472 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40473 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40474 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40475 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40476 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40477 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40478 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40479 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482 +4 4 4 4 4 4
40483 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40484 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40485 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40486 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40487 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40488 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40489 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40490 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40491 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40492 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40493 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496 +4 4 4 4 4 4
40497 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40498 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40499 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40500 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40501 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40502 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40503 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40504 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40505 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40506 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40507 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4
40511 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40512 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40513 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40514 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40515 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40516 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40517 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40518 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40519 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40520 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40521 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524 +4 4 4 4 4 4
40525 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40526 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40527 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40528 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40529 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40530 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40531 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40532 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40533 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40534 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40535 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40538 +4 4 4 4 4 4
40539 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40540 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40541 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40542 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40543 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40544 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40545 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40546 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40547 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40548 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40549 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40552 +4 4 4 4 4 4
40553 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40554 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40555 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40556 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40557 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40558 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40559 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40560 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40561 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40562 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40563 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40566 +4 4 4 4 4 4
40567 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40568 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40569 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40570 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40571 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40572 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40573 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40574 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40575 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40576 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40577 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40580 +4 4 4 4 4 4
40581 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40582 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40583 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40584 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40585 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40586 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40587 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40588 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40589 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40590 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40591 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40594 +4 4 4 4 4 4
40595 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40596 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40597 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40598 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40599 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40600 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40601 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40602 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40603 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40604 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40605 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40608 +4 4 4 4 4 4
40609 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40610 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40611 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40612 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40613 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40614 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40615 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40616 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40617 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40618 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40619 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40622 +4 4 4 4 4 4
40623 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40624 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40625 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40626 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40627 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40628 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40629 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40630 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40631 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40632 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40633 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40636 +4 4 4 4 4 4
40637 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40638 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40639 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40640 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40641 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40642 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40643 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40644 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40645 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40646 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40647 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40650 +4 4 4 4 4 4
40651 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40652 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40653 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40654 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40655 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40656 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40657 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40658 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40659 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40660 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40661 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40664 +4 4 4 4 4 4
40665 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40666 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40667 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40668 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40669 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40670 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40671 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40672 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40673 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40674 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40675 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40678 +4 4 4 4 4 4
40679 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40680 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40681 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40682 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40683 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40684 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40685 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40686 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40687 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40688 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40689 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40692 +4 4 4 4 4 4
40693 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40694 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40695 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40696 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40697 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40698 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40699 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40700 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40701 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40702 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40703 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40706 +4 4 4 4 4 4
40707 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40708 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40709 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40710 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40711 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40712 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40713 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40714 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40715 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40716 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40717 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720 +4 4 4 4 4 4
40721 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40722 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40723 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40724 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40725 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40726 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40727 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40728 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40729 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40730 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40731 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734 +4 4 4 4 4 4
40735 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40736 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40737 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40738 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40739 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40740 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40741 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40742 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40743 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40744 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40745 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748 +4 4 4 4 4 4
40749 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40750 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40751 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40752 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40753 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40754 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40755 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40756 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40757 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40758 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762 +4 4 4 4 4 4
40763 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40764 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40765 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40766 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40767 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40768 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40769 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40770 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40771 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40772 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40776 +4 4 4 4 4 4
40777 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40778 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40779 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40780 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40781 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40782 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40783 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40784 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40785 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40786 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40790 +4 4 4 4 4 4
40791 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40792 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40793 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40794 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40795 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40796 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40797 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40798 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40799 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40800 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40804 +4 4 4 4 4 4
40805 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40806 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40807 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40808 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40809 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40810 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40811 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40812 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40813 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40818 +4 4 4 4 4 4
40819 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40820 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40821 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40822 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40823 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40824 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40825 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40826 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40827 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40832 +4 4 4 4 4 4
40833 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40834 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40835 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40836 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40837 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40838 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40839 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40840 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40841 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40846 +4 4 4 4 4 4
40847 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40848 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40849 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40850 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40851 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40852 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40853 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40854 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40860 +4 4 4 4 4 4
40861 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40862 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40863 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40864 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40865 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40866 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40867 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40868 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40874 +4 4 4 4 4 4
40875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40876 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40877 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40878 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40879 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40880 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40881 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40882 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40888 +4 4 4 4 4 4
40889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40891 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40892 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40893 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40894 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40895 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40896 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40902 +4 4 4 4 4 4
40903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40905 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40906 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40907 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40908 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40909 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40910 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40916 +4 4 4 4 4 4
40917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40920 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40921 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40922 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40923 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40924 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40930 +4 4 4 4 4 4
40931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40934 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40935 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40936 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40937 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40944 +4 4 4 4 4 4
40945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40948 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40949 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40950 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
40951 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
40952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40958 +4 4 4 4 4 4
40959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40962 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40963 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40964 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40965 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
40966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40972 +4 4 4 4 4 4
40973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40976 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
40977 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
40978 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
40979 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
40980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40986 +4 4 4 4 4 4
40987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40991 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
40992 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40993 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41000 +4 4 4 4 4 4
41001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41005 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41006 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41007 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41014 +4 4 4 4 4 4
41015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41019 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41020 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41021 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41028 +4 4 4 4 4 4
41029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41033 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41034 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41042 +4 4 4 4 4 4
41043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41047 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41048 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41056 +4 4 4 4 4 4
41057 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41058 index a159b63..4ab532d 100644
41059 --- a/drivers/video/udlfb.c
41060 +++ b/drivers/video/udlfb.c
41061 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41062 dlfb_urb_completion(urb);
41063
41064 error:
41065 - atomic_add(bytes_sent, &dev->bytes_sent);
41066 - atomic_add(bytes_identical, &dev->bytes_identical);
41067 - atomic_add(width*height*2, &dev->bytes_rendered);
41068 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41069 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41070 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41071 end_cycles = get_cycles();
41072 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41073 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41074 >> 10)), /* Kcycles */
41075 &dev->cpu_kcycles_used);
41076
41077 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41078 dlfb_urb_completion(urb);
41079
41080 error:
41081 - atomic_add(bytes_sent, &dev->bytes_sent);
41082 - atomic_add(bytes_identical, &dev->bytes_identical);
41083 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41084 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41085 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41086 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41087 end_cycles = get_cycles();
41088 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41089 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41090 >> 10)), /* Kcycles */
41091 &dev->cpu_kcycles_used);
41092 }
41093 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41094 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41095 struct dlfb_data *dev = fb_info->par;
41096 return snprintf(buf, PAGE_SIZE, "%u\n",
41097 - atomic_read(&dev->bytes_rendered));
41098 + atomic_read_unchecked(&dev->bytes_rendered));
41099 }
41100
41101 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41102 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41103 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41104 struct dlfb_data *dev = fb_info->par;
41105 return snprintf(buf, PAGE_SIZE, "%u\n",
41106 - atomic_read(&dev->bytes_identical));
41107 + atomic_read_unchecked(&dev->bytes_identical));
41108 }
41109
41110 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41111 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41112 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41113 struct dlfb_data *dev = fb_info->par;
41114 return snprintf(buf, PAGE_SIZE, "%u\n",
41115 - atomic_read(&dev->bytes_sent));
41116 + atomic_read_unchecked(&dev->bytes_sent));
41117 }
41118
41119 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41120 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41121 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41122 struct dlfb_data *dev = fb_info->par;
41123 return snprintf(buf, PAGE_SIZE, "%u\n",
41124 - atomic_read(&dev->cpu_kcycles_used));
41125 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41126 }
41127
41128 static ssize_t edid_show(
41129 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41130 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41131 struct dlfb_data *dev = fb_info->par;
41132
41133 - atomic_set(&dev->bytes_rendered, 0);
41134 - atomic_set(&dev->bytes_identical, 0);
41135 - atomic_set(&dev->bytes_sent, 0);
41136 - atomic_set(&dev->cpu_kcycles_used, 0);
41137 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41138 + atomic_set_unchecked(&dev->bytes_identical, 0);
41139 + atomic_set_unchecked(&dev->bytes_sent, 0);
41140 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41141
41142 return count;
41143 }
41144 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41145 index b0e2a42..e2df3ad 100644
41146 --- a/drivers/video/uvesafb.c
41147 +++ b/drivers/video/uvesafb.c
41148 @@ -19,6 +19,7 @@
41149 #include <linux/io.h>
41150 #include <linux/mutex.h>
41151 #include <linux/slab.h>
41152 +#include <linux/moduleloader.h>
41153 #include <video/edid.h>
41154 #include <video/uvesafb.h>
41155 #ifdef CONFIG_X86
41156 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41157 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41158 par->pmi_setpal = par->ypan = 0;
41159 } else {
41160 +
41161 +#ifdef CONFIG_PAX_KERNEXEC
41162 +#ifdef CONFIG_MODULES
41163 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41164 +#endif
41165 + if (!par->pmi_code) {
41166 + par->pmi_setpal = par->ypan = 0;
41167 + return 0;
41168 + }
41169 +#endif
41170 +
41171 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41172 + task->t.regs.edi);
41173 +
41174 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41175 + pax_open_kernel();
41176 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41177 + pax_close_kernel();
41178 +
41179 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41180 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41181 +#else
41182 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41183 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41184 +#endif
41185 +
41186 printk(KERN_INFO "uvesafb: protected mode interface info at "
41187 "%04x:%04x\n",
41188 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41189 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41190 par->ypan = ypan;
41191
41192 if (par->pmi_setpal || par->ypan) {
41193 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41194 if (__supported_pte_mask & _PAGE_NX) {
41195 par->pmi_setpal = par->ypan = 0;
41196 printk(KERN_WARNING "uvesafb: NX protection is actively."
41197 "We have better not to use the PMI.\n");
41198 - } else {
41199 + } else
41200 +#endif
41201 uvesafb_vbe_getpmi(task, par);
41202 - }
41203 }
41204 #else
41205 /* The protected mode interface is not available on non-x86. */
41206 @@ -1836,6 +1860,11 @@ out:
41207 if (par->vbe_modes)
41208 kfree(par->vbe_modes);
41209
41210 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41211 + if (par->pmi_code)
41212 + module_free_exec(NULL, par->pmi_code);
41213 +#endif
41214 +
41215 framebuffer_release(info);
41216 return err;
41217 }
41218 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41219 kfree(par->vbe_state_orig);
41220 if (par->vbe_state_saved)
41221 kfree(par->vbe_state_saved);
41222 +
41223 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41224 + if (par->pmi_code)
41225 + module_free_exec(NULL, par->pmi_code);
41226 +#endif
41227 +
41228 }
41229
41230 framebuffer_release(info);
41231 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41232 index 501b340..86bd4cf 100644
41233 --- a/drivers/video/vesafb.c
41234 +++ b/drivers/video/vesafb.c
41235 @@ -9,6 +9,7 @@
41236 */
41237
41238 #include <linux/module.h>
41239 +#include <linux/moduleloader.h>
41240 #include <linux/kernel.h>
41241 #include <linux/errno.h>
41242 #include <linux/string.h>
41243 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41244 static int vram_total __initdata; /* Set total amount of memory */
41245 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41246 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41247 -static void (*pmi_start)(void) __read_mostly;
41248 -static void (*pmi_pal) (void) __read_mostly;
41249 +static void (*pmi_start)(void) __read_only;
41250 +static void (*pmi_pal) (void) __read_only;
41251 static int depth __read_mostly;
41252 static int vga_compat __read_mostly;
41253 /* --------------------------------------------------------------------- */
41254 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41255 unsigned int size_vmode;
41256 unsigned int size_remap;
41257 unsigned int size_total;
41258 + void *pmi_code = NULL;
41259
41260 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41261 return -ENODEV;
41262 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41263 size_remap = size_total;
41264 vesafb_fix.smem_len = size_remap;
41265
41266 -#ifndef __i386__
41267 - screen_info.vesapm_seg = 0;
41268 -#endif
41269 -
41270 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41271 printk(KERN_WARNING
41272 "vesafb: cannot reserve video memory at 0x%lx\n",
41273 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41274 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41275 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41276
41277 +#ifdef __i386__
41278 +
41279 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41280 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41281 + if (!pmi_code)
41282 +#elif !defined(CONFIG_PAX_KERNEXEC)
41283 + if (0)
41284 +#endif
41285 +
41286 +#endif
41287 + screen_info.vesapm_seg = 0;
41288 +
41289 if (screen_info.vesapm_seg) {
41290 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41291 - screen_info.vesapm_seg,screen_info.vesapm_off);
41292 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41293 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41294 }
41295
41296 if (screen_info.vesapm_seg < 0xc000)
41297 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41298
41299 if (ypan || pmi_setpal) {
41300 unsigned short *pmi_base;
41301 +
41302 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41303 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41304 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41305 +
41306 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41307 + pax_open_kernel();
41308 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41309 +#else
41310 + pmi_code = pmi_base;
41311 +#endif
41312 +
41313 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41314 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41315 +
41316 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41317 + pmi_start = ktva_ktla(pmi_start);
41318 + pmi_pal = ktva_ktla(pmi_pal);
41319 + pax_close_kernel();
41320 +#endif
41321 +
41322 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41323 if (pmi_base[3]) {
41324 printk(KERN_INFO "vesafb: pmi: ports = ");
41325 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41326 info->node, info->fix.id);
41327 return 0;
41328 err:
41329 +
41330 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41331 + module_free_exec(NULL, pmi_code);
41332 +#endif
41333 +
41334 if (info->screen_base)
41335 iounmap(info->screen_base);
41336 framebuffer_release(info);
41337 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41338 index 88714ae..16c2e11 100644
41339 --- a/drivers/video/via/via_clock.h
41340 +++ b/drivers/video/via/via_clock.h
41341 @@ -56,7 +56,7 @@ struct via_clock {
41342
41343 void (*set_engine_pll_state)(u8 state);
41344 void (*set_engine_pll)(struct via_pll_config config);
41345 -};
41346 +} __no_const;
41347
41348
41349 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41350 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41351 index e56c934..fc22f4b 100644
41352 --- a/drivers/xen/xen-pciback/conf_space.h
41353 +++ b/drivers/xen/xen-pciback/conf_space.h
41354 @@ -44,15 +44,15 @@ struct config_field {
41355 struct {
41356 conf_dword_write write;
41357 conf_dword_read read;
41358 - } dw;
41359 + } __no_const dw;
41360 struct {
41361 conf_word_write write;
41362 conf_word_read read;
41363 - } w;
41364 + } __no_const w;
41365 struct {
41366 conf_byte_write write;
41367 conf_byte_read read;
41368 - } b;
41369 + } __no_const b;
41370 } u;
41371 struct list_head list;
41372 };
41373 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41374 index 014c8dd..6f3dfe6 100644
41375 --- a/fs/9p/vfs_inode.c
41376 +++ b/fs/9p/vfs_inode.c
41377 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41378 void
41379 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41380 {
41381 - char *s = nd_get_link(nd);
41382 + const char *s = nd_get_link(nd);
41383
41384 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41385 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41386 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41387 index e95d1b6..3454244 100644
41388 --- a/fs/Kconfig.binfmt
41389 +++ b/fs/Kconfig.binfmt
41390 @@ -89,7 +89,7 @@ config HAVE_AOUT
41391
41392 config BINFMT_AOUT
41393 tristate "Kernel support for a.out and ECOFF binaries"
41394 - depends on HAVE_AOUT
41395 + depends on HAVE_AOUT && BROKEN
41396 ---help---
41397 A.out (Assembler.OUTput) is a set of formats for libraries and
41398 executables used in the earliest versions of UNIX. Linux used
41399 diff --git a/fs/aio.c b/fs/aio.c
41400 index e7f2fad..15ad8a4 100644
41401 --- a/fs/aio.c
41402 +++ b/fs/aio.c
41403 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41404 size += sizeof(struct io_event) * nr_events;
41405 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41406
41407 - if (nr_pages < 0)
41408 + if (nr_pages <= 0)
41409 return -EINVAL;
41410
41411 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41412 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41413 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41414 {
41415 ssize_t ret;
41416 + struct iovec iovstack;
41417
41418 #ifdef CONFIG_COMPAT
41419 if (compat)
41420 ret = compat_rw_copy_check_uvector(type,
41421 (struct compat_iovec __user *)kiocb->ki_buf,
41422 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41423 + kiocb->ki_nbytes, 1, &iovstack,
41424 &kiocb->ki_iovec, 1);
41425 else
41426 #endif
41427 ret = rw_copy_check_uvector(type,
41428 (struct iovec __user *)kiocb->ki_buf,
41429 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41430 + kiocb->ki_nbytes, 1, &iovstack,
41431 &kiocb->ki_iovec, 1);
41432 if (ret < 0)
41433 goto out;
41434 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41435 if (ret < 0)
41436 goto out;
41437
41438 + if (kiocb->ki_iovec == &iovstack) {
41439 + kiocb->ki_inline_vec = iovstack;
41440 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41441 + }
41442 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41443 kiocb->ki_cur_seg = 0;
41444 /* ki_nbytes/left now reflect bytes instead of segs */
41445 diff --git a/fs/attr.c b/fs/attr.c
41446 index d94d1b6..f9bccd6 100644
41447 --- a/fs/attr.c
41448 +++ b/fs/attr.c
41449 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41450 unsigned long limit;
41451
41452 limit = rlimit(RLIMIT_FSIZE);
41453 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41454 if (limit != RLIM_INFINITY && offset > limit)
41455 goto out_sig;
41456 if (offset > inode->i_sb->s_maxbytes)
41457 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41458 index da8876d..9f3e6d8 100644
41459 --- a/fs/autofs4/waitq.c
41460 +++ b/fs/autofs4/waitq.c
41461 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41462 {
41463 unsigned long sigpipe, flags;
41464 mm_segment_t fs;
41465 - const char *data = (const char *)addr;
41466 + const char __user *data = (const char __force_user *)addr;
41467 ssize_t wr = 0;
41468
41469 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41470 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41471 index e18da23..affc30e 100644
41472 --- a/fs/befs/linuxvfs.c
41473 +++ b/fs/befs/linuxvfs.c
41474 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41475 {
41476 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41477 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41478 - char *link = nd_get_link(nd);
41479 + const char *link = nd_get_link(nd);
41480 if (!IS_ERR(link))
41481 kfree(link);
41482 }
41483 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41484 index d146e18..12d1bd1 100644
41485 --- a/fs/binfmt_aout.c
41486 +++ b/fs/binfmt_aout.c
41487 @@ -16,6 +16,7 @@
41488 #include <linux/string.h>
41489 #include <linux/fs.h>
41490 #include <linux/file.h>
41491 +#include <linux/security.h>
41492 #include <linux/stat.h>
41493 #include <linux/fcntl.h>
41494 #include <linux/ptrace.h>
41495 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41496 #endif
41497 # define START_STACK(u) ((void __user *)u.start_stack)
41498
41499 + memset(&dump, 0, sizeof(dump));
41500 +
41501 fs = get_fs();
41502 set_fs(KERNEL_DS);
41503 has_dumped = 1;
41504 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41505
41506 /* If the size of the dump file exceeds the rlimit, then see what would happen
41507 if we wrote the stack, but not the data area. */
41508 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41509 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41510 dump.u_dsize = 0;
41511
41512 /* Make sure we have enough room to write the stack and data areas. */
41513 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41514 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41515 dump.u_ssize = 0;
41516
41517 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41518 rlim = rlimit(RLIMIT_DATA);
41519 if (rlim >= RLIM_INFINITY)
41520 rlim = ~0;
41521 +
41522 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41523 if (ex.a_data + ex.a_bss > rlim)
41524 return -ENOMEM;
41525
41526 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41527
41528 install_exec_creds(bprm);
41529
41530 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41531 + current->mm->pax_flags = 0UL;
41532 +#endif
41533 +
41534 +#ifdef CONFIG_PAX_PAGEEXEC
41535 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41536 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41537 +
41538 +#ifdef CONFIG_PAX_EMUTRAMP
41539 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41540 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41541 +#endif
41542 +
41543 +#ifdef CONFIG_PAX_MPROTECT
41544 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41545 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41546 +#endif
41547 +
41548 + }
41549 +#endif
41550 +
41551 if (N_MAGIC(ex) == OMAGIC) {
41552 unsigned long text_addr, map_size;
41553 loff_t pos;
41554 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41555 }
41556
41557 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41558 - PROT_READ | PROT_WRITE | PROT_EXEC,
41559 + PROT_READ | PROT_WRITE,
41560 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41561 fd_offset + ex.a_text);
41562 if (error != N_DATADDR(ex)) {
41563 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41564 index 16f7354..666524e 100644
41565 --- a/fs/binfmt_elf.c
41566 +++ b/fs/binfmt_elf.c
41567 @@ -32,6 +32,7 @@
41568 #include <linux/elf.h>
41569 #include <linux/utsname.h>
41570 #include <linux/coredump.h>
41571 +#include <linux/xattr.h>
41572 #include <asm/uaccess.h>
41573 #include <asm/param.h>
41574 #include <asm/page.h>
41575 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41576 #define elf_core_dump NULL
41577 #endif
41578
41579 +#ifdef CONFIG_PAX_MPROTECT
41580 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41581 +#endif
41582 +
41583 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41584 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41585 #else
41586 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41587 .load_binary = load_elf_binary,
41588 .load_shlib = load_elf_library,
41589 .core_dump = elf_core_dump,
41590 +
41591 +#ifdef CONFIG_PAX_MPROTECT
41592 + .handle_mprotect= elf_handle_mprotect,
41593 +#endif
41594 +
41595 .min_coredump = ELF_EXEC_PAGESIZE,
41596 };
41597
41598 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41599
41600 static int set_brk(unsigned long start, unsigned long end)
41601 {
41602 + unsigned long e = end;
41603 +
41604 start = ELF_PAGEALIGN(start);
41605 end = ELF_PAGEALIGN(end);
41606 if (end > start) {
41607 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41608 if (BAD_ADDR(addr))
41609 return addr;
41610 }
41611 - current->mm->start_brk = current->mm->brk = end;
41612 + current->mm->start_brk = current->mm->brk = e;
41613 return 0;
41614 }
41615
41616 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41617 elf_addr_t __user *u_rand_bytes;
41618 const char *k_platform = ELF_PLATFORM;
41619 const char *k_base_platform = ELF_BASE_PLATFORM;
41620 - unsigned char k_rand_bytes[16];
41621 + u32 k_rand_bytes[4];
41622 int items;
41623 elf_addr_t *elf_info;
41624 int ei_index = 0;
41625 const struct cred *cred = current_cred();
41626 struct vm_area_struct *vma;
41627 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41628
41629 /*
41630 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41631 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41632 * Generate 16 random bytes for userspace PRNG seeding.
41633 */
41634 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41635 - u_rand_bytes = (elf_addr_t __user *)
41636 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41637 + srandom32(k_rand_bytes[0] ^ random32());
41638 + srandom32(k_rand_bytes[1] ^ random32());
41639 + srandom32(k_rand_bytes[2] ^ random32());
41640 + srandom32(k_rand_bytes[3] ^ random32());
41641 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41642 + u_rand_bytes = (elf_addr_t __user *) p;
41643 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41644 return -EFAULT;
41645
41646 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41647 return -EFAULT;
41648 current->mm->env_end = p;
41649
41650 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41651 +
41652 /* Put the elf_info on the stack in the right place. */
41653 sp = (elf_addr_t __user *)envp + 1;
41654 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41655 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41656 return -EFAULT;
41657 return 0;
41658 }
41659 @@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41660 {
41661 struct elf_phdr *elf_phdata;
41662 struct elf_phdr *eppnt;
41663 - unsigned long load_addr = 0;
41664 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41665 int load_addr_set = 0;
41666 unsigned long last_bss = 0, elf_bss = 0;
41667 - unsigned long error = ~0UL;
41668 + unsigned long error = -EINVAL;
41669 unsigned long total_size;
41670 int retval, i, size;
41671
41672 @@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41673 goto out_close;
41674 }
41675
41676 +#ifdef CONFIG_PAX_SEGMEXEC
41677 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41678 + pax_task_size = SEGMEXEC_TASK_SIZE;
41679 +#endif
41680 +
41681 eppnt = elf_phdata;
41682 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41683 if (eppnt->p_type == PT_LOAD) {
41684 @@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41685 k = load_addr + eppnt->p_vaddr;
41686 if (BAD_ADDR(k) ||
41687 eppnt->p_filesz > eppnt->p_memsz ||
41688 - eppnt->p_memsz > TASK_SIZE ||
41689 - TASK_SIZE - eppnt->p_memsz < k) {
41690 + eppnt->p_memsz > pax_task_size ||
41691 + pax_task_size - eppnt->p_memsz < k) {
41692 error = -ENOMEM;
41693 goto out_close;
41694 }
41695 @@ -525,6 +549,349 @@ out:
41696 return error;
41697 }
41698
41699 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41700 +#ifdef CONFIG_PAX_SOFTMODE
41701 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41702 +{
41703 + unsigned long pax_flags = 0UL;
41704 +
41705 +#ifdef CONFIG_PAX_PAGEEXEC
41706 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41707 + pax_flags |= MF_PAX_PAGEEXEC;
41708 +#endif
41709 +
41710 +#ifdef CONFIG_PAX_SEGMEXEC
41711 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41712 + pax_flags |= MF_PAX_SEGMEXEC;
41713 +#endif
41714 +
41715 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41716 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41717 + if ((__supported_pte_mask & _PAGE_NX))
41718 + pax_flags &= ~MF_PAX_SEGMEXEC;
41719 + else
41720 + pax_flags &= ~MF_PAX_PAGEEXEC;
41721 + }
41722 +#endif
41723 +
41724 +#ifdef CONFIG_PAX_EMUTRAMP
41725 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41726 + pax_flags |= MF_PAX_EMUTRAMP;
41727 +#endif
41728 +
41729 +#ifdef CONFIG_PAX_MPROTECT
41730 + if (elf_phdata->p_flags & PF_MPROTECT)
41731 + pax_flags |= MF_PAX_MPROTECT;
41732 +#endif
41733 +
41734 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41735 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41736 + pax_flags |= MF_PAX_RANDMMAP;
41737 +#endif
41738 +
41739 + return pax_flags;
41740 +}
41741 +#endif
41742 +
41743 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41744 +{
41745 + unsigned long pax_flags = 0UL;
41746 +
41747 +#ifdef CONFIG_PAX_PAGEEXEC
41748 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41749 + pax_flags |= MF_PAX_PAGEEXEC;
41750 +#endif
41751 +
41752 +#ifdef CONFIG_PAX_SEGMEXEC
41753 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41754 + pax_flags |= MF_PAX_SEGMEXEC;
41755 +#endif
41756 +
41757 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41758 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41759 + if ((__supported_pte_mask & _PAGE_NX))
41760 + pax_flags &= ~MF_PAX_SEGMEXEC;
41761 + else
41762 + pax_flags &= ~MF_PAX_PAGEEXEC;
41763 + }
41764 +#endif
41765 +
41766 +#ifdef CONFIG_PAX_EMUTRAMP
41767 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41768 + pax_flags |= MF_PAX_EMUTRAMP;
41769 +#endif
41770 +
41771 +#ifdef CONFIG_PAX_MPROTECT
41772 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41773 + pax_flags |= MF_PAX_MPROTECT;
41774 +#endif
41775 +
41776 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41777 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41778 + pax_flags |= MF_PAX_RANDMMAP;
41779 +#endif
41780 +
41781 + return pax_flags;
41782 +}
41783 +#endif
41784 +
41785 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41786 +#ifdef CONFIG_PAX_SOFTMODE
41787 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41788 +{
41789 + unsigned long pax_flags = 0UL;
41790 +
41791 +#ifdef CONFIG_PAX_PAGEEXEC
41792 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41793 + pax_flags |= MF_PAX_PAGEEXEC;
41794 +#endif
41795 +
41796 +#ifdef CONFIG_PAX_SEGMEXEC
41797 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41798 + pax_flags |= MF_PAX_SEGMEXEC;
41799 +#endif
41800 +
41801 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41802 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41803 + if ((__supported_pte_mask & _PAGE_NX))
41804 + pax_flags &= ~MF_PAX_SEGMEXEC;
41805 + else
41806 + pax_flags &= ~MF_PAX_PAGEEXEC;
41807 + }
41808 +#endif
41809 +
41810 +#ifdef CONFIG_PAX_EMUTRAMP
41811 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41812 + pax_flags |= MF_PAX_EMUTRAMP;
41813 +#endif
41814 +
41815 +#ifdef CONFIG_PAX_MPROTECT
41816 + if (pax_flags_softmode & MF_PAX_MPROTECT)
41817 + pax_flags |= MF_PAX_MPROTECT;
41818 +#endif
41819 +
41820 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41821 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41822 + pax_flags |= MF_PAX_RANDMMAP;
41823 +#endif
41824 +
41825 + return pax_flags;
41826 +}
41827 +#endif
41828 +
41829 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41830 +{
41831 + unsigned long pax_flags = 0UL;
41832 +
41833 +#ifdef CONFIG_PAX_PAGEEXEC
41834 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41835 + pax_flags |= MF_PAX_PAGEEXEC;
41836 +#endif
41837 +
41838 +#ifdef CONFIG_PAX_SEGMEXEC
41839 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41840 + pax_flags |= MF_PAX_SEGMEXEC;
41841 +#endif
41842 +
41843 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41844 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41845 + if ((__supported_pte_mask & _PAGE_NX))
41846 + pax_flags &= ~MF_PAX_SEGMEXEC;
41847 + else
41848 + pax_flags &= ~MF_PAX_PAGEEXEC;
41849 + }
41850 +#endif
41851 +
41852 +#ifdef CONFIG_PAX_EMUTRAMP
41853 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41854 + pax_flags |= MF_PAX_EMUTRAMP;
41855 +#endif
41856 +
41857 +#ifdef CONFIG_PAX_MPROTECT
41858 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41859 + pax_flags |= MF_PAX_MPROTECT;
41860 +#endif
41861 +
41862 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41863 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41864 + pax_flags |= MF_PAX_RANDMMAP;
41865 +#endif
41866 +
41867 + return pax_flags;
41868 +}
41869 +#endif
41870 +
41871 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41872 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41873 +{
41874 + unsigned long pax_flags = 0UL;
41875 +
41876 +#ifdef CONFIG_PAX_EI_PAX
41877 +
41878 +#ifdef CONFIG_PAX_PAGEEXEC
41879 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41880 + pax_flags |= MF_PAX_PAGEEXEC;
41881 +#endif
41882 +
41883 +#ifdef CONFIG_PAX_SEGMEXEC
41884 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41885 + pax_flags |= MF_PAX_SEGMEXEC;
41886 +#endif
41887 +
41888 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41889 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41890 + if ((__supported_pte_mask & _PAGE_NX))
41891 + pax_flags &= ~MF_PAX_SEGMEXEC;
41892 + else
41893 + pax_flags &= ~MF_PAX_PAGEEXEC;
41894 + }
41895 +#endif
41896 +
41897 +#ifdef CONFIG_PAX_EMUTRAMP
41898 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41899 + pax_flags |= MF_PAX_EMUTRAMP;
41900 +#endif
41901 +
41902 +#ifdef CONFIG_PAX_MPROTECT
41903 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41904 + pax_flags |= MF_PAX_MPROTECT;
41905 +#endif
41906 +
41907 +#ifdef CONFIG_PAX_ASLR
41908 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41909 + pax_flags |= MF_PAX_RANDMMAP;
41910 +#endif
41911 +
41912 +#else
41913 +
41914 +#ifdef CONFIG_PAX_PAGEEXEC
41915 + pax_flags |= MF_PAX_PAGEEXEC;
41916 +#endif
41917 +
41918 +#ifdef CONFIG_PAX_MPROTECT
41919 + pax_flags |= MF_PAX_MPROTECT;
41920 +#endif
41921 +
41922 +#ifdef CONFIG_PAX_RANDMMAP
41923 + pax_flags |= MF_PAX_RANDMMAP;
41924 +#endif
41925 +
41926 +#ifdef CONFIG_PAX_SEGMEXEC
41927 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41928 + pax_flags &= ~MF_PAX_PAGEEXEC;
41929 + pax_flags |= MF_PAX_SEGMEXEC;
41930 + }
41931 +#endif
41932 +
41933 +#endif
41934 +
41935 + return pax_flags;
41936 +}
41937 +
41938 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41939 +{
41940 +
41941 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41942 + unsigned long i;
41943 +
41944 + for (i = 0UL; i < elf_ex->e_phnum; i++)
41945 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41946 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41947 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41948 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41949 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41950 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41951 + return ~0UL;
41952 +
41953 +#ifdef CONFIG_PAX_SOFTMODE
41954 + if (pax_softmode)
41955 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41956 + else
41957 +#endif
41958 +
41959 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41960 + break;
41961 + }
41962 +#endif
41963 +
41964 + return ~0UL;
41965 +}
41966 +
41967 +static unsigned long pax_parse_xattr_pax(struct file * const file)
41968 +{
41969 +
41970 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41971 + ssize_t xattr_size, i;
41972 + unsigned char xattr_value[5];
41973 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
41974 +
41975 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
41976 + if (xattr_size <= 0)
41977 + return ~0UL;
41978 +
41979 + for (i = 0; i < xattr_size; i++)
41980 + switch (xattr_value[i]) {
41981 + default:
41982 + return ~0UL;
41983 +
41984 +#define parse_flag(option1, option2, flag) \
41985 + case option1: \
41986 + pax_flags_hardmode |= MF_PAX_##flag; \
41987 + break; \
41988 + case option2: \
41989 + pax_flags_softmode |= MF_PAX_##flag; \
41990 + break;
41991 +
41992 + parse_flag('p', 'P', PAGEEXEC);
41993 + parse_flag('e', 'E', EMUTRAMP);
41994 + parse_flag('m', 'M', MPROTECT);
41995 + parse_flag('r', 'R', RANDMMAP);
41996 + parse_flag('s', 'S', SEGMEXEC);
41997 +
41998 +#undef parse_flag
41999 + }
42000 +
42001 + if (pax_flags_hardmode & pax_flags_softmode)
42002 + return ~0UL;
42003 +
42004 +#ifdef CONFIG_PAX_SOFTMODE
42005 + if (pax_softmode)
42006 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42007 + else
42008 +#endif
42009 +
42010 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42011 +#else
42012 + return ~0UL;
42013 +#endif
42014 +
42015 +}
42016 +
42017 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42018 +{
42019 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42020 +
42021 + pax_flags = pax_parse_ei_pax(elf_ex);
42022 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42023 + xattr_pax_flags = pax_parse_xattr_pax(file);
42024 +
42025 + if (pt_pax_flags == ~0UL)
42026 + pt_pax_flags = xattr_pax_flags;
42027 + else if (xattr_pax_flags == ~0UL)
42028 + xattr_pax_flags = pt_pax_flags;
42029 + if (pt_pax_flags != xattr_pax_flags)
42030 + return -EINVAL;
42031 + if (pt_pax_flags != ~0UL)
42032 + pax_flags = pt_pax_flags;
42033 +
42034 + if (0 > pax_check_flags(&pax_flags))
42035 + return -EINVAL;
42036 +
42037 + current->mm->pax_flags = pax_flags;
42038 + return 0;
42039 +}
42040 +#endif
42041 +
42042 /*
42043 * These are the functions used to load ELF style executables and shared
42044 * libraries. There is no binary dependent code anywhere else.
42045 @@ -541,6 +908,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42046 {
42047 unsigned int random_variable = 0;
42048
42049 +#ifdef CONFIG_PAX_RANDUSTACK
42050 + if (randomize_va_space)
42051 + return stack_top - current->mm->delta_stack;
42052 +#endif
42053 +
42054 if ((current->flags & PF_RANDOMIZE) &&
42055 !(current->personality & ADDR_NO_RANDOMIZE)) {
42056 random_variable = get_random_int() & STACK_RND_MASK;
42057 @@ -559,7 +931,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42058 unsigned long load_addr = 0, load_bias = 0;
42059 int load_addr_set = 0;
42060 char * elf_interpreter = NULL;
42061 - unsigned long error;
42062 + unsigned long error = 0;
42063 struct elf_phdr *elf_ppnt, *elf_phdata;
42064 unsigned long elf_bss, elf_brk;
42065 int retval, i;
42066 @@ -569,11 +941,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42067 unsigned long start_code, end_code, start_data, end_data;
42068 unsigned long reloc_func_desc __maybe_unused = 0;
42069 int executable_stack = EXSTACK_DEFAULT;
42070 - unsigned long def_flags = 0;
42071 struct {
42072 struct elfhdr elf_ex;
42073 struct elfhdr interp_elf_ex;
42074 } *loc;
42075 + unsigned long pax_task_size = TASK_SIZE;
42076
42077 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42078 if (!loc) {
42079 @@ -709,11 +1081,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42080 goto out_free_dentry;
42081
42082 /* OK, This is the point of no return */
42083 - current->mm->def_flags = def_flags;
42084 +
42085 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42086 + current->mm->pax_flags = 0UL;
42087 +#endif
42088 +
42089 +#ifdef CONFIG_PAX_DLRESOLVE
42090 + current->mm->call_dl_resolve = 0UL;
42091 +#endif
42092 +
42093 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42094 + current->mm->call_syscall = 0UL;
42095 +#endif
42096 +
42097 +#ifdef CONFIG_PAX_ASLR
42098 + current->mm->delta_mmap = 0UL;
42099 + current->mm->delta_stack = 0UL;
42100 +#endif
42101 +
42102 + current->mm->def_flags = 0;
42103 +
42104 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42105 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42106 + send_sig(SIGKILL, current, 0);
42107 + goto out_free_dentry;
42108 + }
42109 +#endif
42110 +
42111 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42112 + pax_set_initial_flags(bprm);
42113 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42114 + if (pax_set_initial_flags_func)
42115 + (pax_set_initial_flags_func)(bprm);
42116 +#endif
42117 +
42118 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42119 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42120 + current->mm->context.user_cs_limit = PAGE_SIZE;
42121 + current->mm->def_flags |= VM_PAGEEXEC;
42122 + }
42123 +#endif
42124 +
42125 +#ifdef CONFIG_PAX_SEGMEXEC
42126 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42127 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42128 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42129 + pax_task_size = SEGMEXEC_TASK_SIZE;
42130 + current->mm->def_flags |= VM_NOHUGEPAGE;
42131 + }
42132 +#endif
42133 +
42134 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42135 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42136 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42137 + put_cpu();
42138 + }
42139 +#endif
42140
42141 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42142 may depend on the personality. */
42143 SET_PERSONALITY(loc->elf_ex);
42144 +
42145 +#ifdef CONFIG_PAX_ASLR
42146 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42147 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42148 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42149 + }
42150 +#endif
42151 +
42152 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42153 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42154 + executable_stack = EXSTACK_DISABLE_X;
42155 + current->personality &= ~READ_IMPLIES_EXEC;
42156 + } else
42157 +#endif
42158 +
42159 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42160 current->personality |= READ_IMPLIES_EXEC;
42161
42162 @@ -804,6 +1246,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42163 #else
42164 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42165 #endif
42166 +
42167 +#ifdef CONFIG_PAX_RANDMMAP
42168 + /* PaX: randomize base address at the default exe base if requested */
42169 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42170 +#ifdef CONFIG_SPARC64
42171 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42172 +#else
42173 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42174 +#endif
42175 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42176 + elf_flags |= MAP_FIXED;
42177 + }
42178 +#endif
42179 +
42180 }
42181
42182 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42183 @@ -836,9 +1292,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42184 * allowed task size. Note that p_filesz must always be
42185 * <= p_memsz so it is only necessary to check p_memsz.
42186 */
42187 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42188 - elf_ppnt->p_memsz > TASK_SIZE ||
42189 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42190 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42191 + elf_ppnt->p_memsz > pax_task_size ||
42192 + pax_task_size - elf_ppnt->p_memsz < k) {
42193 /* set_brk can never work. Avoid overflows. */
42194 send_sig(SIGKILL, current, 0);
42195 retval = -EINVAL;
42196 @@ -877,11 +1333,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42197 goto out_free_dentry;
42198 }
42199 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42200 - send_sig(SIGSEGV, current, 0);
42201 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42202 - goto out_free_dentry;
42203 + /*
42204 + * This bss-zeroing can fail if the ELF
42205 + * file specifies odd protections. So
42206 + * we don't check the return value
42207 + */
42208 }
42209
42210 +#ifdef CONFIG_PAX_RANDMMAP
42211 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42212 + unsigned long start, size;
42213 +
42214 + start = ELF_PAGEALIGN(elf_brk);
42215 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42216 + down_write(&current->mm->mmap_sem);
42217 + retval = -ENOMEM;
42218 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42219 + unsigned long prot = PROT_NONE;
42220 +
42221 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42222 +// if (current->personality & ADDR_NO_RANDOMIZE)
42223 +// prot = PROT_READ;
42224 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42225 + retval = IS_ERR_VALUE(start) ? start : 0;
42226 + }
42227 + up_write(&current->mm->mmap_sem);
42228 + if (retval == 0)
42229 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42230 + if (retval < 0) {
42231 + send_sig(SIGKILL, current, 0);
42232 + goto out_free_dentry;
42233 + }
42234 + }
42235 +#endif
42236 +
42237 if (elf_interpreter) {
42238 unsigned long uninitialized_var(interp_map_addr);
42239
42240 @@ -1109,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42241 * Decide what to dump of a segment, part, all or none.
42242 */
42243 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42244 - unsigned long mm_flags)
42245 + unsigned long mm_flags, long signr)
42246 {
42247 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42248
42249 @@ -1146,7 +1631,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42250 if (vma->vm_file == NULL)
42251 return 0;
42252
42253 - if (FILTER(MAPPED_PRIVATE))
42254 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42255 goto whole;
42256
42257 /*
42258 @@ -1368,9 +1853,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42259 {
42260 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42261 int i = 0;
42262 - do
42263 + do {
42264 i += 2;
42265 - while (auxv[i - 2] != AT_NULL);
42266 + } while (auxv[i - 2] != AT_NULL);
42267 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42268 }
42269
42270 @@ -1892,14 +2377,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42271 }
42272
42273 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42274 - unsigned long mm_flags)
42275 + struct coredump_params *cprm)
42276 {
42277 struct vm_area_struct *vma;
42278 size_t size = 0;
42279
42280 for (vma = first_vma(current, gate_vma); vma != NULL;
42281 vma = next_vma(vma, gate_vma))
42282 - size += vma_dump_size(vma, mm_flags);
42283 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42284 return size;
42285 }
42286
42287 @@ -1993,7 +2478,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42288
42289 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42290
42291 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42292 + offset += elf_core_vma_data_size(gate_vma, cprm);
42293 offset += elf_core_extra_data_size();
42294 e_shoff = offset;
42295
42296 @@ -2007,10 +2492,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42297 offset = dataoff;
42298
42299 size += sizeof(*elf);
42300 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42301 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42302 goto end_coredump;
42303
42304 size += sizeof(*phdr4note);
42305 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42306 if (size > cprm->limit
42307 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42308 goto end_coredump;
42309 @@ -2024,7 +2511,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42310 phdr.p_offset = offset;
42311 phdr.p_vaddr = vma->vm_start;
42312 phdr.p_paddr = 0;
42313 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42314 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42315 phdr.p_memsz = vma->vm_end - vma->vm_start;
42316 offset += phdr.p_filesz;
42317 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42318 @@ -2035,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42319 phdr.p_align = ELF_EXEC_PAGESIZE;
42320
42321 size += sizeof(phdr);
42322 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42323 if (size > cprm->limit
42324 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42325 goto end_coredump;
42326 @@ -2059,7 +2547,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42327 unsigned long addr;
42328 unsigned long end;
42329
42330 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42331 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42332
42333 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42334 struct page *page;
42335 @@ -2068,6 +2556,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42336 page = get_dump_page(addr);
42337 if (page) {
42338 void *kaddr = kmap(page);
42339 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42340 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42341 !dump_write(cprm->file, kaddr,
42342 PAGE_SIZE);
42343 @@ -2085,6 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42344
42345 if (e_phnum == PN_XNUM) {
42346 size += sizeof(*shdr4extnum);
42347 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42348 if (size > cprm->limit
42349 || !dump_write(cprm->file, shdr4extnum,
42350 sizeof(*shdr4extnum)))
42351 @@ -2105,6 +2595,97 @@ out:
42352
42353 #endif /* CONFIG_ELF_CORE */
42354
42355 +#ifdef CONFIG_PAX_MPROTECT
42356 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42357 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42358 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42359 + *
42360 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42361 + * basis because we want to allow the common case and not the special ones.
42362 + */
42363 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42364 +{
42365 + struct elfhdr elf_h;
42366 + struct elf_phdr elf_p;
42367 + unsigned long i;
42368 + unsigned long oldflags;
42369 + bool is_textrel_rw, is_textrel_rx, is_relro;
42370 +
42371 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42372 + return;
42373 +
42374 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42375 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42376 +
42377 +#ifdef CONFIG_PAX_ELFRELOCS
42378 + /* possible TEXTREL */
42379 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42380 + 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);
42381 +#else
42382 + is_textrel_rw = false;
42383 + is_textrel_rx = false;
42384 +#endif
42385 +
42386 + /* possible RELRO */
42387 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42388 +
42389 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42390 + return;
42391 +
42392 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42393 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42394 +
42395 +#ifdef CONFIG_PAX_ETEXECRELOCS
42396 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42397 +#else
42398 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42399 +#endif
42400 +
42401 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42402 + !elf_check_arch(&elf_h) ||
42403 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42404 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42405 + return;
42406 +
42407 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42408 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42409 + return;
42410 + switch (elf_p.p_type) {
42411 + case PT_DYNAMIC:
42412 + if (!is_textrel_rw && !is_textrel_rx)
42413 + continue;
42414 + i = 0UL;
42415 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42416 + elf_dyn dyn;
42417 +
42418 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42419 + return;
42420 + if (dyn.d_tag == DT_NULL)
42421 + return;
42422 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42423 + gr_log_textrel(vma);
42424 + if (is_textrel_rw)
42425 + vma->vm_flags |= VM_MAYWRITE;
42426 + else
42427 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42428 + vma->vm_flags &= ~VM_MAYWRITE;
42429 + return;
42430 + }
42431 + i++;
42432 + }
42433 + return;
42434 +
42435 + case PT_GNU_RELRO:
42436 + if (!is_relro)
42437 + continue;
42438 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42439 + vma->vm_flags &= ~VM_MAYWRITE;
42440 + return;
42441 + }
42442 + }
42443 +}
42444 +#endif
42445 +
42446 static int __init init_elf_binfmt(void)
42447 {
42448 register_binfmt(&elf_format);
42449 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42450 index 6b2daf9..a70dccb 100644
42451 --- a/fs/binfmt_flat.c
42452 +++ b/fs/binfmt_flat.c
42453 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42454 realdatastart = (unsigned long) -ENOMEM;
42455 printk("Unable to allocate RAM for process data, errno %d\n",
42456 (int)-realdatastart);
42457 + down_write(&current->mm->mmap_sem);
42458 do_munmap(current->mm, textpos, text_len);
42459 + up_write(&current->mm->mmap_sem);
42460 ret = realdatastart;
42461 goto err;
42462 }
42463 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42464 }
42465 if (IS_ERR_VALUE(result)) {
42466 printk("Unable to read data+bss, errno %d\n", (int)-result);
42467 + down_write(&current->mm->mmap_sem);
42468 do_munmap(current->mm, textpos, text_len);
42469 do_munmap(current->mm, realdatastart, len);
42470 + up_write(&current->mm->mmap_sem);
42471 ret = result;
42472 goto err;
42473 }
42474 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42475 }
42476 if (IS_ERR_VALUE(result)) {
42477 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42478 + down_write(&current->mm->mmap_sem);
42479 do_munmap(current->mm, textpos, text_len + data_len + extra +
42480 MAX_SHARED_LIBS * sizeof(unsigned long));
42481 + up_write(&current->mm->mmap_sem);
42482 ret = result;
42483 goto err;
42484 }
42485 diff --git a/fs/bio.c b/fs/bio.c
42486 index 84da885..2149cd9 100644
42487 --- a/fs/bio.c
42488 +++ b/fs/bio.c
42489 @@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42490 /*
42491 * Overflow, abort
42492 */
42493 - if (end < start)
42494 + if (end < start || end - start > INT_MAX - nr_pages)
42495 return ERR_PTR(-EINVAL);
42496
42497 nr_pages += end - start;
42498 @@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42499 const int read = bio_data_dir(bio) == READ;
42500 struct bio_map_data *bmd = bio->bi_private;
42501 int i;
42502 - char *p = bmd->sgvecs[0].iov_base;
42503 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42504
42505 __bio_for_each_segment(bvec, bio, i, 0) {
42506 char *addr = page_address(bvec->bv_page);
42507 diff --git a/fs/block_dev.c b/fs/block_dev.c
42508 index ba11c30..623d736 100644
42509 --- a/fs/block_dev.c
42510 +++ b/fs/block_dev.c
42511 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42512 else if (bdev->bd_contains == bdev)
42513 return true; /* is a whole device which isn't held */
42514
42515 - else if (whole->bd_holder == bd_may_claim)
42516 + else if (whole->bd_holder == (void *)bd_may_claim)
42517 return true; /* is a partition of a device that is being partitioned */
42518 else if (whole->bd_holder != NULL)
42519 return false; /* is a partition of a held device */
42520 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42521 index c053e90..e5f1afc 100644
42522 --- a/fs/btrfs/check-integrity.c
42523 +++ b/fs/btrfs/check-integrity.c
42524 @@ -156,7 +156,7 @@ struct btrfsic_block {
42525 union {
42526 bio_end_io_t *bio;
42527 bh_end_io_t *bh;
42528 - } orig_bio_bh_end_io;
42529 + } __no_const orig_bio_bh_end_io;
42530 int submit_bio_bh_rw;
42531 u64 flush_gen; /* only valid if !never_written */
42532 };
42533 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42534 index 4106264..8157ede 100644
42535 --- a/fs/btrfs/ctree.c
42536 +++ b/fs/btrfs/ctree.c
42537 @@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42538 free_extent_buffer(buf);
42539 add_root_to_dirty_list(root);
42540 } else {
42541 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42542 - parent_start = parent->start;
42543 - else
42544 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42545 + if (parent)
42546 + parent_start = parent->start;
42547 + else
42548 + parent_start = 0;
42549 + } else
42550 parent_start = 0;
42551
42552 WARN_ON(trans->transid != btrfs_header_generation(parent));
42553 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42554 index 0df0d1f..4bdcbfe 100644
42555 --- a/fs/btrfs/inode.c
42556 +++ b/fs/btrfs/inode.c
42557 @@ -7074,7 +7074,7 @@ fail:
42558 return -ENOMEM;
42559 }
42560
42561 -static int btrfs_getattr(struct vfsmount *mnt,
42562 +int btrfs_getattr(struct vfsmount *mnt,
42563 struct dentry *dentry, struct kstat *stat)
42564 {
42565 struct inode *inode = dentry->d_inode;
42566 @@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42567 return 0;
42568 }
42569
42570 +EXPORT_SYMBOL(btrfs_getattr);
42571 +
42572 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42573 +{
42574 + return BTRFS_I(inode)->root->anon_dev;
42575 +}
42576 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42577 +
42578 /*
42579 * If a file is moved, it will inherit the cow and compression flags of the new
42580 * directory.
42581 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42582 index 14f8e1f..ab8d81f 100644
42583 --- a/fs/btrfs/ioctl.c
42584 +++ b/fs/btrfs/ioctl.c
42585 @@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42586 for (i = 0; i < num_types; i++) {
42587 struct btrfs_space_info *tmp;
42588
42589 + /* Don't copy in more than we allocated */
42590 if (!slot_count)
42591 break;
42592
42593 + slot_count--;
42594 +
42595 info = NULL;
42596 rcu_read_lock();
42597 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42598 @@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42599 memcpy(dest, &space, sizeof(space));
42600 dest++;
42601 space_args.total_spaces++;
42602 - slot_count--;
42603 }
42604 - if (!slot_count)
42605 - break;
42606 }
42607 up_read(&info->groups_sem);
42608 }
42609
42610 - user_dest = (struct btrfs_ioctl_space_info *)
42611 + user_dest = (struct btrfs_ioctl_space_info __user *)
42612 (arg + sizeof(struct btrfs_ioctl_space_args));
42613
42614 if (copy_to_user(user_dest, dest_orig, alloc_size))
42615 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42616 index 646ee21..f020f87 100644
42617 --- a/fs/btrfs/relocation.c
42618 +++ b/fs/btrfs/relocation.c
42619 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42620 }
42621 spin_unlock(&rc->reloc_root_tree.lock);
42622
42623 - BUG_ON((struct btrfs_root *)node->data != root);
42624 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
42625
42626 if (!del) {
42627 spin_lock(&rc->reloc_root_tree.lock);
42628 diff --git a/fs/buffer.c b/fs/buffer.c
42629 index ad5938c..0bc1bed 100644
42630 --- a/fs/buffer.c
42631 +++ b/fs/buffer.c
42632 @@ -1036,6 +1036,9 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
42633 static struct buffer_head *
42634 __getblk_slow(struct block_device *bdev, sector_t block, int size)
42635 {
42636 + int ret;
42637 + struct buffer_head *bh;
42638 +
42639 /* Size must be multiple of hard sectorsize */
42640 if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
42641 (size < 512 || size > PAGE_SIZE))) {
42642 @@ -1048,20 +1051,21 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
42643 return NULL;
42644 }
42645
42646 - for (;;) {
42647 - struct buffer_head * bh;
42648 - int ret;
42649 +retry:
42650 + bh = __find_get_block(bdev, block, size);
42651 + if (bh)
42652 + return bh;
42653
42654 + ret = grow_buffers(bdev, block, size);
42655 + if (ret == 0) {
42656 + free_more_memory();
42657 + goto retry;
42658 + } else if (ret > 0) {
42659 bh = __find_get_block(bdev, block, size);
42660 if (bh)
42661 return bh;
42662 -
42663 - ret = grow_buffers(bdev, block, size);
42664 - if (ret < 0)
42665 - return NULL;
42666 - if (ret == 0)
42667 - free_more_memory();
42668 }
42669 + return NULL;
42670 }
42671
42672 /*
42673 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42674 index 622f469..e8d2d55 100644
42675 --- a/fs/cachefiles/bind.c
42676 +++ b/fs/cachefiles/bind.c
42677 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42678 args);
42679
42680 /* start by checking things over */
42681 - ASSERT(cache->fstop_percent >= 0 &&
42682 - cache->fstop_percent < cache->fcull_percent &&
42683 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
42684 cache->fcull_percent < cache->frun_percent &&
42685 cache->frun_percent < 100);
42686
42687 - ASSERT(cache->bstop_percent >= 0 &&
42688 - cache->bstop_percent < cache->bcull_percent &&
42689 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42690 cache->bcull_percent < cache->brun_percent &&
42691 cache->brun_percent < 100);
42692
42693 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42694 index 0a1467b..6a53245 100644
42695 --- a/fs/cachefiles/daemon.c
42696 +++ b/fs/cachefiles/daemon.c
42697 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42698 if (n > buflen)
42699 return -EMSGSIZE;
42700
42701 - if (copy_to_user(_buffer, buffer, n) != 0)
42702 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42703 return -EFAULT;
42704
42705 return n;
42706 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42707 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42708 return -EIO;
42709
42710 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42711 + if (datalen > PAGE_SIZE - 1)
42712 return -EOPNOTSUPP;
42713
42714 /* drag the command string into the kernel so we can parse it */
42715 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42716 if (args[0] != '%' || args[1] != '\0')
42717 return -EINVAL;
42718
42719 - if (fstop < 0 || fstop >= cache->fcull_percent)
42720 + if (fstop >= cache->fcull_percent)
42721 return cachefiles_daemon_range_error(cache, args);
42722
42723 cache->fstop_percent = fstop;
42724 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42725 if (args[0] != '%' || args[1] != '\0')
42726 return -EINVAL;
42727
42728 - if (bstop < 0 || bstop >= cache->bcull_percent)
42729 + if (bstop >= cache->bcull_percent)
42730 return cachefiles_daemon_range_error(cache, args);
42731
42732 cache->bstop_percent = bstop;
42733 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42734 index bd6bc1b..b627b53 100644
42735 --- a/fs/cachefiles/internal.h
42736 +++ b/fs/cachefiles/internal.h
42737 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42738 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42739 struct rb_root active_nodes; /* active nodes (can't be culled) */
42740 rwlock_t active_lock; /* lock for active_nodes */
42741 - atomic_t gravecounter; /* graveyard uniquifier */
42742 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42743 unsigned frun_percent; /* when to stop culling (% files) */
42744 unsigned fcull_percent; /* when to start culling (% files) */
42745 unsigned fstop_percent; /* when to stop allocating (% files) */
42746 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42747 * proc.c
42748 */
42749 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42750 -extern atomic_t cachefiles_lookup_histogram[HZ];
42751 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42752 -extern atomic_t cachefiles_create_histogram[HZ];
42753 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42754 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42755 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42756
42757 extern int __init cachefiles_proc_init(void);
42758 extern void cachefiles_proc_cleanup(void);
42759 static inline
42760 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42761 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42762 {
42763 unsigned long jif = jiffies - start_jif;
42764 if (jif >= HZ)
42765 jif = HZ - 1;
42766 - atomic_inc(&histogram[jif]);
42767 + atomic_inc_unchecked(&histogram[jif]);
42768 }
42769
42770 #else
42771 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42772 index 7f0771d..87d4f36 100644
42773 --- a/fs/cachefiles/namei.c
42774 +++ b/fs/cachefiles/namei.c
42775 @@ -318,7 +318,7 @@ try_again:
42776 /* first step is to make up a grave dentry in the graveyard */
42777 sprintf(nbuffer, "%08x%08x",
42778 (uint32_t) get_seconds(),
42779 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42780 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42781
42782 /* do the multiway lock magic */
42783 trap = lock_rename(cache->graveyard, dir);
42784 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42785 index eccd339..4c1d995 100644
42786 --- a/fs/cachefiles/proc.c
42787 +++ b/fs/cachefiles/proc.c
42788 @@ -14,9 +14,9 @@
42789 #include <linux/seq_file.h>
42790 #include "internal.h"
42791
42792 -atomic_t cachefiles_lookup_histogram[HZ];
42793 -atomic_t cachefiles_mkdir_histogram[HZ];
42794 -atomic_t cachefiles_create_histogram[HZ];
42795 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42796 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42797 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42798
42799 /*
42800 * display the latency histogram
42801 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42802 return 0;
42803 default:
42804 index = (unsigned long) v - 3;
42805 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42806 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42807 - z = atomic_read(&cachefiles_create_histogram[index]);
42808 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42809 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42810 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42811 if (x == 0 && y == 0 && z == 0)
42812 return 0;
42813
42814 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42815 index 0e3c092..818480e 100644
42816 --- a/fs/cachefiles/rdwr.c
42817 +++ b/fs/cachefiles/rdwr.c
42818 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42819 old_fs = get_fs();
42820 set_fs(KERNEL_DS);
42821 ret = file->f_op->write(
42822 - file, (const void __user *) data, len, &pos);
42823 + file, (const void __force_user *) data, len, &pos);
42824 set_fs(old_fs);
42825 kunmap(page);
42826 if (ret != len)
42827 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42828 index 3e8094b..cb3ff3d 100644
42829 --- a/fs/ceph/dir.c
42830 +++ b/fs/ceph/dir.c
42831 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42832 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42833 struct ceph_mds_client *mdsc = fsc->mdsc;
42834 unsigned frag = fpos_frag(filp->f_pos);
42835 - int off = fpos_off(filp->f_pos);
42836 + unsigned int off = fpos_off(filp->f_pos);
42837 int err;
42838 u32 ftype;
42839 struct ceph_mds_reply_info_parsed *rinfo;
42840 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42841 if (nd &&
42842 (nd->flags & LOOKUP_OPEN) &&
42843 !(nd->intent.open.flags & O_CREAT)) {
42844 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
42845 + int mode = nd->intent.open.create_mode & ~current_umask();
42846 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42847 }
42848
42849 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42850 index 2704646..c581c91 100644
42851 --- a/fs/cifs/cifs_debug.c
42852 +++ b/fs/cifs/cifs_debug.c
42853 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42854
42855 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42856 #ifdef CONFIG_CIFS_STATS2
42857 - atomic_set(&totBufAllocCount, 0);
42858 - atomic_set(&totSmBufAllocCount, 0);
42859 + atomic_set_unchecked(&totBufAllocCount, 0);
42860 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42861 #endif /* CONFIG_CIFS_STATS2 */
42862 spin_lock(&cifs_tcp_ses_lock);
42863 list_for_each(tmp1, &cifs_tcp_ses_list) {
42864 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42865 tcon = list_entry(tmp3,
42866 struct cifs_tcon,
42867 tcon_list);
42868 - atomic_set(&tcon->num_smbs_sent, 0);
42869 - atomic_set(&tcon->num_writes, 0);
42870 - atomic_set(&tcon->num_reads, 0);
42871 - atomic_set(&tcon->num_oplock_brks, 0);
42872 - atomic_set(&tcon->num_opens, 0);
42873 - atomic_set(&tcon->num_posixopens, 0);
42874 - atomic_set(&tcon->num_posixmkdirs, 0);
42875 - atomic_set(&tcon->num_closes, 0);
42876 - atomic_set(&tcon->num_deletes, 0);
42877 - atomic_set(&tcon->num_mkdirs, 0);
42878 - atomic_set(&tcon->num_rmdirs, 0);
42879 - atomic_set(&tcon->num_renames, 0);
42880 - atomic_set(&tcon->num_t2renames, 0);
42881 - atomic_set(&tcon->num_ffirst, 0);
42882 - atomic_set(&tcon->num_fnext, 0);
42883 - atomic_set(&tcon->num_fclose, 0);
42884 - atomic_set(&tcon->num_hardlinks, 0);
42885 - atomic_set(&tcon->num_symlinks, 0);
42886 - atomic_set(&tcon->num_locks, 0);
42887 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42888 + atomic_set_unchecked(&tcon->num_writes, 0);
42889 + atomic_set_unchecked(&tcon->num_reads, 0);
42890 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42891 + atomic_set_unchecked(&tcon->num_opens, 0);
42892 + atomic_set_unchecked(&tcon->num_posixopens, 0);
42893 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42894 + atomic_set_unchecked(&tcon->num_closes, 0);
42895 + atomic_set_unchecked(&tcon->num_deletes, 0);
42896 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
42897 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
42898 + atomic_set_unchecked(&tcon->num_renames, 0);
42899 + atomic_set_unchecked(&tcon->num_t2renames, 0);
42900 + atomic_set_unchecked(&tcon->num_ffirst, 0);
42901 + atomic_set_unchecked(&tcon->num_fnext, 0);
42902 + atomic_set_unchecked(&tcon->num_fclose, 0);
42903 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
42904 + atomic_set_unchecked(&tcon->num_symlinks, 0);
42905 + atomic_set_unchecked(&tcon->num_locks, 0);
42906 }
42907 }
42908 }
42909 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42910 smBufAllocCount.counter, cifs_min_small);
42911 #ifdef CONFIG_CIFS_STATS2
42912 seq_printf(m, "Total Large %d Small %d Allocations\n",
42913 - atomic_read(&totBufAllocCount),
42914 - atomic_read(&totSmBufAllocCount));
42915 + atomic_read_unchecked(&totBufAllocCount),
42916 + atomic_read_unchecked(&totSmBufAllocCount));
42917 #endif /* CONFIG_CIFS_STATS2 */
42918
42919 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42920 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42921 if (tcon->need_reconnect)
42922 seq_puts(m, "\tDISCONNECTED ");
42923 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42924 - atomic_read(&tcon->num_smbs_sent),
42925 - atomic_read(&tcon->num_oplock_brks));
42926 + atomic_read_unchecked(&tcon->num_smbs_sent),
42927 + atomic_read_unchecked(&tcon->num_oplock_brks));
42928 seq_printf(m, "\nReads: %d Bytes: %lld",
42929 - atomic_read(&tcon->num_reads),
42930 + atomic_read_unchecked(&tcon->num_reads),
42931 (long long)(tcon->bytes_read));
42932 seq_printf(m, "\nWrites: %d Bytes: %lld",
42933 - atomic_read(&tcon->num_writes),
42934 + atomic_read_unchecked(&tcon->num_writes),
42935 (long long)(tcon->bytes_written));
42936 seq_printf(m, "\nFlushes: %d",
42937 - atomic_read(&tcon->num_flushes));
42938 + atomic_read_unchecked(&tcon->num_flushes));
42939 seq_printf(m, "\nLocks: %d HardLinks: %d "
42940 "Symlinks: %d",
42941 - atomic_read(&tcon->num_locks),
42942 - atomic_read(&tcon->num_hardlinks),
42943 - atomic_read(&tcon->num_symlinks));
42944 + atomic_read_unchecked(&tcon->num_locks),
42945 + atomic_read_unchecked(&tcon->num_hardlinks),
42946 + atomic_read_unchecked(&tcon->num_symlinks));
42947 seq_printf(m, "\nOpens: %d Closes: %d "
42948 "Deletes: %d",
42949 - atomic_read(&tcon->num_opens),
42950 - atomic_read(&tcon->num_closes),
42951 - atomic_read(&tcon->num_deletes));
42952 + atomic_read_unchecked(&tcon->num_opens),
42953 + atomic_read_unchecked(&tcon->num_closes),
42954 + atomic_read_unchecked(&tcon->num_deletes));
42955 seq_printf(m, "\nPosix Opens: %d "
42956 "Posix Mkdirs: %d",
42957 - atomic_read(&tcon->num_posixopens),
42958 - atomic_read(&tcon->num_posixmkdirs));
42959 + atomic_read_unchecked(&tcon->num_posixopens),
42960 + atomic_read_unchecked(&tcon->num_posixmkdirs));
42961 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42962 - atomic_read(&tcon->num_mkdirs),
42963 - atomic_read(&tcon->num_rmdirs));
42964 + atomic_read_unchecked(&tcon->num_mkdirs),
42965 + atomic_read_unchecked(&tcon->num_rmdirs));
42966 seq_printf(m, "\nRenames: %d T2 Renames %d",
42967 - atomic_read(&tcon->num_renames),
42968 - atomic_read(&tcon->num_t2renames));
42969 + atomic_read_unchecked(&tcon->num_renames),
42970 + atomic_read_unchecked(&tcon->num_t2renames));
42971 seq_printf(m, "\nFindFirst: %d FNext %d "
42972 "FClose %d",
42973 - atomic_read(&tcon->num_ffirst),
42974 - atomic_read(&tcon->num_fnext),
42975 - atomic_read(&tcon->num_fclose));
42976 + atomic_read_unchecked(&tcon->num_ffirst),
42977 + atomic_read_unchecked(&tcon->num_fnext),
42978 + atomic_read_unchecked(&tcon->num_fclose));
42979 }
42980 }
42981 }
42982 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42983 index 541ef81..a78deb8 100644
42984 --- a/fs/cifs/cifsfs.c
42985 +++ b/fs/cifs/cifsfs.c
42986 @@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
42987 cifs_req_cachep = kmem_cache_create("cifs_request",
42988 CIFSMaxBufSize +
42989 MAX_CIFS_HDR_SIZE, 0,
42990 - SLAB_HWCACHE_ALIGN, NULL);
42991 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
42992 if (cifs_req_cachep == NULL)
42993 return -ENOMEM;
42994
42995 @@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
42996 efficient to alloc 1 per page off the slab compared to 17K (5page)
42997 alloc of large cifs buffers even when page debugging is on */
42998 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
42999 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43000 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43001 NULL);
43002 if (cifs_sm_req_cachep == NULL) {
43003 mempool_destroy(cifs_req_poolp);
43004 @@ -1097,8 +1097,8 @@ init_cifs(void)
43005 atomic_set(&bufAllocCount, 0);
43006 atomic_set(&smBufAllocCount, 0);
43007 #ifdef CONFIG_CIFS_STATS2
43008 - atomic_set(&totBufAllocCount, 0);
43009 - atomic_set(&totSmBufAllocCount, 0);
43010 + atomic_set_unchecked(&totBufAllocCount, 0);
43011 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43012 #endif /* CONFIG_CIFS_STATS2 */
43013
43014 atomic_set(&midCount, 0);
43015 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43016 index 73fea28..b996b84 100644
43017 --- a/fs/cifs/cifsglob.h
43018 +++ b/fs/cifs/cifsglob.h
43019 @@ -439,28 +439,28 @@ struct cifs_tcon {
43020 __u16 Flags; /* optional support bits */
43021 enum statusEnum tidStatus;
43022 #ifdef CONFIG_CIFS_STATS
43023 - atomic_t num_smbs_sent;
43024 - atomic_t num_writes;
43025 - atomic_t num_reads;
43026 - atomic_t num_flushes;
43027 - atomic_t num_oplock_brks;
43028 - atomic_t num_opens;
43029 - atomic_t num_closes;
43030 - atomic_t num_deletes;
43031 - atomic_t num_mkdirs;
43032 - atomic_t num_posixopens;
43033 - atomic_t num_posixmkdirs;
43034 - atomic_t num_rmdirs;
43035 - atomic_t num_renames;
43036 - atomic_t num_t2renames;
43037 - atomic_t num_ffirst;
43038 - atomic_t num_fnext;
43039 - atomic_t num_fclose;
43040 - atomic_t num_hardlinks;
43041 - atomic_t num_symlinks;
43042 - atomic_t num_locks;
43043 - atomic_t num_acl_get;
43044 - atomic_t num_acl_set;
43045 + atomic_unchecked_t num_smbs_sent;
43046 + atomic_unchecked_t num_writes;
43047 + atomic_unchecked_t num_reads;
43048 + atomic_unchecked_t num_flushes;
43049 + atomic_unchecked_t num_oplock_brks;
43050 + atomic_unchecked_t num_opens;
43051 + atomic_unchecked_t num_closes;
43052 + atomic_unchecked_t num_deletes;
43053 + atomic_unchecked_t num_mkdirs;
43054 + atomic_unchecked_t num_posixopens;
43055 + atomic_unchecked_t num_posixmkdirs;
43056 + atomic_unchecked_t num_rmdirs;
43057 + atomic_unchecked_t num_renames;
43058 + atomic_unchecked_t num_t2renames;
43059 + atomic_unchecked_t num_ffirst;
43060 + atomic_unchecked_t num_fnext;
43061 + atomic_unchecked_t num_fclose;
43062 + atomic_unchecked_t num_hardlinks;
43063 + atomic_unchecked_t num_symlinks;
43064 + atomic_unchecked_t num_locks;
43065 + atomic_unchecked_t num_acl_get;
43066 + atomic_unchecked_t num_acl_set;
43067 #ifdef CONFIG_CIFS_STATS2
43068 unsigned long long time_writes;
43069 unsigned long long time_reads;
43070 @@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43071 }
43072
43073 #ifdef CONFIG_CIFS_STATS
43074 -#define cifs_stats_inc atomic_inc
43075 +#define cifs_stats_inc atomic_inc_unchecked
43076
43077 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43078 unsigned int bytes)
43079 @@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43080 /* Various Debug counters */
43081 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43082 #ifdef CONFIG_CIFS_STATS2
43083 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43084 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43085 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43086 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43087 #endif
43088 GLOBAL_EXTERN atomic_t smBufAllocCount;
43089 GLOBAL_EXTERN atomic_t midCount;
43090 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43091 index 6b0e064..94e6c3c 100644
43092 --- a/fs/cifs/link.c
43093 +++ b/fs/cifs/link.c
43094 @@ -600,7 +600,7 @@ symlink_exit:
43095
43096 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43097 {
43098 - char *p = nd_get_link(nd);
43099 + const char *p = nd_get_link(nd);
43100 if (!IS_ERR(p))
43101 kfree(p);
43102 }
43103 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43104 index c29d1aa..58018da 100644
43105 --- a/fs/cifs/misc.c
43106 +++ b/fs/cifs/misc.c
43107 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43108 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43109 atomic_inc(&bufAllocCount);
43110 #ifdef CONFIG_CIFS_STATS2
43111 - atomic_inc(&totBufAllocCount);
43112 + atomic_inc_unchecked(&totBufAllocCount);
43113 #endif /* CONFIG_CIFS_STATS2 */
43114 }
43115
43116 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43117 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43118 atomic_inc(&smBufAllocCount);
43119 #ifdef CONFIG_CIFS_STATS2
43120 - atomic_inc(&totSmBufAllocCount);
43121 + atomic_inc_unchecked(&totSmBufAllocCount);
43122 #endif /* CONFIG_CIFS_STATS2 */
43123
43124 }
43125 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43126 index 6901578..d402eb5 100644
43127 --- a/fs/coda/cache.c
43128 +++ b/fs/coda/cache.c
43129 @@ -24,7 +24,7 @@
43130 #include "coda_linux.h"
43131 #include "coda_cache.h"
43132
43133 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43134 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43135
43136 /* replace or extend an acl cache hit */
43137 void coda_cache_enter(struct inode *inode, int mask)
43138 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43139 struct coda_inode_info *cii = ITOC(inode);
43140
43141 spin_lock(&cii->c_lock);
43142 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43143 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43144 if (cii->c_uid != current_fsuid()) {
43145 cii->c_uid = current_fsuid();
43146 cii->c_cached_perm = mask;
43147 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43148 {
43149 struct coda_inode_info *cii = ITOC(inode);
43150 spin_lock(&cii->c_lock);
43151 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43152 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43153 spin_unlock(&cii->c_lock);
43154 }
43155
43156 /* remove all acl caches */
43157 void coda_cache_clear_all(struct super_block *sb)
43158 {
43159 - atomic_inc(&permission_epoch);
43160 + atomic_inc_unchecked(&permission_epoch);
43161 }
43162
43163
43164 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43165 spin_lock(&cii->c_lock);
43166 hit = (mask & cii->c_cached_perm) == mask &&
43167 cii->c_uid == current_fsuid() &&
43168 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43169 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43170 spin_unlock(&cii->c_lock);
43171
43172 return hit;
43173 diff --git a/fs/compat.c b/fs/compat.c
43174 index f2944ac..62845d2 100644
43175 --- a/fs/compat.c
43176 +++ b/fs/compat.c
43177 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43178
43179 set_fs(KERNEL_DS);
43180 /* The __user pointer cast is valid because of the set_fs() */
43181 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43182 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43183 set_fs(oldfs);
43184 /* truncating is ok because it's a user address */
43185 if (!ret)
43186 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43187 goto out;
43188
43189 ret = -EINVAL;
43190 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43191 + if (nr_segs > UIO_MAXIOV)
43192 goto out;
43193 if (nr_segs > fast_segs) {
43194 ret = -ENOMEM;
43195 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43196
43197 struct compat_readdir_callback {
43198 struct compat_old_linux_dirent __user *dirent;
43199 + struct file * file;
43200 int result;
43201 };
43202
43203 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43204 buf->result = -EOVERFLOW;
43205 return -EOVERFLOW;
43206 }
43207 +
43208 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43209 + return 0;
43210 +
43211 buf->result++;
43212 dirent = buf->dirent;
43213 if (!access_ok(VERIFY_WRITE, dirent,
43214 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43215
43216 buf.result = 0;
43217 buf.dirent = dirent;
43218 + buf.file = file;
43219
43220 error = vfs_readdir(file, compat_fillonedir, &buf);
43221 if (buf.result)
43222 @@ -900,6 +906,7 @@ struct compat_linux_dirent {
43223 struct compat_getdents_callback {
43224 struct compat_linux_dirent __user *current_dir;
43225 struct compat_linux_dirent __user *previous;
43226 + struct file * file;
43227 int count;
43228 int error;
43229 };
43230 @@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43231 buf->error = -EOVERFLOW;
43232 return -EOVERFLOW;
43233 }
43234 +
43235 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43236 + return 0;
43237 +
43238 dirent = buf->previous;
43239 if (dirent) {
43240 if (__put_user(offset, &dirent->d_off))
43241 @@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43242 buf.previous = NULL;
43243 buf.count = count;
43244 buf.error = 0;
43245 + buf.file = file;
43246
43247 error = vfs_readdir(file, compat_filldir, &buf);
43248 if (error >= 0)
43249 @@ -989,6 +1001,7 @@ out:
43250 struct compat_getdents_callback64 {
43251 struct linux_dirent64 __user *current_dir;
43252 struct linux_dirent64 __user *previous;
43253 + struct file * file;
43254 int count;
43255 int error;
43256 };
43257 @@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43258 buf->error = -EINVAL; /* only used if we fail.. */
43259 if (reclen > buf->count)
43260 return -EINVAL;
43261 +
43262 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43263 + return 0;
43264 +
43265 dirent = buf->previous;
43266
43267 if (dirent) {
43268 @@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43269 buf.previous = NULL;
43270 buf.count = count;
43271 buf.error = 0;
43272 + buf.file = file;
43273
43274 error = vfs_readdir(file, compat_filldir64, &buf);
43275 if (error >= 0)
43276 error = buf.error;
43277 lastdirent = buf.previous;
43278 if (lastdirent) {
43279 - typeof(lastdirent->d_off) d_off = file->f_pos;
43280 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43281 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43282 error = -EFAULT;
43283 else
43284 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43285 index 112e45a..b59845b 100644
43286 --- a/fs/compat_binfmt_elf.c
43287 +++ b/fs/compat_binfmt_elf.c
43288 @@ -30,11 +30,13 @@
43289 #undef elf_phdr
43290 #undef elf_shdr
43291 #undef elf_note
43292 +#undef elf_dyn
43293 #undef elf_addr_t
43294 #define elfhdr elf32_hdr
43295 #define elf_phdr elf32_phdr
43296 #define elf_shdr elf32_shdr
43297 #define elf_note elf32_note
43298 +#define elf_dyn Elf32_Dyn
43299 #define elf_addr_t Elf32_Addr
43300
43301 /*
43302 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43303 index debdfe0..75d31d4 100644
43304 --- a/fs/compat_ioctl.c
43305 +++ b/fs/compat_ioctl.c
43306 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43307
43308 err = get_user(palp, &up->palette);
43309 err |= get_user(length, &up->length);
43310 + if (err)
43311 + return -EFAULT;
43312
43313 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43314 err = put_user(compat_ptr(palp), &up_native->palette);
43315 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43316 return -EFAULT;
43317 if (__get_user(udata, &ss32->iomem_base))
43318 return -EFAULT;
43319 - ss.iomem_base = compat_ptr(udata);
43320 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43321 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43322 __get_user(ss.port_high, &ss32->port_high))
43323 return -EFAULT;
43324 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43325 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43326 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43327 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43328 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43329 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43330 return -EFAULT;
43331
43332 return ioctl_preallocate(file, p);
43333 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43334 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43335 {
43336 unsigned int a, b;
43337 - a = *(unsigned int *)p;
43338 - b = *(unsigned int *)q;
43339 + a = *(const unsigned int *)p;
43340 + b = *(const unsigned int *)q;
43341 if (a > b)
43342 return 1;
43343 if (a < b)
43344 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43345 index 7e6c52d..94bc756 100644
43346 --- a/fs/configfs/dir.c
43347 +++ b/fs/configfs/dir.c
43348 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43349 }
43350 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43351 struct configfs_dirent *next;
43352 - const char * name;
43353 + const unsigned char * name;
43354 + char d_name[sizeof(next->s_dentry->d_iname)];
43355 int len;
43356 struct inode *inode = NULL;
43357
43358 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43359 continue;
43360
43361 name = configfs_get_name(next);
43362 - len = strlen(name);
43363 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43364 + len = next->s_dentry->d_name.len;
43365 + memcpy(d_name, name, len);
43366 + name = d_name;
43367 + } else
43368 + len = strlen(name);
43369
43370 /*
43371 * We'll have a dentry and an inode for
43372 diff --git a/fs/dcache.c b/fs/dcache.c
43373 index b80531c..8ca7e2d 100644
43374 --- a/fs/dcache.c
43375 +++ b/fs/dcache.c
43376 @@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43377 mempages -= reserve;
43378
43379 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43380 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43381 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43382
43383 dcache_init();
43384 inode_init();
43385 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43386 index b80bc84..0d46d1a 100644
43387 --- a/fs/debugfs/inode.c
43388 +++ b/fs/debugfs/inode.c
43389 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43390 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43391 {
43392 return debugfs_create_file(name,
43393 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43394 + S_IFDIR | S_IRWXU,
43395 +#else
43396 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43397 +#endif
43398 parent, NULL, NULL);
43399 }
43400 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43401 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43402 index ab35b11..b30af66 100644
43403 --- a/fs/ecryptfs/inode.c
43404 +++ b/fs/ecryptfs/inode.c
43405 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43406 old_fs = get_fs();
43407 set_fs(get_ds());
43408 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43409 - (char __user *)lower_buf,
43410 + (char __force_user *)lower_buf,
43411 lower_bufsiz);
43412 set_fs(old_fs);
43413 if (rc < 0)
43414 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43415 }
43416 old_fs = get_fs();
43417 set_fs(get_ds());
43418 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43419 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43420 set_fs(old_fs);
43421 if (rc < 0) {
43422 kfree(buf);
43423 @@ -733,7 +733,7 @@ out:
43424 static void
43425 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43426 {
43427 - char *buf = nd_get_link(nd);
43428 + const char *buf = nd_get_link(nd);
43429 if (!IS_ERR(buf)) {
43430 /* Free the char* */
43431 kfree(buf);
43432 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43433 index c0038f6..47ab347 100644
43434 --- a/fs/ecryptfs/miscdev.c
43435 +++ b/fs/ecryptfs/miscdev.c
43436 @@ -355,7 +355,7 @@ check_list:
43437 goto out_unlock_msg_ctx;
43438 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43439 if (msg_ctx->msg) {
43440 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43441 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43442 goto out_unlock_msg_ctx;
43443 i += packet_length_size;
43444 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43445 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43446 index b2a34a1..162fa69 100644
43447 --- a/fs/ecryptfs/read_write.c
43448 +++ b/fs/ecryptfs/read_write.c
43449 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43450 return -EIO;
43451 fs_save = get_fs();
43452 set_fs(get_ds());
43453 - rc = vfs_write(lower_file, data, size, &offset);
43454 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43455 set_fs(fs_save);
43456 mark_inode_dirty_sync(ecryptfs_inode);
43457 return rc;
43458 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43459 return -EIO;
43460 fs_save = get_fs();
43461 set_fs(get_ds());
43462 - rc = vfs_read(lower_file, data, size, &offset);
43463 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43464 set_fs(fs_save);
43465 return rc;
43466 }
43467 diff --git a/fs/exec.c b/fs/exec.c
43468 index 29e5f84..ec81452 100644
43469 --- a/fs/exec.c
43470 +++ b/fs/exec.c
43471 @@ -55,6 +55,15 @@
43472 #include <linux/pipe_fs_i.h>
43473 #include <linux/oom.h>
43474 #include <linux/compat.h>
43475 +#include <linux/random.h>
43476 +#include <linux/seq_file.h>
43477 +
43478 +#ifdef CONFIG_PAX_REFCOUNT
43479 +#include <linux/kallsyms.h>
43480 +#include <linux/kdebug.h>
43481 +#endif
43482 +
43483 +#include <trace/events/fs.h>
43484
43485 #include <asm/uaccess.h>
43486 #include <asm/mmu_context.h>
43487 @@ -66,6 +75,18 @@
43488
43489 #include <trace/events/sched.h>
43490
43491 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43492 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43493 +{
43494 + WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
43495 +}
43496 +#endif
43497 +
43498 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43499 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43500 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43501 +#endif
43502 +
43503 int core_uses_pid;
43504 char core_pattern[CORENAME_MAX_SIZE] = "core";
43505 unsigned int core_pipe_limit;
43506 @@ -75,7 +96,7 @@ struct core_name {
43507 char *corename;
43508 int used, size;
43509 };
43510 -static atomic_t call_count = ATOMIC_INIT(1);
43511 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43512
43513 /* The maximal length of core_pattern is also specified in sysctl.c */
43514
43515 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43516 int write)
43517 {
43518 struct page *page;
43519 - int ret;
43520
43521 -#ifdef CONFIG_STACK_GROWSUP
43522 - if (write) {
43523 - ret = expand_downwards(bprm->vma, pos);
43524 - if (ret < 0)
43525 - return NULL;
43526 - }
43527 -#endif
43528 - ret = get_user_pages(current, bprm->mm, pos,
43529 - 1, write, 1, &page, NULL);
43530 - if (ret <= 0)
43531 + if (0 > expand_downwards(bprm->vma, pos))
43532 + return NULL;
43533 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43534 return NULL;
43535
43536 if (write) {
43537 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43538 if (size <= ARG_MAX)
43539 return page;
43540
43541 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43542 + // only allow 512KB for argv+env on suid/sgid binaries
43543 + // to prevent easy ASLR exhaustion
43544 + if (((bprm->cred->euid != current_euid()) ||
43545 + (bprm->cred->egid != current_egid())) &&
43546 + (size > (512 * 1024))) {
43547 + put_page(page);
43548 + return NULL;
43549 + }
43550 +#endif
43551 +
43552 /*
43553 * Limit to 1/4-th the stack size for the argv+env strings.
43554 * This ensures that:
43555 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43556 vma->vm_end = STACK_TOP_MAX;
43557 vma->vm_start = vma->vm_end - PAGE_SIZE;
43558 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43559 +
43560 +#ifdef CONFIG_PAX_SEGMEXEC
43561 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43562 +#endif
43563 +
43564 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43565 INIT_LIST_HEAD(&vma->anon_vma_chain);
43566
43567 @@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43568 mm->stack_vm = mm->total_vm = 1;
43569 up_write(&mm->mmap_sem);
43570 bprm->p = vma->vm_end - sizeof(void *);
43571 +
43572 +#ifdef CONFIG_PAX_RANDUSTACK
43573 + if (randomize_va_space)
43574 + bprm->p ^= random32() & ~PAGE_MASK;
43575 +#endif
43576 +
43577 return 0;
43578 err:
43579 up_write(&mm->mmap_sem);
43580 @@ -399,19 +434,7 @@ err:
43581 return err;
43582 }
43583
43584 -struct user_arg_ptr {
43585 -#ifdef CONFIG_COMPAT
43586 - bool is_compat;
43587 -#endif
43588 - union {
43589 - const char __user *const __user *native;
43590 -#ifdef CONFIG_COMPAT
43591 - compat_uptr_t __user *compat;
43592 -#endif
43593 - } ptr;
43594 -};
43595 -
43596 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43597 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43598 {
43599 const char __user *native;
43600
43601 @@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43602 compat_uptr_t compat;
43603
43604 if (get_user(compat, argv.ptr.compat + nr))
43605 - return ERR_PTR(-EFAULT);
43606 + return (const char __force_user *)ERR_PTR(-EFAULT);
43607
43608 return compat_ptr(compat);
43609 }
43610 #endif
43611
43612 if (get_user(native, argv.ptr.native + nr))
43613 - return ERR_PTR(-EFAULT);
43614 + return (const char __force_user *)ERR_PTR(-EFAULT);
43615
43616 return native;
43617 }
43618 @@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43619 if (!p)
43620 break;
43621
43622 - if (IS_ERR(p))
43623 + if (IS_ERR((const char __force_kernel *)p))
43624 return -EFAULT;
43625
43626 if (i++ >= max)
43627 @@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43628
43629 ret = -EFAULT;
43630 str = get_user_arg_ptr(argv, argc);
43631 - if (IS_ERR(str))
43632 + if (IS_ERR((const char __force_kernel *)str))
43633 goto out;
43634
43635 len = strnlen_user(str, MAX_ARG_STRLEN);
43636 @@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43637 int r;
43638 mm_segment_t oldfs = get_fs();
43639 struct user_arg_ptr argv = {
43640 - .ptr.native = (const char __user *const __user *)__argv,
43641 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43642 };
43643
43644 set_fs(KERNEL_DS);
43645 @@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43646 unsigned long new_end = old_end - shift;
43647 struct mmu_gather tlb;
43648
43649 - BUG_ON(new_start > new_end);
43650 + if (new_start >= new_end || new_start < mmap_min_addr)
43651 + return -ENOMEM;
43652
43653 /*
43654 * ensure there are no vmas between where we want to go
43655 @@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43656 if (vma != find_vma(mm, new_start))
43657 return -EFAULT;
43658
43659 +#ifdef CONFIG_PAX_SEGMEXEC
43660 + BUG_ON(pax_find_mirror_vma(vma));
43661 +#endif
43662 +
43663 /*
43664 * cover the whole range: [new_start, old_end)
43665 */
43666 @@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43667 stack_top = arch_align_stack(stack_top);
43668 stack_top = PAGE_ALIGN(stack_top);
43669
43670 - if (unlikely(stack_top < mmap_min_addr) ||
43671 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43672 - return -ENOMEM;
43673 -
43674 stack_shift = vma->vm_end - stack_top;
43675
43676 bprm->p -= stack_shift;
43677 @@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43678 bprm->exec -= stack_shift;
43679
43680 down_write(&mm->mmap_sem);
43681 +
43682 + /* Move stack pages down in memory. */
43683 + if (stack_shift) {
43684 + ret = shift_arg_pages(vma, stack_shift);
43685 + if (ret)
43686 + goto out_unlock;
43687 + }
43688 +
43689 vm_flags = VM_STACK_FLAGS;
43690
43691 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43692 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43693 + vm_flags &= ~VM_EXEC;
43694 +
43695 +#ifdef CONFIG_PAX_MPROTECT
43696 + if (mm->pax_flags & MF_PAX_MPROTECT)
43697 + vm_flags &= ~VM_MAYEXEC;
43698 +#endif
43699 +
43700 + }
43701 +#endif
43702 +
43703 /*
43704 * Adjust stack execute permissions; explicitly enable for
43705 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43706 @@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43707 goto out_unlock;
43708 BUG_ON(prev != vma);
43709
43710 - /* Move stack pages down in memory. */
43711 - if (stack_shift) {
43712 - ret = shift_arg_pages(vma, stack_shift);
43713 - if (ret)
43714 - goto out_unlock;
43715 - }
43716 -
43717 /* mprotect_fixup is overkill to remove the temporary stack flags */
43718 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43719
43720 @@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43721
43722 fsnotify_open(file);
43723
43724 + trace_open_exec(name);
43725 +
43726 err = deny_write_access(file);
43727 if (err)
43728 goto exit;
43729 @@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43730 old_fs = get_fs();
43731 set_fs(get_ds());
43732 /* The cast to a user pointer is valid due to the set_fs() */
43733 - result = vfs_read(file, (void __user *)addr, count, &pos);
43734 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43735 set_fs(old_fs);
43736 return result;
43737 }
43738 @@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43739 }
43740 rcu_read_unlock();
43741
43742 - if (p->fs->users > n_fs) {
43743 + if (atomic_read(&p->fs->users) > n_fs) {
43744 bprm->unsafe |= LSM_UNSAFE_SHARE;
43745 } else {
43746 res = -EAGAIN;
43747 @@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43748
43749 EXPORT_SYMBOL(search_binary_handler);
43750
43751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43752 +static DEFINE_PER_CPU(u64, exec_counter);
43753 +static int __init init_exec_counters(void)
43754 +{
43755 + unsigned int cpu;
43756 +
43757 + for_each_possible_cpu(cpu) {
43758 + per_cpu(exec_counter, cpu) = (u64)cpu;
43759 + }
43760 +
43761 + return 0;
43762 +}
43763 +early_initcall(init_exec_counters);
43764 +static inline void increment_exec_counter(void)
43765 +{
43766 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43767 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43768 +}
43769 +#else
43770 +static inline void increment_exec_counter(void) {}
43771 +#endif
43772 +
43773 /*
43774 * sys_execve() executes a new program.
43775 */
43776 @@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43777 struct user_arg_ptr envp,
43778 struct pt_regs *regs)
43779 {
43780 +#ifdef CONFIG_GRKERNSEC
43781 + struct file *old_exec_file;
43782 + struct acl_subject_label *old_acl;
43783 + struct rlimit old_rlim[RLIM_NLIMITS];
43784 +#endif
43785 struct linux_binprm *bprm;
43786 struct file *file;
43787 struct files_struct *displaced;
43788 @@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43789 int retval;
43790 const struct cred *cred = current_cred();
43791
43792 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43793 +
43794 /*
43795 * We move the actual failure in case of RLIMIT_NPROC excess from
43796 * set*uid() to execve() because too many poorly written programs
43797 @@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43798 if (IS_ERR(file))
43799 goto out_unmark;
43800
43801 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43802 + retval = -EPERM;
43803 + goto out_file;
43804 + }
43805 +
43806 sched_exec();
43807
43808 bprm->file = file;
43809 bprm->filename = filename;
43810 bprm->interp = filename;
43811
43812 + if (gr_process_user_ban()) {
43813 + retval = -EPERM;
43814 + goto out_file;
43815 + }
43816 +
43817 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43818 + retval = -EACCES;
43819 + goto out_file;
43820 + }
43821 +
43822 retval = bprm_mm_init(bprm);
43823 if (retval)
43824 goto out_file;
43825 @@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
43826 if (retval < 0)
43827 goto out;
43828
43829 +#ifdef CONFIG_GRKERNSEC
43830 + old_acl = current->acl;
43831 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43832 + old_exec_file = current->exec_file;
43833 + get_file(file);
43834 + current->exec_file = file;
43835 +#endif
43836 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43837 + /* limit suid stack to 8MB
43838 + we saved the old limits above and will restore them if this exec fails
43839 + */
43840 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43841 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43842 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43843 +#endif
43844 +
43845 + if (!gr_tpe_allow(file)) {
43846 + retval = -EACCES;
43847 + goto out_fail;
43848 + }
43849 +
43850 + if (gr_check_crash_exec(file)) {
43851 + retval = -EACCES;
43852 + goto out_fail;
43853 + }
43854 +
43855 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43856 + bprm->unsafe);
43857 + if (retval < 0)
43858 + goto out_fail;
43859 +
43860 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43861 if (retval < 0)
43862 - goto out;
43863 + goto out_fail;
43864
43865 bprm->exec = bprm->p;
43866 retval = copy_strings(bprm->envc, envp, bprm);
43867 if (retval < 0)
43868 - goto out;
43869 + goto out_fail;
43870
43871 retval = copy_strings(bprm->argc, argv, bprm);
43872 if (retval < 0)
43873 - goto out;
43874 + goto out_fail;
43875 +
43876 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43877 +
43878 + gr_handle_exec_args(bprm, argv);
43879
43880 retval = search_binary_handler(bprm,regs);
43881 if (retval < 0)
43882 - goto out;
43883 + goto out_fail;
43884 +#ifdef CONFIG_GRKERNSEC
43885 + if (old_exec_file)
43886 + fput(old_exec_file);
43887 +#endif
43888
43889 /* execve succeeded */
43890 +
43891 + increment_exec_counter();
43892 current->fs->in_exec = 0;
43893 current->in_execve = 0;
43894 acct_update_integrals(current);
43895 @@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
43896 put_files_struct(displaced);
43897 return retval;
43898
43899 +out_fail:
43900 +#ifdef CONFIG_GRKERNSEC
43901 + current->acl = old_acl;
43902 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43903 + fput(current->exec_file);
43904 + current->exec_file = old_exec_file;
43905 +#endif
43906 +
43907 out:
43908 if (bprm->mm) {
43909 acct_arg_size(bprm, 0);
43910 @@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
43911 {
43912 char *old_corename = cn->corename;
43913
43914 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43915 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43916 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43917
43918 if (!cn->corename) {
43919 @@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
43920 int pid_in_pattern = 0;
43921 int err = 0;
43922
43923 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43924 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43925 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43926 cn->used = 0;
43927
43928 @@ -1821,6 +1953,228 @@ out:
43929 return ispipe;
43930 }
43931
43932 +int pax_check_flags(unsigned long *flags)
43933 +{
43934 + int retval = 0;
43935 +
43936 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43937 + if (*flags & MF_PAX_SEGMEXEC)
43938 + {
43939 + *flags &= ~MF_PAX_SEGMEXEC;
43940 + retval = -EINVAL;
43941 + }
43942 +#endif
43943 +
43944 + if ((*flags & MF_PAX_PAGEEXEC)
43945 +
43946 +#ifdef CONFIG_PAX_PAGEEXEC
43947 + && (*flags & MF_PAX_SEGMEXEC)
43948 +#endif
43949 +
43950 + )
43951 + {
43952 + *flags &= ~MF_PAX_PAGEEXEC;
43953 + retval = -EINVAL;
43954 + }
43955 +
43956 + if ((*flags & MF_PAX_MPROTECT)
43957 +
43958 +#ifdef CONFIG_PAX_MPROTECT
43959 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43960 +#endif
43961 +
43962 + )
43963 + {
43964 + *flags &= ~MF_PAX_MPROTECT;
43965 + retval = -EINVAL;
43966 + }
43967 +
43968 + if ((*flags & MF_PAX_EMUTRAMP)
43969 +
43970 +#ifdef CONFIG_PAX_EMUTRAMP
43971 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43972 +#endif
43973 +
43974 + )
43975 + {
43976 + *flags &= ~MF_PAX_EMUTRAMP;
43977 + retval = -EINVAL;
43978 + }
43979 +
43980 + return retval;
43981 +}
43982 +
43983 +EXPORT_SYMBOL(pax_check_flags);
43984 +
43985 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43986 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43987 +{
43988 + struct task_struct *tsk = current;
43989 + struct mm_struct *mm = current->mm;
43990 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
43991 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
43992 + char *path_exec = NULL;
43993 + char *path_fault = NULL;
43994 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
43995 +
43996 + if (buffer_exec && buffer_fault) {
43997 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
43998 +
43999 + down_read(&mm->mmap_sem);
44000 + vma = mm->mmap;
44001 + while (vma && (!vma_exec || !vma_fault)) {
44002 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44003 + vma_exec = vma;
44004 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44005 + vma_fault = vma;
44006 + vma = vma->vm_next;
44007 + }
44008 + if (vma_exec) {
44009 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44010 + if (IS_ERR(path_exec))
44011 + path_exec = "<path too long>";
44012 + else {
44013 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44014 + if (path_exec) {
44015 + *path_exec = 0;
44016 + path_exec = buffer_exec;
44017 + } else
44018 + path_exec = "<path too long>";
44019 + }
44020 + }
44021 + if (vma_fault) {
44022 + start = vma_fault->vm_start;
44023 + end = vma_fault->vm_end;
44024 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44025 + if (vma_fault->vm_file) {
44026 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44027 + if (IS_ERR(path_fault))
44028 + path_fault = "<path too long>";
44029 + else {
44030 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44031 + if (path_fault) {
44032 + *path_fault = 0;
44033 + path_fault = buffer_fault;
44034 + } else
44035 + path_fault = "<path too long>";
44036 + }
44037 + } else
44038 + path_fault = "<anonymous mapping>";
44039 + }
44040 + up_read(&mm->mmap_sem);
44041 + }
44042 + if (tsk->signal->curr_ip)
44043 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44044 + else
44045 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44046 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44047 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44048 + task_uid(tsk), task_euid(tsk), pc, sp);
44049 + free_page((unsigned long)buffer_exec);
44050 + free_page((unsigned long)buffer_fault);
44051 + pax_report_insns(regs, pc, sp);
44052 + do_coredump(SIGKILL, SIGKILL, regs);
44053 +}
44054 +#endif
44055 +
44056 +#ifdef CONFIG_PAX_REFCOUNT
44057 +void pax_report_refcount_overflow(struct pt_regs *regs)
44058 +{
44059 + if (current->signal->curr_ip)
44060 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44061 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44062 + else
44063 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44064 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44065 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44066 + show_regs(regs);
44067 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44068 +}
44069 +#endif
44070 +
44071 +#ifdef CONFIG_PAX_USERCOPY
44072 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44073 +int object_is_on_stack(const void *obj, unsigned long len)
44074 +{
44075 + const void * const stack = task_stack_page(current);
44076 + const void * const stackend = stack + THREAD_SIZE;
44077 +
44078 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44079 + const void *frame = NULL;
44080 + const void *oldframe;
44081 +#endif
44082 +
44083 + if (obj + len < obj)
44084 + return -1;
44085 +
44086 + if (obj + len <= stack || stackend <= obj)
44087 + return 0;
44088 +
44089 + if (obj < stack || stackend < obj + len)
44090 + return -1;
44091 +
44092 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44093 + oldframe = __builtin_frame_address(1);
44094 + if (oldframe)
44095 + frame = __builtin_frame_address(2);
44096 + /*
44097 + low ----------------------------------------------> high
44098 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44099 + ^----------------^
44100 + allow copies only within here
44101 + */
44102 + while (stack <= frame && frame < stackend) {
44103 + /* if obj + len extends past the last frame, this
44104 + check won't pass and the next frame will be 0,
44105 + causing us to bail out and correctly report
44106 + the copy as invalid
44107 + */
44108 + if (obj + len <= frame)
44109 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44110 + oldframe = frame;
44111 + frame = *(const void * const *)frame;
44112 + }
44113 + return -1;
44114 +#else
44115 + return 1;
44116 +#endif
44117 +}
44118 +
44119 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44120 +{
44121 + if (current->signal->curr_ip)
44122 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44123 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44124 + else
44125 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44126 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44127 + dump_stack();
44128 + gr_handle_kernel_exploit();
44129 + do_group_exit(SIGKILL);
44130 +}
44131 +#endif
44132 +
44133 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44134 +void pax_track_stack(void)
44135 +{
44136 + unsigned long sp = (unsigned long)&sp;
44137 + if (sp < current_thread_info()->lowest_stack &&
44138 + sp > (unsigned long)task_stack_page(current))
44139 + current_thread_info()->lowest_stack = sp;
44140 +}
44141 +EXPORT_SYMBOL(pax_track_stack);
44142 +#endif
44143 +
44144 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44145 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44146 +{
44147 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44148 + dump_stack();
44149 + do_group_exit(SIGKILL);
44150 +}
44151 +EXPORT_SYMBOL(report_size_overflow);
44152 +#endif
44153 +
44154 static int zap_process(struct task_struct *start, int exit_code)
44155 {
44156 struct task_struct *t;
44157 @@ -2018,17 +2372,17 @@ static void wait_for_dump_helpers(struct file *file)
44158 pipe = file->f_path.dentry->d_inode->i_pipe;
44159
44160 pipe_lock(pipe);
44161 - pipe->readers++;
44162 - pipe->writers--;
44163 + atomic_inc(&pipe->readers);
44164 + atomic_dec(&pipe->writers);
44165
44166 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44167 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44168 wake_up_interruptible_sync(&pipe->wait);
44169 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44170 pipe_wait(pipe);
44171 }
44172
44173 - pipe->readers--;
44174 - pipe->writers++;
44175 + atomic_dec(&pipe->readers);
44176 + atomic_inc(&pipe->writers);
44177 pipe_unlock(pipe);
44178
44179 }
44180 @@ -2089,7 +2443,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44181 int retval = 0;
44182 int flag = 0;
44183 int ispipe;
44184 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44185 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44186 struct coredump_params cprm = {
44187 .signr = signr,
44188 .regs = regs,
44189 @@ -2104,6 +2458,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44190
44191 audit_core_dumps(signr);
44192
44193 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44194 + gr_handle_brute_attach(current, cprm.mm_flags);
44195 +
44196 binfmt = mm->binfmt;
44197 if (!binfmt || !binfmt->core_dump)
44198 goto fail;
44199 @@ -2171,7 +2528,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44200 }
44201 cprm.limit = RLIM_INFINITY;
44202
44203 - dump_count = atomic_inc_return(&core_dump_count);
44204 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44205 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44206 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44207 task_tgid_vnr(current), current->comm);
44208 @@ -2198,6 +2555,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44209 } else {
44210 struct inode *inode;
44211
44212 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44213 +
44214 if (cprm.limit < binfmt->min_coredump)
44215 goto fail_unlock;
44216
44217 @@ -2241,7 +2600,7 @@ close_fail:
44218 filp_close(cprm.file, NULL);
44219 fail_dropcount:
44220 if (ispipe)
44221 - atomic_dec(&core_dump_count);
44222 + atomic_dec_unchecked(&core_dump_count);
44223 fail_unlock:
44224 kfree(cn.corename);
44225 fail_corename:
44226 @@ -2260,7 +2619,7 @@ fail:
44227 */
44228 int dump_write(struct file *file, const void *addr, int nr)
44229 {
44230 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44231 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44232 }
44233 EXPORT_SYMBOL(dump_write);
44234
44235 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44236 index a8cbe1b..fed04cb 100644
44237 --- a/fs/ext2/balloc.c
44238 +++ b/fs/ext2/balloc.c
44239 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44240
44241 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44242 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44243 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44244 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44245 sbi->s_resuid != current_fsuid() &&
44246 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44247 return 0;
44248 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44249 index baac1b1..1499b62 100644
44250 --- a/fs/ext3/balloc.c
44251 +++ b/fs/ext3/balloc.c
44252 @@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44253
44254 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44255 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44256 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44257 + if (free_blocks < root_blocks + 1 &&
44258 !use_reservation && sbi->s_resuid != current_fsuid() &&
44259 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44260 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44261 + !capable_nolog(CAP_SYS_RESOURCE)) {
44262 return 0;
44263 }
44264 return 1;
44265 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44266 index 8da837b..ed3835b 100644
44267 --- a/fs/ext4/balloc.c
44268 +++ b/fs/ext4/balloc.c
44269 @@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44270 /* Hm, nope. Are (enough) root reserved clusters available? */
44271 if (sbi->s_resuid == current_fsuid() ||
44272 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44273 - capable(CAP_SYS_RESOURCE) ||
44274 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44275 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44276 + capable_nolog(CAP_SYS_RESOURCE)) {
44277
44278 if (free_clusters >= (nclusters + dirty_clusters))
44279 return 1;
44280 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44281 index 0e01e90..ae2bd5e 100644
44282 --- a/fs/ext4/ext4.h
44283 +++ b/fs/ext4/ext4.h
44284 @@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44285 unsigned long s_mb_last_start;
44286
44287 /* stats for buddy allocator */
44288 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44289 - atomic_t s_bal_success; /* we found long enough chunks */
44290 - atomic_t s_bal_allocated; /* in blocks */
44291 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44292 - atomic_t s_bal_goals; /* goal hits */
44293 - atomic_t s_bal_breaks; /* too long searches */
44294 - atomic_t s_bal_2orders; /* 2^order hits */
44295 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44296 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44297 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44298 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44299 + atomic_unchecked_t s_bal_goals; /* goal hits */
44300 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44301 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44302 spinlock_t s_bal_lock;
44303 unsigned long s_mb_buddies_generated;
44304 unsigned long long s_mb_generation_time;
44305 - atomic_t s_mb_lost_chunks;
44306 - atomic_t s_mb_preallocated;
44307 - atomic_t s_mb_discarded;
44308 + atomic_unchecked_t s_mb_lost_chunks;
44309 + atomic_unchecked_t s_mb_preallocated;
44310 + atomic_unchecked_t s_mb_discarded;
44311 atomic_t s_lock_busy;
44312
44313 /* locality groups */
44314 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44315 index 6b0a57e..1955a44 100644
44316 --- a/fs/ext4/mballoc.c
44317 +++ b/fs/ext4/mballoc.c
44318 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44319 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44320
44321 if (EXT4_SB(sb)->s_mb_stats)
44322 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44323 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44324
44325 break;
44326 }
44327 @@ -2041,7 +2041,7 @@ repeat:
44328 ac->ac_status = AC_STATUS_CONTINUE;
44329 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44330 cr = 3;
44331 - atomic_inc(&sbi->s_mb_lost_chunks);
44332 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44333 goto repeat;
44334 }
44335 }
44336 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44337 if (sbi->s_mb_stats) {
44338 ext4_msg(sb, KERN_INFO,
44339 "mballoc: %u blocks %u reqs (%u success)",
44340 - atomic_read(&sbi->s_bal_allocated),
44341 - atomic_read(&sbi->s_bal_reqs),
44342 - atomic_read(&sbi->s_bal_success));
44343 + atomic_read_unchecked(&sbi->s_bal_allocated),
44344 + atomic_read_unchecked(&sbi->s_bal_reqs),
44345 + atomic_read_unchecked(&sbi->s_bal_success));
44346 ext4_msg(sb, KERN_INFO,
44347 "mballoc: %u extents scanned, %u goal hits, "
44348 "%u 2^N hits, %u breaks, %u lost",
44349 - atomic_read(&sbi->s_bal_ex_scanned),
44350 - atomic_read(&sbi->s_bal_goals),
44351 - atomic_read(&sbi->s_bal_2orders),
44352 - atomic_read(&sbi->s_bal_breaks),
44353 - atomic_read(&sbi->s_mb_lost_chunks));
44354 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44355 + atomic_read_unchecked(&sbi->s_bal_goals),
44356 + atomic_read_unchecked(&sbi->s_bal_2orders),
44357 + atomic_read_unchecked(&sbi->s_bal_breaks),
44358 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44359 ext4_msg(sb, KERN_INFO,
44360 "mballoc: %lu generated and it took %Lu",
44361 sbi->s_mb_buddies_generated,
44362 sbi->s_mb_generation_time);
44363 ext4_msg(sb, KERN_INFO,
44364 "mballoc: %u preallocated, %u discarded",
44365 - atomic_read(&sbi->s_mb_preallocated),
44366 - atomic_read(&sbi->s_mb_discarded));
44367 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44368 + atomic_read_unchecked(&sbi->s_mb_discarded));
44369 }
44370
44371 free_percpu(sbi->s_locality_groups);
44372 @@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44373 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44374
44375 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44376 - atomic_inc(&sbi->s_bal_reqs);
44377 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44378 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44379 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44380 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44381 - atomic_inc(&sbi->s_bal_success);
44382 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44383 + atomic_inc_unchecked(&sbi->s_bal_success);
44384 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44385 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44386 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44387 - atomic_inc(&sbi->s_bal_goals);
44388 + atomic_inc_unchecked(&sbi->s_bal_goals);
44389 if (ac->ac_found > sbi->s_mb_max_to_scan)
44390 - atomic_inc(&sbi->s_bal_breaks);
44391 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44392 }
44393
44394 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44395 @@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44396 trace_ext4_mb_new_inode_pa(ac, pa);
44397
44398 ext4_mb_use_inode_pa(ac, pa);
44399 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44400 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44401
44402 ei = EXT4_I(ac->ac_inode);
44403 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44404 @@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44405 trace_ext4_mb_new_group_pa(ac, pa);
44406
44407 ext4_mb_use_group_pa(ac, pa);
44408 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44409 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44410
44411 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44412 lg = ac->ac_lg;
44413 @@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44414 * from the bitmap and continue.
44415 */
44416 }
44417 - atomic_add(free, &sbi->s_mb_discarded);
44418 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44419
44420 return err;
44421 }
44422 @@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44423 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44424 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44425 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44426 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44427 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44428 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44429
44430 return 0;
44431 diff --git a/fs/fcntl.c b/fs/fcntl.c
44432 index 75e7c1f..1eb3e4d 100644
44433 --- a/fs/fcntl.c
44434 +++ b/fs/fcntl.c
44435 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44436 if (err)
44437 return err;
44438
44439 + if (gr_handle_chroot_fowner(pid, type))
44440 + return -ENOENT;
44441 + if (gr_check_protected_task_fowner(pid, type))
44442 + return -EACCES;
44443 +
44444 f_modown(filp, pid, type, force);
44445 return 0;
44446 }
44447 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44448
44449 static int f_setown_ex(struct file *filp, unsigned long arg)
44450 {
44451 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44452 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44453 struct f_owner_ex owner;
44454 struct pid *pid;
44455 int type;
44456 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44457
44458 static int f_getown_ex(struct file *filp, unsigned long arg)
44459 {
44460 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44461 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44462 struct f_owner_ex owner;
44463 int ret = 0;
44464
44465 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44466 switch (cmd) {
44467 case F_DUPFD:
44468 case F_DUPFD_CLOEXEC:
44469 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44470 if (arg >= rlimit(RLIMIT_NOFILE))
44471 break;
44472 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44473 diff --git a/fs/fifo.c b/fs/fifo.c
44474 index b1a524d..4ee270e 100644
44475 --- a/fs/fifo.c
44476 +++ b/fs/fifo.c
44477 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44478 */
44479 filp->f_op = &read_pipefifo_fops;
44480 pipe->r_counter++;
44481 - if (pipe->readers++ == 0)
44482 + if (atomic_inc_return(&pipe->readers) == 1)
44483 wake_up_partner(inode);
44484
44485 - if (!pipe->writers) {
44486 + if (!atomic_read(&pipe->writers)) {
44487 if ((filp->f_flags & O_NONBLOCK)) {
44488 /* suppress POLLHUP until we have
44489 * seen a writer */
44490 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44491 * errno=ENXIO when there is no process reading the FIFO.
44492 */
44493 ret = -ENXIO;
44494 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44495 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44496 goto err;
44497
44498 filp->f_op = &write_pipefifo_fops;
44499 pipe->w_counter++;
44500 - if (!pipe->writers++)
44501 + if (atomic_inc_return(&pipe->writers) == 1)
44502 wake_up_partner(inode);
44503
44504 - if (!pipe->readers) {
44505 + if (!atomic_read(&pipe->readers)) {
44506 wait_for_partner(inode, &pipe->r_counter);
44507 if (signal_pending(current))
44508 goto err_wr;
44509 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44510 */
44511 filp->f_op = &rdwr_pipefifo_fops;
44512
44513 - pipe->readers++;
44514 - pipe->writers++;
44515 + atomic_inc(&pipe->readers);
44516 + atomic_inc(&pipe->writers);
44517 pipe->r_counter++;
44518 pipe->w_counter++;
44519 - if (pipe->readers == 1 || pipe->writers == 1)
44520 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44521 wake_up_partner(inode);
44522 break;
44523
44524 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44525 return 0;
44526
44527 err_rd:
44528 - if (!--pipe->readers)
44529 + if (atomic_dec_and_test(&pipe->readers))
44530 wake_up_interruptible(&pipe->wait);
44531 ret = -ERESTARTSYS;
44532 goto err;
44533
44534 err_wr:
44535 - if (!--pipe->writers)
44536 + if (atomic_dec_and_test(&pipe->writers))
44537 wake_up_interruptible(&pipe->wait);
44538 ret = -ERESTARTSYS;
44539 goto err;
44540
44541 err:
44542 - if (!pipe->readers && !pipe->writers)
44543 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44544 free_pipe_info(inode);
44545
44546 err_nocleanup:
44547 diff --git a/fs/file.c b/fs/file.c
44548 index ba3f605..fade102 100644
44549 --- a/fs/file.c
44550 +++ b/fs/file.c
44551 @@ -15,6 +15,7 @@
44552 #include <linux/slab.h>
44553 #include <linux/vmalloc.h>
44554 #include <linux/file.h>
44555 +#include <linux/security.h>
44556 #include <linux/fdtable.h>
44557 #include <linux/bitops.h>
44558 #include <linux/interrupt.h>
44559 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44560 * N.B. For clone tasks sharing a files structure, this test
44561 * will limit the total number of files that can be opened.
44562 */
44563 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44564 if (nr >= rlimit(RLIMIT_NOFILE))
44565 return -EMFILE;
44566
44567 diff --git a/fs/filesystems.c b/fs/filesystems.c
44568 index 96f2428..f5eeb8e 100644
44569 --- a/fs/filesystems.c
44570 +++ b/fs/filesystems.c
44571 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44572 int len = dot ? dot - name : strlen(name);
44573
44574 fs = __get_fs_type(name, len);
44575 +
44576 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44577 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44578 +#else
44579 if (!fs && (request_module("%.*s", len, name) == 0))
44580 +#endif
44581 fs = __get_fs_type(name, len);
44582
44583 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44584 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44585 index e159e68..e7d2a6f 100644
44586 --- a/fs/fs_struct.c
44587 +++ b/fs/fs_struct.c
44588 @@ -4,6 +4,7 @@
44589 #include <linux/path.h>
44590 #include <linux/slab.h>
44591 #include <linux/fs_struct.h>
44592 +#include <linux/grsecurity.h>
44593 #include "internal.h"
44594
44595 static inline void path_get_longterm(struct path *path)
44596 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44597 write_seqcount_begin(&fs->seq);
44598 old_root = fs->root;
44599 fs->root = *path;
44600 + gr_set_chroot_entries(current, path);
44601 write_seqcount_end(&fs->seq);
44602 spin_unlock(&fs->lock);
44603 if (old_root.dentry)
44604 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44605 return 1;
44606 }
44607
44608 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44609 +{
44610 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44611 + return 0;
44612 + *p = *new;
44613 +
44614 + gr_set_chroot_entries(task, new);
44615 +
44616 + return 1;
44617 +}
44618 +
44619 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44620 {
44621 struct task_struct *g, *p;
44622 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44623 int hits = 0;
44624 spin_lock(&fs->lock);
44625 write_seqcount_begin(&fs->seq);
44626 - hits += replace_path(&fs->root, old_root, new_root);
44627 + hits += replace_root_path(p, &fs->root, old_root, new_root);
44628 hits += replace_path(&fs->pwd, old_root, new_root);
44629 write_seqcount_end(&fs->seq);
44630 while (hits--) {
44631 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44632 task_lock(tsk);
44633 spin_lock(&fs->lock);
44634 tsk->fs = NULL;
44635 - kill = !--fs->users;
44636 + gr_clear_chroot_entries(tsk);
44637 + kill = !atomic_dec_return(&fs->users);
44638 spin_unlock(&fs->lock);
44639 task_unlock(tsk);
44640 if (kill)
44641 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44642 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44643 /* We don't need to lock fs - think why ;-) */
44644 if (fs) {
44645 - fs->users = 1;
44646 + atomic_set(&fs->users, 1);
44647 fs->in_exec = 0;
44648 spin_lock_init(&fs->lock);
44649 seqcount_init(&fs->seq);
44650 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44651 spin_lock(&old->lock);
44652 fs->root = old->root;
44653 path_get_longterm(&fs->root);
44654 + /* instead of calling gr_set_chroot_entries here,
44655 + we call it from every caller of this function
44656 + */
44657 fs->pwd = old->pwd;
44658 path_get_longterm(&fs->pwd);
44659 spin_unlock(&old->lock);
44660 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44661
44662 task_lock(current);
44663 spin_lock(&fs->lock);
44664 - kill = !--fs->users;
44665 + kill = !atomic_dec_return(&fs->users);
44666 current->fs = new_fs;
44667 + gr_set_chroot_entries(current, &new_fs->root);
44668 spin_unlock(&fs->lock);
44669 task_unlock(current);
44670
44671 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44672
44673 int current_umask(void)
44674 {
44675 - return current->fs->umask;
44676 + return current->fs->umask | gr_acl_umask();
44677 }
44678 EXPORT_SYMBOL(current_umask);
44679
44680 /* to be mentioned only in INIT_TASK */
44681 struct fs_struct init_fs = {
44682 - .users = 1,
44683 + .users = ATOMIC_INIT(1),
44684 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44685 .seq = SEQCNT_ZERO,
44686 .umask = 0022,
44687 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44688 task_lock(current);
44689
44690 spin_lock(&init_fs.lock);
44691 - init_fs.users++;
44692 + atomic_inc(&init_fs.users);
44693 spin_unlock(&init_fs.lock);
44694
44695 spin_lock(&fs->lock);
44696 current->fs = &init_fs;
44697 - kill = !--fs->users;
44698 + gr_set_chroot_entries(current, &current->fs->root);
44699 + kill = !atomic_dec_return(&fs->users);
44700 spin_unlock(&fs->lock);
44701
44702 task_unlock(current);
44703 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44704 index 9905350..02eaec4 100644
44705 --- a/fs/fscache/cookie.c
44706 +++ b/fs/fscache/cookie.c
44707 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44708 parent ? (char *) parent->def->name : "<no-parent>",
44709 def->name, netfs_data);
44710
44711 - fscache_stat(&fscache_n_acquires);
44712 + fscache_stat_unchecked(&fscache_n_acquires);
44713
44714 /* if there's no parent cookie, then we don't create one here either */
44715 if (!parent) {
44716 - fscache_stat(&fscache_n_acquires_null);
44717 + fscache_stat_unchecked(&fscache_n_acquires_null);
44718 _leave(" [no parent]");
44719 return NULL;
44720 }
44721 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44722 /* allocate and initialise a cookie */
44723 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44724 if (!cookie) {
44725 - fscache_stat(&fscache_n_acquires_oom);
44726 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44727 _leave(" [ENOMEM]");
44728 return NULL;
44729 }
44730 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44731
44732 switch (cookie->def->type) {
44733 case FSCACHE_COOKIE_TYPE_INDEX:
44734 - fscache_stat(&fscache_n_cookie_index);
44735 + fscache_stat_unchecked(&fscache_n_cookie_index);
44736 break;
44737 case FSCACHE_COOKIE_TYPE_DATAFILE:
44738 - fscache_stat(&fscache_n_cookie_data);
44739 + fscache_stat_unchecked(&fscache_n_cookie_data);
44740 break;
44741 default:
44742 - fscache_stat(&fscache_n_cookie_special);
44743 + fscache_stat_unchecked(&fscache_n_cookie_special);
44744 break;
44745 }
44746
44747 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44748 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44749 atomic_dec(&parent->n_children);
44750 __fscache_cookie_put(cookie);
44751 - fscache_stat(&fscache_n_acquires_nobufs);
44752 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44753 _leave(" = NULL");
44754 return NULL;
44755 }
44756 }
44757
44758 - fscache_stat(&fscache_n_acquires_ok);
44759 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44760 _leave(" = %p", cookie);
44761 return cookie;
44762 }
44763 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44764 cache = fscache_select_cache_for_object(cookie->parent);
44765 if (!cache) {
44766 up_read(&fscache_addremove_sem);
44767 - fscache_stat(&fscache_n_acquires_no_cache);
44768 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44769 _leave(" = -ENOMEDIUM [no cache]");
44770 return -ENOMEDIUM;
44771 }
44772 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44773 object = cache->ops->alloc_object(cache, cookie);
44774 fscache_stat_d(&fscache_n_cop_alloc_object);
44775 if (IS_ERR(object)) {
44776 - fscache_stat(&fscache_n_object_no_alloc);
44777 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44778 ret = PTR_ERR(object);
44779 goto error;
44780 }
44781
44782 - fscache_stat(&fscache_n_object_alloc);
44783 + fscache_stat_unchecked(&fscache_n_object_alloc);
44784
44785 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44786
44787 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44788 struct fscache_object *object;
44789 struct hlist_node *_p;
44790
44791 - fscache_stat(&fscache_n_updates);
44792 + fscache_stat_unchecked(&fscache_n_updates);
44793
44794 if (!cookie) {
44795 - fscache_stat(&fscache_n_updates_null);
44796 + fscache_stat_unchecked(&fscache_n_updates_null);
44797 _leave(" [no cookie]");
44798 return;
44799 }
44800 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44801 struct fscache_object *object;
44802 unsigned long event;
44803
44804 - fscache_stat(&fscache_n_relinquishes);
44805 + fscache_stat_unchecked(&fscache_n_relinquishes);
44806 if (retire)
44807 - fscache_stat(&fscache_n_relinquishes_retire);
44808 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44809
44810 if (!cookie) {
44811 - fscache_stat(&fscache_n_relinquishes_null);
44812 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
44813 _leave(" [no cookie]");
44814 return;
44815 }
44816 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44817
44818 /* wait for the cookie to finish being instantiated (or to fail) */
44819 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44820 - fscache_stat(&fscache_n_relinquishes_waitcrt);
44821 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44822 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44823 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44824 }
44825 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44826 index f6aad48..88dcf26 100644
44827 --- a/fs/fscache/internal.h
44828 +++ b/fs/fscache/internal.h
44829 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44830 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44831 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44832
44833 -extern atomic_t fscache_n_op_pend;
44834 -extern atomic_t fscache_n_op_run;
44835 -extern atomic_t fscache_n_op_enqueue;
44836 -extern atomic_t fscache_n_op_deferred_release;
44837 -extern atomic_t fscache_n_op_release;
44838 -extern atomic_t fscache_n_op_gc;
44839 -extern atomic_t fscache_n_op_cancelled;
44840 -extern atomic_t fscache_n_op_rejected;
44841 +extern atomic_unchecked_t fscache_n_op_pend;
44842 +extern atomic_unchecked_t fscache_n_op_run;
44843 +extern atomic_unchecked_t fscache_n_op_enqueue;
44844 +extern atomic_unchecked_t fscache_n_op_deferred_release;
44845 +extern atomic_unchecked_t fscache_n_op_release;
44846 +extern atomic_unchecked_t fscache_n_op_gc;
44847 +extern atomic_unchecked_t fscache_n_op_cancelled;
44848 +extern atomic_unchecked_t fscache_n_op_rejected;
44849
44850 -extern atomic_t fscache_n_attr_changed;
44851 -extern atomic_t fscache_n_attr_changed_ok;
44852 -extern atomic_t fscache_n_attr_changed_nobufs;
44853 -extern atomic_t fscache_n_attr_changed_nomem;
44854 -extern atomic_t fscache_n_attr_changed_calls;
44855 +extern atomic_unchecked_t fscache_n_attr_changed;
44856 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
44857 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44858 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44859 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
44860
44861 -extern atomic_t fscache_n_allocs;
44862 -extern atomic_t fscache_n_allocs_ok;
44863 -extern atomic_t fscache_n_allocs_wait;
44864 -extern atomic_t fscache_n_allocs_nobufs;
44865 -extern atomic_t fscache_n_allocs_intr;
44866 -extern atomic_t fscache_n_allocs_object_dead;
44867 -extern atomic_t fscache_n_alloc_ops;
44868 -extern atomic_t fscache_n_alloc_op_waits;
44869 +extern atomic_unchecked_t fscache_n_allocs;
44870 +extern atomic_unchecked_t fscache_n_allocs_ok;
44871 +extern atomic_unchecked_t fscache_n_allocs_wait;
44872 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
44873 +extern atomic_unchecked_t fscache_n_allocs_intr;
44874 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
44875 +extern atomic_unchecked_t fscache_n_alloc_ops;
44876 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
44877
44878 -extern atomic_t fscache_n_retrievals;
44879 -extern atomic_t fscache_n_retrievals_ok;
44880 -extern atomic_t fscache_n_retrievals_wait;
44881 -extern atomic_t fscache_n_retrievals_nodata;
44882 -extern atomic_t fscache_n_retrievals_nobufs;
44883 -extern atomic_t fscache_n_retrievals_intr;
44884 -extern atomic_t fscache_n_retrievals_nomem;
44885 -extern atomic_t fscache_n_retrievals_object_dead;
44886 -extern atomic_t fscache_n_retrieval_ops;
44887 -extern atomic_t fscache_n_retrieval_op_waits;
44888 +extern atomic_unchecked_t fscache_n_retrievals;
44889 +extern atomic_unchecked_t fscache_n_retrievals_ok;
44890 +extern atomic_unchecked_t fscache_n_retrievals_wait;
44891 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
44892 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44893 +extern atomic_unchecked_t fscache_n_retrievals_intr;
44894 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
44895 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44896 +extern atomic_unchecked_t fscache_n_retrieval_ops;
44897 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44898
44899 -extern atomic_t fscache_n_stores;
44900 -extern atomic_t fscache_n_stores_ok;
44901 -extern atomic_t fscache_n_stores_again;
44902 -extern atomic_t fscache_n_stores_nobufs;
44903 -extern atomic_t fscache_n_stores_oom;
44904 -extern atomic_t fscache_n_store_ops;
44905 -extern atomic_t fscache_n_store_calls;
44906 -extern atomic_t fscache_n_store_pages;
44907 -extern atomic_t fscache_n_store_radix_deletes;
44908 -extern atomic_t fscache_n_store_pages_over_limit;
44909 +extern atomic_unchecked_t fscache_n_stores;
44910 +extern atomic_unchecked_t fscache_n_stores_ok;
44911 +extern atomic_unchecked_t fscache_n_stores_again;
44912 +extern atomic_unchecked_t fscache_n_stores_nobufs;
44913 +extern atomic_unchecked_t fscache_n_stores_oom;
44914 +extern atomic_unchecked_t fscache_n_store_ops;
44915 +extern atomic_unchecked_t fscache_n_store_calls;
44916 +extern atomic_unchecked_t fscache_n_store_pages;
44917 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
44918 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44919
44920 -extern atomic_t fscache_n_store_vmscan_not_storing;
44921 -extern atomic_t fscache_n_store_vmscan_gone;
44922 -extern atomic_t fscache_n_store_vmscan_busy;
44923 -extern atomic_t fscache_n_store_vmscan_cancelled;
44924 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44925 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44926 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44927 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44928
44929 -extern atomic_t fscache_n_marks;
44930 -extern atomic_t fscache_n_uncaches;
44931 +extern atomic_unchecked_t fscache_n_marks;
44932 +extern atomic_unchecked_t fscache_n_uncaches;
44933
44934 -extern atomic_t fscache_n_acquires;
44935 -extern atomic_t fscache_n_acquires_null;
44936 -extern atomic_t fscache_n_acquires_no_cache;
44937 -extern atomic_t fscache_n_acquires_ok;
44938 -extern atomic_t fscache_n_acquires_nobufs;
44939 -extern atomic_t fscache_n_acquires_oom;
44940 +extern atomic_unchecked_t fscache_n_acquires;
44941 +extern atomic_unchecked_t fscache_n_acquires_null;
44942 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
44943 +extern atomic_unchecked_t fscache_n_acquires_ok;
44944 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
44945 +extern atomic_unchecked_t fscache_n_acquires_oom;
44946
44947 -extern atomic_t fscache_n_updates;
44948 -extern atomic_t fscache_n_updates_null;
44949 -extern atomic_t fscache_n_updates_run;
44950 +extern atomic_unchecked_t fscache_n_updates;
44951 +extern atomic_unchecked_t fscache_n_updates_null;
44952 +extern atomic_unchecked_t fscache_n_updates_run;
44953
44954 -extern atomic_t fscache_n_relinquishes;
44955 -extern atomic_t fscache_n_relinquishes_null;
44956 -extern atomic_t fscache_n_relinquishes_waitcrt;
44957 -extern atomic_t fscache_n_relinquishes_retire;
44958 +extern atomic_unchecked_t fscache_n_relinquishes;
44959 +extern atomic_unchecked_t fscache_n_relinquishes_null;
44960 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44961 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
44962
44963 -extern atomic_t fscache_n_cookie_index;
44964 -extern atomic_t fscache_n_cookie_data;
44965 -extern atomic_t fscache_n_cookie_special;
44966 +extern atomic_unchecked_t fscache_n_cookie_index;
44967 +extern atomic_unchecked_t fscache_n_cookie_data;
44968 +extern atomic_unchecked_t fscache_n_cookie_special;
44969
44970 -extern atomic_t fscache_n_object_alloc;
44971 -extern atomic_t fscache_n_object_no_alloc;
44972 -extern atomic_t fscache_n_object_lookups;
44973 -extern atomic_t fscache_n_object_lookups_negative;
44974 -extern atomic_t fscache_n_object_lookups_positive;
44975 -extern atomic_t fscache_n_object_lookups_timed_out;
44976 -extern atomic_t fscache_n_object_created;
44977 -extern atomic_t fscache_n_object_avail;
44978 -extern atomic_t fscache_n_object_dead;
44979 +extern atomic_unchecked_t fscache_n_object_alloc;
44980 +extern atomic_unchecked_t fscache_n_object_no_alloc;
44981 +extern atomic_unchecked_t fscache_n_object_lookups;
44982 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
44983 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
44984 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44985 +extern atomic_unchecked_t fscache_n_object_created;
44986 +extern atomic_unchecked_t fscache_n_object_avail;
44987 +extern atomic_unchecked_t fscache_n_object_dead;
44988
44989 -extern atomic_t fscache_n_checkaux_none;
44990 -extern atomic_t fscache_n_checkaux_okay;
44991 -extern atomic_t fscache_n_checkaux_update;
44992 -extern atomic_t fscache_n_checkaux_obsolete;
44993 +extern atomic_unchecked_t fscache_n_checkaux_none;
44994 +extern atomic_unchecked_t fscache_n_checkaux_okay;
44995 +extern atomic_unchecked_t fscache_n_checkaux_update;
44996 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
44997
44998 extern atomic_t fscache_n_cop_alloc_object;
44999 extern atomic_t fscache_n_cop_lookup_object;
45000 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45001 atomic_inc(stat);
45002 }
45003
45004 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45005 +{
45006 + atomic_inc_unchecked(stat);
45007 +}
45008 +
45009 static inline void fscache_stat_d(atomic_t *stat)
45010 {
45011 atomic_dec(stat);
45012 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45013
45014 #define __fscache_stat(stat) (NULL)
45015 #define fscache_stat(stat) do {} while (0)
45016 +#define fscache_stat_unchecked(stat) do {} while (0)
45017 #define fscache_stat_d(stat) do {} while (0)
45018 #endif
45019
45020 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45021 index b6b897c..0ffff9c 100644
45022 --- a/fs/fscache/object.c
45023 +++ b/fs/fscache/object.c
45024 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45025 /* update the object metadata on disk */
45026 case FSCACHE_OBJECT_UPDATING:
45027 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45028 - fscache_stat(&fscache_n_updates_run);
45029 + fscache_stat_unchecked(&fscache_n_updates_run);
45030 fscache_stat(&fscache_n_cop_update_object);
45031 object->cache->ops->update_object(object);
45032 fscache_stat_d(&fscache_n_cop_update_object);
45033 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45034 spin_lock(&object->lock);
45035 object->state = FSCACHE_OBJECT_DEAD;
45036 spin_unlock(&object->lock);
45037 - fscache_stat(&fscache_n_object_dead);
45038 + fscache_stat_unchecked(&fscache_n_object_dead);
45039 goto terminal_transit;
45040
45041 /* handle the parent cache of this object being withdrawn from
45042 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45043 spin_lock(&object->lock);
45044 object->state = FSCACHE_OBJECT_DEAD;
45045 spin_unlock(&object->lock);
45046 - fscache_stat(&fscache_n_object_dead);
45047 + fscache_stat_unchecked(&fscache_n_object_dead);
45048 goto terminal_transit;
45049
45050 /* complain about the object being woken up once it is
45051 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45052 parent->cookie->def->name, cookie->def->name,
45053 object->cache->tag->name);
45054
45055 - fscache_stat(&fscache_n_object_lookups);
45056 + fscache_stat_unchecked(&fscache_n_object_lookups);
45057 fscache_stat(&fscache_n_cop_lookup_object);
45058 ret = object->cache->ops->lookup_object(object);
45059 fscache_stat_d(&fscache_n_cop_lookup_object);
45060 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45061 if (ret == -ETIMEDOUT) {
45062 /* probably stuck behind another object, so move this one to
45063 * the back of the queue */
45064 - fscache_stat(&fscache_n_object_lookups_timed_out);
45065 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45066 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45067 }
45068
45069 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45070
45071 spin_lock(&object->lock);
45072 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45073 - fscache_stat(&fscache_n_object_lookups_negative);
45074 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45075
45076 /* transit here to allow write requests to begin stacking up
45077 * and read requests to begin returning ENODATA */
45078 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45079 * result, in which case there may be data available */
45080 spin_lock(&object->lock);
45081 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45082 - fscache_stat(&fscache_n_object_lookups_positive);
45083 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45084
45085 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45086
45087 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45088 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45089 } else {
45090 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45091 - fscache_stat(&fscache_n_object_created);
45092 + fscache_stat_unchecked(&fscache_n_object_created);
45093
45094 object->state = FSCACHE_OBJECT_AVAILABLE;
45095 spin_unlock(&object->lock);
45096 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45097 fscache_enqueue_dependents(object);
45098
45099 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45100 - fscache_stat(&fscache_n_object_avail);
45101 + fscache_stat_unchecked(&fscache_n_object_avail);
45102
45103 _leave("");
45104 }
45105 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45106 enum fscache_checkaux result;
45107
45108 if (!object->cookie->def->check_aux) {
45109 - fscache_stat(&fscache_n_checkaux_none);
45110 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45111 return FSCACHE_CHECKAUX_OKAY;
45112 }
45113
45114 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45115 switch (result) {
45116 /* entry okay as is */
45117 case FSCACHE_CHECKAUX_OKAY:
45118 - fscache_stat(&fscache_n_checkaux_okay);
45119 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45120 break;
45121
45122 /* entry requires update */
45123 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45124 - fscache_stat(&fscache_n_checkaux_update);
45125 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45126 break;
45127
45128 /* entry requires deletion */
45129 case FSCACHE_CHECKAUX_OBSOLETE:
45130 - fscache_stat(&fscache_n_checkaux_obsolete);
45131 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45132 break;
45133
45134 default:
45135 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45136 index 30afdfa..2256596 100644
45137 --- a/fs/fscache/operation.c
45138 +++ b/fs/fscache/operation.c
45139 @@ -17,7 +17,7 @@
45140 #include <linux/slab.h>
45141 #include "internal.h"
45142
45143 -atomic_t fscache_op_debug_id;
45144 +atomic_unchecked_t fscache_op_debug_id;
45145 EXPORT_SYMBOL(fscache_op_debug_id);
45146
45147 /**
45148 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45149 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45150 ASSERTCMP(atomic_read(&op->usage), >, 0);
45151
45152 - fscache_stat(&fscache_n_op_enqueue);
45153 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45154 switch (op->flags & FSCACHE_OP_TYPE) {
45155 case FSCACHE_OP_ASYNC:
45156 _debug("queue async");
45157 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45158 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45159 if (op->processor)
45160 fscache_enqueue_operation(op);
45161 - fscache_stat(&fscache_n_op_run);
45162 + fscache_stat_unchecked(&fscache_n_op_run);
45163 }
45164
45165 /*
45166 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45167 if (object->n_ops > 1) {
45168 atomic_inc(&op->usage);
45169 list_add_tail(&op->pend_link, &object->pending_ops);
45170 - fscache_stat(&fscache_n_op_pend);
45171 + fscache_stat_unchecked(&fscache_n_op_pend);
45172 } else if (!list_empty(&object->pending_ops)) {
45173 atomic_inc(&op->usage);
45174 list_add_tail(&op->pend_link, &object->pending_ops);
45175 - fscache_stat(&fscache_n_op_pend);
45176 + fscache_stat_unchecked(&fscache_n_op_pend);
45177 fscache_start_operations(object);
45178 } else {
45179 ASSERTCMP(object->n_in_progress, ==, 0);
45180 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45181 object->n_exclusive++; /* reads and writes must wait */
45182 atomic_inc(&op->usage);
45183 list_add_tail(&op->pend_link, &object->pending_ops);
45184 - fscache_stat(&fscache_n_op_pend);
45185 + fscache_stat_unchecked(&fscache_n_op_pend);
45186 ret = 0;
45187 } else {
45188 /* not allowed to submit ops in any other state */
45189 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45190 if (object->n_exclusive > 0) {
45191 atomic_inc(&op->usage);
45192 list_add_tail(&op->pend_link, &object->pending_ops);
45193 - fscache_stat(&fscache_n_op_pend);
45194 + fscache_stat_unchecked(&fscache_n_op_pend);
45195 } else if (!list_empty(&object->pending_ops)) {
45196 atomic_inc(&op->usage);
45197 list_add_tail(&op->pend_link, &object->pending_ops);
45198 - fscache_stat(&fscache_n_op_pend);
45199 + fscache_stat_unchecked(&fscache_n_op_pend);
45200 fscache_start_operations(object);
45201 } else {
45202 ASSERTCMP(object->n_exclusive, ==, 0);
45203 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45204 object->n_ops++;
45205 atomic_inc(&op->usage);
45206 list_add_tail(&op->pend_link, &object->pending_ops);
45207 - fscache_stat(&fscache_n_op_pend);
45208 + fscache_stat_unchecked(&fscache_n_op_pend);
45209 ret = 0;
45210 } else if (object->state == FSCACHE_OBJECT_DYING ||
45211 object->state == FSCACHE_OBJECT_LC_DYING ||
45212 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45213 - fscache_stat(&fscache_n_op_rejected);
45214 + fscache_stat_unchecked(&fscache_n_op_rejected);
45215 ret = -ENOBUFS;
45216 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45217 fscache_report_unexpected_submission(object, op, ostate);
45218 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45219
45220 ret = -EBUSY;
45221 if (!list_empty(&op->pend_link)) {
45222 - fscache_stat(&fscache_n_op_cancelled);
45223 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45224 list_del_init(&op->pend_link);
45225 object->n_ops--;
45226 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45227 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45228 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45229 BUG();
45230
45231 - fscache_stat(&fscache_n_op_release);
45232 + fscache_stat_unchecked(&fscache_n_op_release);
45233
45234 if (op->release) {
45235 op->release(op);
45236 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45237 * lock, and defer it otherwise */
45238 if (!spin_trylock(&object->lock)) {
45239 _debug("defer put");
45240 - fscache_stat(&fscache_n_op_deferred_release);
45241 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45242
45243 cache = object->cache;
45244 spin_lock(&cache->op_gc_list_lock);
45245 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45246
45247 _debug("GC DEFERRED REL OBJ%x OP%x",
45248 object->debug_id, op->debug_id);
45249 - fscache_stat(&fscache_n_op_gc);
45250 + fscache_stat_unchecked(&fscache_n_op_gc);
45251
45252 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45253
45254 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45255 index 3f7a59b..cf196cc 100644
45256 --- a/fs/fscache/page.c
45257 +++ b/fs/fscache/page.c
45258 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45259 val = radix_tree_lookup(&cookie->stores, page->index);
45260 if (!val) {
45261 rcu_read_unlock();
45262 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45263 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45264 __fscache_uncache_page(cookie, page);
45265 return true;
45266 }
45267 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45268 spin_unlock(&cookie->stores_lock);
45269
45270 if (xpage) {
45271 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45272 - fscache_stat(&fscache_n_store_radix_deletes);
45273 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45274 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45275 ASSERTCMP(xpage, ==, page);
45276 } else {
45277 - fscache_stat(&fscache_n_store_vmscan_gone);
45278 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45279 }
45280
45281 wake_up_bit(&cookie->flags, 0);
45282 @@ -107,7 +107,7 @@ page_busy:
45283 /* we might want to wait here, but that could deadlock the allocator as
45284 * the work threads writing to the cache may all end up sleeping
45285 * on memory allocation */
45286 - fscache_stat(&fscache_n_store_vmscan_busy);
45287 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45288 return false;
45289 }
45290 EXPORT_SYMBOL(__fscache_maybe_release_page);
45291 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45292 FSCACHE_COOKIE_STORING_TAG);
45293 if (!radix_tree_tag_get(&cookie->stores, page->index,
45294 FSCACHE_COOKIE_PENDING_TAG)) {
45295 - fscache_stat(&fscache_n_store_radix_deletes);
45296 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45297 xpage = radix_tree_delete(&cookie->stores, page->index);
45298 }
45299 spin_unlock(&cookie->stores_lock);
45300 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45301
45302 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45303
45304 - fscache_stat(&fscache_n_attr_changed_calls);
45305 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45306
45307 if (fscache_object_is_active(object)) {
45308 fscache_stat(&fscache_n_cop_attr_changed);
45309 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45310
45311 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45312
45313 - fscache_stat(&fscache_n_attr_changed);
45314 + fscache_stat_unchecked(&fscache_n_attr_changed);
45315
45316 op = kzalloc(sizeof(*op), GFP_KERNEL);
45317 if (!op) {
45318 - fscache_stat(&fscache_n_attr_changed_nomem);
45319 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45320 _leave(" = -ENOMEM");
45321 return -ENOMEM;
45322 }
45323 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45324 if (fscache_submit_exclusive_op(object, op) < 0)
45325 goto nobufs;
45326 spin_unlock(&cookie->lock);
45327 - fscache_stat(&fscache_n_attr_changed_ok);
45328 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45329 fscache_put_operation(op);
45330 _leave(" = 0");
45331 return 0;
45332 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45333 nobufs:
45334 spin_unlock(&cookie->lock);
45335 kfree(op);
45336 - fscache_stat(&fscache_n_attr_changed_nobufs);
45337 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45338 _leave(" = %d", -ENOBUFS);
45339 return -ENOBUFS;
45340 }
45341 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45342 /* allocate a retrieval operation and attempt to submit it */
45343 op = kzalloc(sizeof(*op), GFP_NOIO);
45344 if (!op) {
45345 - fscache_stat(&fscache_n_retrievals_nomem);
45346 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45347 return NULL;
45348 }
45349
45350 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45351 return 0;
45352 }
45353
45354 - fscache_stat(&fscache_n_retrievals_wait);
45355 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45356
45357 jif = jiffies;
45358 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45359 fscache_wait_bit_interruptible,
45360 TASK_INTERRUPTIBLE) != 0) {
45361 - fscache_stat(&fscache_n_retrievals_intr);
45362 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45363 _leave(" = -ERESTARTSYS");
45364 return -ERESTARTSYS;
45365 }
45366 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45367 */
45368 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45369 struct fscache_retrieval *op,
45370 - atomic_t *stat_op_waits,
45371 - atomic_t *stat_object_dead)
45372 + atomic_unchecked_t *stat_op_waits,
45373 + atomic_unchecked_t *stat_object_dead)
45374 {
45375 int ret;
45376
45377 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45378 goto check_if_dead;
45379
45380 _debug(">>> WT");
45381 - fscache_stat(stat_op_waits);
45382 + fscache_stat_unchecked(stat_op_waits);
45383 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45384 fscache_wait_bit_interruptible,
45385 TASK_INTERRUPTIBLE) < 0) {
45386 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45387
45388 check_if_dead:
45389 if (unlikely(fscache_object_is_dead(object))) {
45390 - fscache_stat(stat_object_dead);
45391 + fscache_stat_unchecked(stat_object_dead);
45392 return -ENOBUFS;
45393 }
45394 return 0;
45395 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45396
45397 _enter("%p,%p,,,", cookie, page);
45398
45399 - fscache_stat(&fscache_n_retrievals);
45400 + fscache_stat_unchecked(&fscache_n_retrievals);
45401
45402 if (hlist_empty(&cookie->backing_objects))
45403 goto nobufs;
45404 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45405 goto nobufs_unlock;
45406 spin_unlock(&cookie->lock);
45407
45408 - fscache_stat(&fscache_n_retrieval_ops);
45409 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45410
45411 /* pin the netfs read context in case we need to do the actual netfs
45412 * read because we've encountered a cache read failure */
45413 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45414
45415 error:
45416 if (ret == -ENOMEM)
45417 - fscache_stat(&fscache_n_retrievals_nomem);
45418 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45419 else if (ret == -ERESTARTSYS)
45420 - fscache_stat(&fscache_n_retrievals_intr);
45421 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45422 else if (ret == -ENODATA)
45423 - fscache_stat(&fscache_n_retrievals_nodata);
45424 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45425 else if (ret < 0)
45426 - fscache_stat(&fscache_n_retrievals_nobufs);
45427 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45428 else
45429 - fscache_stat(&fscache_n_retrievals_ok);
45430 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45431
45432 fscache_put_retrieval(op);
45433 _leave(" = %d", ret);
45434 @@ -429,7 +429,7 @@ nobufs_unlock:
45435 spin_unlock(&cookie->lock);
45436 kfree(op);
45437 nobufs:
45438 - fscache_stat(&fscache_n_retrievals_nobufs);
45439 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45440 _leave(" = -ENOBUFS");
45441 return -ENOBUFS;
45442 }
45443 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45444
45445 _enter("%p,,%d,,,", cookie, *nr_pages);
45446
45447 - fscache_stat(&fscache_n_retrievals);
45448 + fscache_stat_unchecked(&fscache_n_retrievals);
45449
45450 if (hlist_empty(&cookie->backing_objects))
45451 goto nobufs;
45452 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45453 goto nobufs_unlock;
45454 spin_unlock(&cookie->lock);
45455
45456 - fscache_stat(&fscache_n_retrieval_ops);
45457 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45458
45459 /* pin the netfs read context in case we need to do the actual netfs
45460 * read because we've encountered a cache read failure */
45461 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45462
45463 error:
45464 if (ret == -ENOMEM)
45465 - fscache_stat(&fscache_n_retrievals_nomem);
45466 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45467 else if (ret == -ERESTARTSYS)
45468 - fscache_stat(&fscache_n_retrievals_intr);
45469 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45470 else if (ret == -ENODATA)
45471 - fscache_stat(&fscache_n_retrievals_nodata);
45472 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45473 else if (ret < 0)
45474 - fscache_stat(&fscache_n_retrievals_nobufs);
45475 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45476 else
45477 - fscache_stat(&fscache_n_retrievals_ok);
45478 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45479
45480 fscache_put_retrieval(op);
45481 _leave(" = %d", ret);
45482 @@ -545,7 +545,7 @@ nobufs_unlock:
45483 spin_unlock(&cookie->lock);
45484 kfree(op);
45485 nobufs:
45486 - fscache_stat(&fscache_n_retrievals_nobufs);
45487 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45488 _leave(" = -ENOBUFS");
45489 return -ENOBUFS;
45490 }
45491 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45492
45493 _enter("%p,%p,,,", cookie, page);
45494
45495 - fscache_stat(&fscache_n_allocs);
45496 + fscache_stat_unchecked(&fscache_n_allocs);
45497
45498 if (hlist_empty(&cookie->backing_objects))
45499 goto nobufs;
45500 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45501 goto nobufs_unlock;
45502 spin_unlock(&cookie->lock);
45503
45504 - fscache_stat(&fscache_n_alloc_ops);
45505 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45506
45507 ret = fscache_wait_for_retrieval_activation(
45508 object, op,
45509 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45510
45511 error:
45512 if (ret == -ERESTARTSYS)
45513 - fscache_stat(&fscache_n_allocs_intr);
45514 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45515 else if (ret < 0)
45516 - fscache_stat(&fscache_n_allocs_nobufs);
45517 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45518 else
45519 - fscache_stat(&fscache_n_allocs_ok);
45520 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45521
45522 fscache_put_retrieval(op);
45523 _leave(" = %d", ret);
45524 @@ -625,7 +625,7 @@ nobufs_unlock:
45525 spin_unlock(&cookie->lock);
45526 kfree(op);
45527 nobufs:
45528 - fscache_stat(&fscache_n_allocs_nobufs);
45529 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45530 _leave(" = -ENOBUFS");
45531 return -ENOBUFS;
45532 }
45533 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45534
45535 spin_lock(&cookie->stores_lock);
45536
45537 - fscache_stat(&fscache_n_store_calls);
45538 + fscache_stat_unchecked(&fscache_n_store_calls);
45539
45540 /* find a page to store */
45541 page = NULL;
45542 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45543 page = results[0];
45544 _debug("gang %d [%lx]", n, page->index);
45545 if (page->index > op->store_limit) {
45546 - fscache_stat(&fscache_n_store_pages_over_limit);
45547 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45548 goto superseded;
45549 }
45550
45551 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45552 spin_unlock(&cookie->stores_lock);
45553 spin_unlock(&object->lock);
45554
45555 - fscache_stat(&fscache_n_store_pages);
45556 + fscache_stat_unchecked(&fscache_n_store_pages);
45557 fscache_stat(&fscache_n_cop_write_page);
45558 ret = object->cache->ops->write_page(op, page);
45559 fscache_stat_d(&fscache_n_cop_write_page);
45560 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45561 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45562 ASSERT(PageFsCache(page));
45563
45564 - fscache_stat(&fscache_n_stores);
45565 + fscache_stat_unchecked(&fscache_n_stores);
45566
45567 op = kzalloc(sizeof(*op), GFP_NOIO);
45568 if (!op)
45569 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45570 spin_unlock(&cookie->stores_lock);
45571 spin_unlock(&object->lock);
45572
45573 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45574 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45575 op->store_limit = object->store_limit;
45576
45577 if (fscache_submit_op(object, &op->op) < 0)
45578 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45579
45580 spin_unlock(&cookie->lock);
45581 radix_tree_preload_end();
45582 - fscache_stat(&fscache_n_store_ops);
45583 - fscache_stat(&fscache_n_stores_ok);
45584 + fscache_stat_unchecked(&fscache_n_store_ops);
45585 + fscache_stat_unchecked(&fscache_n_stores_ok);
45586
45587 /* the work queue now carries its own ref on the object */
45588 fscache_put_operation(&op->op);
45589 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45590 return 0;
45591
45592 already_queued:
45593 - fscache_stat(&fscache_n_stores_again);
45594 + fscache_stat_unchecked(&fscache_n_stores_again);
45595 already_pending:
45596 spin_unlock(&cookie->stores_lock);
45597 spin_unlock(&object->lock);
45598 spin_unlock(&cookie->lock);
45599 radix_tree_preload_end();
45600 kfree(op);
45601 - fscache_stat(&fscache_n_stores_ok);
45602 + fscache_stat_unchecked(&fscache_n_stores_ok);
45603 _leave(" = 0");
45604 return 0;
45605
45606 @@ -851,14 +851,14 @@ nobufs:
45607 spin_unlock(&cookie->lock);
45608 radix_tree_preload_end();
45609 kfree(op);
45610 - fscache_stat(&fscache_n_stores_nobufs);
45611 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
45612 _leave(" = -ENOBUFS");
45613 return -ENOBUFS;
45614
45615 nomem_free:
45616 kfree(op);
45617 nomem:
45618 - fscache_stat(&fscache_n_stores_oom);
45619 + fscache_stat_unchecked(&fscache_n_stores_oom);
45620 _leave(" = -ENOMEM");
45621 return -ENOMEM;
45622 }
45623 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45624 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45625 ASSERTCMP(page, !=, NULL);
45626
45627 - fscache_stat(&fscache_n_uncaches);
45628 + fscache_stat_unchecked(&fscache_n_uncaches);
45629
45630 /* cache withdrawal may beat us to it */
45631 if (!PageFsCache(page))
45632 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45633 unsigned long loop;
45634
45635 #ifdef CONFIG_FSCACHE_STATS
45636 - atomic_add(pagevec->nr, &fscache_n_marks);
45637 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45638 #endif
45639
45640 for (loop = 0; loop < pagevec->nr; loop++) {
45641 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45642 index 4765190..2a067f2 100644
45643 --- a/fs/fscache/stats.c
45644 +++ b/fs/fscache/stats.c
45645 @@ -18,95 +18,95 @@
45646 /*
45647 * operation counters
45648 */
45649 -atomic_t fscache_n_op_pend;
45650 -atomic_t fscache_n_op_run;
45651 -atomic_t fscache_n_op_enqueue;
45652 -atomic_t fscache_n_op_requeue;
45653 -atomic_t fscache_n_op_deferred_release;
45654 -atomic_t fscache_n_op_release;
45655 -atomic_t fscache_n_op_gc;
45656 -atomic_t fscache_n_op_cancelled;
45657 -atomic_t fscache_n_op_rejected;
45658 +atomic_unchecked_t fscache_n_op_pend;
45659 +atomic_unchecked_t fscache_n_op_run;
45660 +atomic_unchecked_t fscache_n_op_enqueue;
45661 +atomic_unchecked_t fscache_n_op_requeue;
45662 +atomic_unchecked_t fscache_n_op_deferred_release;
45663 +atomic_unchecked_t fscache_n_op_release;
45664 +atomic_unchecked_t fscache_n_op_gc;
45665 +atomic_unchecked_t fscache_n_op_cancelled;
45666 +atomic_unchecked_t fscache_n_op_rejected;
45667
45668 -atomic_t fscache_n_attr_changed;
45669 -atomic_t fscache_n_attr_changed_ok;
45670 -atomic_t fscache_n_attr_changed_nobufs;
45671 -atomic_t fscache_n_attr_changed_nomem;
45672 -atomic_t fscache_n_attr_changed_calls;
45673 +atomic_unchecked_t fscache_n_attr_changed;
45674 +atomic_unchecked_t fscache_n_attr_changed_ok;
45675 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45676 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45677 +atomic_unchecked_t fscache_n_attr_changed_calls;
45678
45679 -atomic_t fscache_n_allocs;
45680 -atomic_t fscache_n_allocs_ok;
45681 -atomic_t fscache_n_allocs_wait;
45682 -atomic_t fscache_n_allocs_nobufs;
45683 -atomic_t fscache_n_allocs_intr;
45684 -atomic_t fscache_n_allocs_object_dead;
45685 -atomic_t fscache_n_alloc_ops;
45686 -atomic_t fscache_n_alloc_op_waits;
45687 +atomic_unchecked_t fscache_n_allocs;
45688 +atomic_unchecked_t fscache_n_allocs_ok;
45689 +atomic_unchecked_t fscache_n_allocs_wait;
45690 +atomic_unchecked_t fscache_n_allocs_nobufs;
45691 +atomic_unchecked_t fscache_n_allocs_intr;
45692 +atomic_unchecked_t fscache_n_allocs_object_dead;
45693 +atomic_unchecked_t fscache_n_alloc_ops;
45694 +atomic_unchecked_t fscache_n_alloc_op_waits;
45695
45696 -atomic_t fscache_n_retrievals;
45697 -atomic_t fscache_n_retrievals_ok;
45698 -atomic_t fscache_n_retrievals_wait;
45699 -atomic_t fscache_n_retrievals_nodata;
45700 -atomic_t fscache_n_retrievals_nobufs;
45701 -atomic_t fscache_n_retrievals_intr;
45702 -atomic_t fscache_n_retrievals_nomem;
45703 -atomic_t fscache_n_retrievals_object_dead;
45704 -atomic_t fscache_n_retrieval_ops;
45705 -atomic_t fscache_n_retrieval_op_waits;
45706 +atomic_unchecked_t fscache_n_retrievals;
45707 +atomic_unchecked_t fscache_n_retrievals_ok;
45708 +atomic_unchecked_t fscache_n_retrievals_wait;
45709 +atomic_unchecked_t fscache_n_retrievals_nodata;
45710 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45711 +atomic_unchecked_t fscache_n_retrievals_intr;
45712 +atomic_unchecked_t fscache_n_retrievals_nomem;
45713 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45714 +atomic_unchecked_t fscache_n_retrieval_ops;
45715 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45716
45717 -atomic_t fscache_n_stores;
45718 -atomic_t fscache_n_stores_ok;
45719 -atomic_t fscache_n_stores_again;
45720 -atomic_t fscache_n_stores_nobufs;
45721 -atomic_t fscache_n_stores_oom;
45722 -atomic_t fscache_n_store_ops;
45723 -atomic_t fscache_n_store_calls;
45724 -atomic_t fscache_n_store_pages;
45725 -atomic_t fscache_n_store_radix_deletes;
45726 -atomic_t fscache_n_store_pages_over_limit;
45727 +atomic_unchecked_t fscache_n_stores;
45728 +atomic_unchecked_t fscache_n_stores_ok;
45729 +atomic_unchecked_t fscache_n_stores_again;
45730 +atomic_unchecked_t fscache_n_stores_nobufs;
45731 +atomic_unchecked_t fscache_n_stores_oom;
45732 +atomic_unchecked_t fscache_n_store_ops;
45733 +atomic_unchecked_t fscache_n_store_calls;
45734 +atomic_unchecked_t fscache_n_store_pages;
45735 +atomic_unchecked_t fscache_n_store_radix_deletes;
45736 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45737
45738 -atomic_t fscache_n_store_vmscan_not_storing;
45739 -atomic_t fscache_n_store_vmscan_gone;
45740 -atomic_t fscache_n_store_vmscan_busy;
45741 -atomic_t fscache_n_store_vmscan_cancelled;
45742 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45743 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45744 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45745 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45746
45747 -atomic_t fscache_n_marks;
45748 -atomic_t fscache_n_uncaches;
45749 +atomic_unchecked_t fscache_n_marks;
45750 +atomic_unchecked_t fscache_n_uncaches;
45751
45752 -atomic_t fscache_n_acquires;
45753 -atomic_t fscache_n_acquires_null;
45754 -atomic_t fscache_n_acquires_no_cache;
45755 -atomic_t fscache_n_acquires_ok;
45756 -atomic_t fscache_n_acquires_nobufs;
45757 -atomic_t fscache_n_acquires_oom;
45758 +atomic_unchecked_t fscache_n_acquires;
45759 +atomic_unchecked_t fscache_n_acquires_null;
45760 +atomic_unchecked_t fscache_n_acquires_no_cache;
45761 +atomic_unchecked_t fscache_n_acquires_ok;
45762 +atomic_unchecked_t fscache_n_acquires_nobufs;
45763 +atomic_unchecked_t fscache_n_acquires_oom;
45764
45765 -atomic_t fscache_n_updates;
45766 -atomic_t fscache_n_updates_null;
45767 -atomic_t fscache_n_updates_run;
45768 +atomic_unchecked_t fscache_n_updates;
45769 +atomic_unchecked_t fscache_n_updates_null;
45770 +atomic_unchecked_t fscache_n_updates_run;
45771
45772 -atomic_t fscache_n_relinquishes;
45773 -atomic_t fscache_n_relinquishes_null;
45774 -atomic_t fscache_n_relinquishes_waitcrt;
45775 -atomic_t fscache_n_relinquishes_retire;
45776 +atomic_unchecked_t fscache_n_relinquishes;
45777 +atomic_unchecked_t fscache_n_relinquishes_null;
45778 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45779 +atomic_unchecked_t fscache_n_relinquishes_retire;
45780
45781 -atomic_t fscache_n_cookie_index;
45782 -atomic_t fscache_n_cookie_data;
45783 -atomic_t fscache_n_cookie_special;
45784 +atomic_unchecked_t fscache_n_cookie_index;
45785 +atomic_unchecked_t fscache_n_cookie_data;
45786 +atomic_unchecked_t fscache_n_cookie_special;
45787
45788 -atomic_t fscache_n_object_alloc;
45789 -atomic_t fscache_n_object_no_alloc;
45790 -atomic_t fscache_n_object_lookups;
45791 -atomic_t fscache_n_object_lookups_negative;
45792 -atomic_t fscache_n_object_lookups_positive;
45793 -atomic_t fscache_n_object_lookups_timed_out;
45794 -atomic_t fscache_n_object_created;
45795 -atomic_t fscache_n_object_avail;
45796 -atomic_t fscache_n_object_dead;
45797 +atomic_unchecked_t fscache_n_object_alloc;
45798 +atomic_unchecked_t fscache_n_object_no_alloc;
45799 +atomic_unchecked_t fscache_n_object_lookups;
45800 +atomic_unchecked_t fscache_n_object_lookups_negative;
45801 +atomic_unchecked_t fscache_n_object_lookups_positive;
45802 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
45803 +atomic_unchecked_t fscache_n_object_created;
45804 +atomic_unchecked_t fscache_n_object_avail;
45805 +atomic_unchecked_t fscache_n_object_dead;
45806
45807 -atomic_t fscache_n_checkaux_none;
45808 -atomic_t fscache_n_checkaux_okay;
45809 -atomic_t fscache_n_checkaux_update;
45810 -atomic_t fscache_n_checkaux_obsolete;
45811 +atomic_unchecked_t fscache_n_checkaux_none;
45812 +atomic_unchecked_t fscache_n_checkaux_okay;
45813 +atomic_unchecked_t fscache_n_checkaux_update;
45814 +atomic_unchecked_t fscache_n_checkaux_obsolete;
45815
45816 atomic_t fscache_n_cop_alloc_object;
45817 atomic_t fscache_n_cop_lookup_object;
45818 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45819 seq_puts(m, "FS-Cache statistics\n");
45820
45821 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45822 - atomic_read(&fscache_n_cookie_index),
45823 - atomic_read(&fscache_n_cookie_data),
45824 - atomic_read(&fscache_n_cookie_special));
45825 + atomic_read_unchecked(&fscache_n_cookie_index),
45826 + atomic_read_unchecked(&fscache_n_cookie_data),
45827 + atomic_read_unchecked(&fscache_n_cookie_special));
45828
45829 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45830 - atomic_read(&fscache_n_object_alloc),
45831 - atomic_read(&fscache_n_object_no_alloc),
45832 - atomic_read(&fscache_n_object_avail),
45833 - atomic_read(&fscache_n_object_dead));
45834 + atomic_read_unchecked(&fscache_n_object_alloc),
45835 + atomic_read_unchecked(&fscache_n_object_no_alloc),
45836 + atomic_read_unchecked(&fscache_n_object_avail),
45837 + atomic_read_unchecked(&fscache_n_object_dead));
45838 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45839 - atomic_read(&fscache_n_checkaux_none),
45840 - atomic_read(&fscache_n_checkaux_okay),
45841 - atomic_read(&fscache_n_checkaux_update),
45842 - atomic_read(&fscache_n_checkaux_obsolete));
45843 + atomic_read_unchecked(&fscache_n_checkaux_none),
45844 + atomic_read_unchecked(&fscache_n_checkaux_okay),
45845 + atomic_read_unchecked(&fscache_n_checkaux_update),
45846 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45847
45848 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45849 - atomic_read(&fscache_n_marks),
45850 - atomic_read(&fscache_n_uncaches));
45851 + atomic_read_unchecked(&fscache_n_marks),
45852 + atomic_read_unchecked(&fscache_n_uncaches));
45853
45854 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45855 " oom=%u\n",
45856 - atomic_read(&fscache_n_acquires),
45857 - atomic_read(&fscache_n_acquires_null),
45858 - atomic_read(&fscache_n_acquires_no_cache),
45859 - atomic_read(&fscache_n_acquires_ok),
45860 - atomic_read(&fscache_n_acquires_nobufs),
45861 - atomic_read(&fscache_n_acquires_oom));
45862 + atomic_read_unchecked(&fscache_n_acquires),
45863 + atomic_read_unchecked(&fscache_n_acquires_null),
45864 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
45865 + atomic_read_unchecked(&fscache_n_acquires_ok),
45866 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
45867 + atomic_read_unchecked(&fscache_n_acquires_oom));
45868
45869 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45870 - atomic_read(&fscache_n_object_lookups),
45871 - atomic_read(&fscache_n_object_lookups_negative),
45872 - atomic_read(&fscache_n_object_lookups_positive),
45873 - atomic_read(&fscache_n_object_created),
45874 - atomic_read(&fscache_n_object_lookups_timed_out));
45875 + atomic_read_unchecked(&fscache_n_object_lookups),
45876 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
45877 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
45878 + atomic_read_unchecked(&fscache_n_object_created),
45879 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45880
45881 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45882 - atomic_read(&fscache_n_updates),
45883 - atomic_read(&fscache_n_updates_null),
45884 - atomic_read(&fscache_n_updates_run));
45885 + atomic_read_unchecked(&fscache_n_updates),
45886 + atomic_read_unchecked(&fscache_n_updates_null),
45887 + atomic_read_unchecked(&fscache_n_updates_run));
45888
45889 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45890 - atomic_read(&fscache_n_relinquishes),
45891 - atomic_read(&fscache_n_relinquishes_null),
45892 - atomic_read(&fscache_n_relinquishes_waitcrt),
45893 - atomic_read(&fscache_n_relinquishes_retire));
45894 + atomic_read_unchecked(&fscache_n_relinquishes),
45895 + atomic_read_unchecked(&fscache_n_relinquishes_null),
45896 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45897 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
45898
45899 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45900 - atomic_read(&fscache_n_attr_changed),
45901 - atomic_read(&fscache_n_attr_changed_ok),
45902 - atomic_read(&fscache_n_attr_changed_nobufs),
45903 - atomic_read(&fscache_n_attr_changed_nomem),
45904 - atomic_read(&fscache_n_attr_changed_calls));
45905 + atomic_read_unchecked(&fscache_n_attr_changed),
45906 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
45907 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45908 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45909 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
45910
45911 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45912 - atomic_read(&fscache_n_allocs),
45913 - atomic_read(&fscache_n_allocs_ok),
45914 - atomic_read(&fscache_n_allocs_wait),
45915 - atomic_read(&fscache_n_allocs_nobufs),
45916 - atomic_read(&fscache_n_allocs_intr));
45917 + atomic_read_unchecked(&fscache_n_allocs),
45918 + atomic_read_unchecked(&fscache_n_allocs_ok),
45919 + atomic_read_unchecked(&fscache_n_allocs_wait),
45920 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
45921 + atomic_read_unchecked(&fscache_n_allocs_intr));
45922 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45923 - atomic_read(&fscache_n_alloc_ops),
45924 - atomic_read(&fscache_n_alloc_op_waits),
45925 - atomic_read(&fscache_n_allocs_object_dead));
45926 + atomic_read_unchecked(&fscache_n_alloc_ops),
45927 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
45928 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
45929
45930 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45931 " int=%u oom=%u\n",
45932 - atomic_read(&fscache_n_retrievals),
45933 - atomic_read(&fscache_n_retrievals_ok),
45934 - atomic_read(&fscache_n_retrievals_wait),
45935 - atomic_read(&fscache_n_retrievals_nodata),
45936 - atomic_read(&fscache_n_retrievals_nobufs),
45937 - atomic_read(&fscache_n_retrievals_intr),
45938 - atomic_read(&fscache_n_retrievals_nomem));
45939 + atomic_read_unchecked(&fscache_n_retrievals),
45940 + atomic_read_unchecked(&fscache_n_retrievals_ok),
45941 + atomic_read_unchecked(&fscache_n_retrievals_wait),
45942 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
45943 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45944 + atomic_read_unchecked(&fscache_n_retrievals_intr),
45945 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
45946 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45947 - atomic_read(&fscache_n_retrieval_ops),
45948 - atomic_read(&fscache_n_retrieval_op_waits),
45949 - atomic_read(&fscache_n_retrievals_object_dead));
45950 + atomic_read_unchecked(&fscache_n_retrieval_ops),
45951 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45952 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45953
45954 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45955 - atomic_read(&fscache_n_stores),
45956 - atomic_read(&fscache_n_stores_ok),
45957 - atomic_read(&fscache_n_stores_again),
45958 - atomic_read(&fscache_n_stores_nobufs),
45959 - atomic_read(&fscache_n_stores_oom));
45960 + atomic_read_unchecked(&fscache_n_stores),
45961 + atomic_read_unchecked(&fscache_n_stores_ok),
45962 + atomic_read_unchecked(&fscache_n_stores_again),
45963 + atomic_read_unchecked(&fscache_n_stores_nobufs),
45964 + atomic_read_unchecked(&fscache_n_stores_oom));
45965 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45966 - atomic_read(&fscache_n_store_ops),
45967 - atomic_read(&fscache_n_store_calls),
45968 - atomic_read(&fscache_n_store_pages),
45969 - atomic_read(&fscache_n_store_radix_deletes),
45970 - atomic_read(&fscache_n_store_pages_over_limit));
45971 + atomic_read_unchecked(&fscache_n_store_ops),
45972 + atomic_read_unchecked(&fscache_n_store_calls),
45973 + atomic_read_unchecked(&fscache_n_store_pages),
45974 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
45975 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45976
45977 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45978 - atomic_read(&fscache_n_store_vmscan_not_storing),
45979 - atomic_read(&fscache_n_store_vmscan_gone),
45980 - atomic_read(&fscache_n_store_vmscan_busy),
45981 - atomic_read(&fscache_n_store_vmscan_cancelled));
45982 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45983 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45984 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45985 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45986
45987 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45988 - atomic_read(&fscache_n_op_pend),
45989 - atomic_read(&fscache_n_op_run),
45990 - atomic_read(&fscache_n_op_enqueue),
45991 - atomic_read(&fscache_n_op_cancelled),
45992 - atomic_read(&fscache_n_op_rejected));
45993 + atomic_read_unchecked(&fscache_n_op_pend),
45994 + atomic_read_unchecked(&fscache_n_op_run),
45995 + atomic_read_unchecked(&fscache_n_op_enqueue),
45996 + atomic_read_unchecked(&fscache_n_op_cancelled),
45997 + atomic_read_unchecked(&fscache_n_op_rejected));
45998 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
45999 - atomic_read(&fscache_n_op_deferred_release),
46000 - atomic_read(&fscache_n_op_release),
46001 - atomic_read(&fscache_n_op_gc));
46002 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46003 + atomic_read_unchecked(&fscache_n_op_release),
46004 + atomic_read_unchecked(&fscache_n_op_gc));
46005
46006 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46007 atomic_read(&fscache_n_cop_alloc_object),
46008 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46009 index 3426521..3b75162 100644
46010 --- a/fs/fuse/cuse.c
46011 +++ b/fs/fuse/cuse.c
46012 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46013 INIT_LIST_HEAD(&cuse_conntbl[i]);
46014
46015 /* inherit and extend fuse_dev_operations */
46016 - cuse_channel_fops = fuse_dev_operations;
46017 - cuse_channel_fops.owner = THIS_MODULE;
46018 - cuse_channel_fops.open = cuse_channel_open;
46019 - cuse_channel_fops.release = cuse_channel_release;
46020 + pax_open_kernel();
46021 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46022 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46023 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46024 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46025 + pax_close_kernel();
46026
46027 cuse_class = class_create(THIS_MODULE, "cuse");
46028 if (IS_ERR(cuse_class))
46029 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46030 index 7df2b5e..5804aa7 100644
46031 --- a/fs/fuse/dev.c
46032 +++ b/fs/fuse/dev.c
46033 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46034 ret = 0;
46035 pipe_lock(pipe);
46036
46037 - if (!pipe->readers) {
46038 + if (!atomic_read(&pipe->readers)) {
46039 send_sig(SIGPIPE, current, 0);
46040 if (!ret)
46041 ret = -EPIPE;
46042 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46043 index bc43832..0cfe5a6 100644
46044 --- a/fs/fuse/dir.c
46045 +++ b/fs/fuse/dir.c
46046 @@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46047 return link;
46048 }
46049
46050 -static void free_link(char *link)
46051 +static void free_link(const char *link)
46052 {
46053 if (!IS_ERR(link))
46054 free_page((unsigned long) link);
46055 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46056 index a9ba244..d9df391 100644
46057 --- a/fs/gfs2/inode.c
46058 +++ b/fs/gfs2/inode.c
46059 @@ -1496,7 +1496,7 @@ out:
46060
46061 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46062 {
46063 - char *s = nd_get_link(nd);
46064 + const char *s = nd_get_link(nd);
46065 if (!IS_ERR(s))
46066 kfree(s);
46067 }
46068 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46069 index 001ef01..f7d5f07 100644
46070 --- a/fs/hugetlbfs/inode.c
46071 +++ b/fs/hugetlbfs/inode.c
46072 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46073 .kill_sb = kill_litter_super,
46074 };
46075
46076 -static struct vfsmount *hugetlbfs_vfsmount;
46077 +struct vfsmount *hugetlbfs_vfsmount;
46078
46079 static int can_do_hugetlb_shm(void)
46080 {
46081 diff --git a/fs/inode.c b/fs/inode.c
46082 index 9f4f5fe..6214688 100644
46083 --- a/fs/inode.c
46084 +++ b/fs/inode.c
46085 @@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46086
46087 #ifdef CONFIG_SMP
46088 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46089 - static atomic_t shared_last_ino;
46090 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46091 + static atomic_unchecked_t shared_last_ino;
46092 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46093
46094 res = next - LAST_INO_BATCH;
46095 }
46096 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46097 index 4a6cf28..d3a29d3 100644
46098 --- a/fs/jffs2/erase.c
46099 +++ b/fs/jffs2/erase.c
46100 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46101 struct jffs2_unknown_node marker = {
46102 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46103 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46104 - .totlen = cpu_to_je32(c->cleanmarker_size)
46105 + .totlen = cpu_to_je32(c->cleanmarker_size),
46106 + .hdr_crc = cpu_to_je32(0)
46107 };
46108
46109 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46110 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46111 index 74d9be1..d5dd140 100644
46112 --- a/fs/jffs2/wbuf.c
46113 +++ b/fs/jffs2/wbuf.c
46114 @@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46115 {
46116 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46117 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46118 - .totlen = constant_cpu_to_je32(8)
46119 + .totlen = constant_cpu_to_je32(8),
46120 + .hdr_crc = constant_cpu_to_je32(0)
46121 };
46122
46123 /*
46124 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46125 index 4a82950..bcaa0cb 100644
46126 --- a/fs/jfs/super.c
46127 +++ b/fs/jfs/super.c
46128 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46129
46130 jfs_inode_cachep =
46131 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46132 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46133 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46134 init_once);
46135 if (jfs_inode_cachep == NULL)
46136 return -ENOMEM;
46137 diff --git a/fs/libfs.c b/fs/libfs.c
46138 index 18d08f5..fe3dc64 100644
46139 --- a/fs/libfs.c
46140 +++ b/fs/libfs.c
46141 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46142
46143 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46144 struct dentry *next;
46145 + char d_name[sizeof(next->d_iname)];
46146 + const unsigned char *name;
46147 +
46148 next = list_entry(p, struct dentry, d_u.d_child);
46149 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46150 if (!simple_positive(next)) {
46151 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46152
46153 spin_unlock(&next->d_lock);
46154 spin_unlock(&dentry->d_lock);
46155 - if (filldir(dirent, next->d_name.name,
46156 + name = next->d_name.name;
46157 + if (name == next->d_iname) {
46158 + memcpy(d_name, name, next->d_name.len);
46159 + name = d_name;
46160 + }
46161 + if (filldir(dirent, name,
46162 next->d_name.len, filp->f_pos,
46163 next->d_inode->i_ino,
46164 dt_type(next->d_inode)) < 0)
46165 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46166 index 8392cb8..80d6193 100644
46167 --- a/fs/lockd/clntproc.c
46168 +++ b/fs/lockd/clntproc.c
46169 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46170 /*
46171 * Cookie counter for NLM requests
46172 */
46173 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46174 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46175
46176 void nlmclnt_next_cookie(struct nlm_cookie *c)
46177 {
46178 - u32 cookie = atomic_inc_return(&nlm_cookie);
46179 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46180
46181 memcpy(c->data, &cookie, 4);
46182 c->len=4;
46183 diff --git a/fs/locks.c b/fs/locks.c
46184 index 0d68f1f..3114738 100644
46185 --- a/fs/locks.c
46186 +++ b/fs/locks.c
46187 @@ -1465,7 +1465,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
46188 case F_WRLCK:
46189 return generic_add_lease(filp, arg, flp);
46190 default:
46191 - BUG();
46192 + return -EINVAL;
46193 }
46194 }
46195 EXPORT_SYMBOL(generic_setlease);
46196 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46197 return;
46198
46199 if (filp->f_op && filp->f_op->flock) {
46200 - struct file_lock fl = {
46201 + struct file_lock flock = {
46202 .fl_pid = current->tgid,
46203 .fl_file = filp,
46204 .fl_flags = FL_FLOCK,
46205 .fl_type = F_UNLCK,
46206 .fl_end = OFFSET_MAX,
46207 };
46208 - filp->f_op->flock(filp, F_SETLKW, &fl);
46209 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46210 - fl.fl_ops->fl_release_private(&fl);
46211 + filp->f_op->flock(filp, F_SETLKW, &flock);
46212 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46213 + flock.fl_ops->fl_release_private(&flock);
46214 }
46215
46216 lock_flocks();
46217 diff --git a/fs/namei.c b/fs/namei.c
46218 index c427919..232326c 100644
46219 --- a/fs/namei.c
46220 +++ b/fs/namei.c
46221 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46222 if (ret != -EACCES)
46223 return ret;
46224
46225 +#ifdef CONFIG_GRKERNSEC
46226 + /* we'll block if we have to log due to a denied capability use */
46227 + if (mask & MAY_NOT_BLOCK)
46228 + return -ECHILD;
46229 +#endif
46230 +
46231 if (S_ISDIR(inode->i_mode)) {
46232 /* DACs are overridable for directories */
46233 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46234 - return 0;
46235 if (!(mask & MAY_WRITE))
46236 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46237 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46238 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46239 return 0;
46240 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46241 + return 0;
46242 return -EACCES;
46243 }
46244 /*
46245 + * Searching includes executable on directories, else just read.
46246 + */
46247 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46248 + if (mask == MAY_READ)
46249 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46250 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46251 + return 0;
46252 +
46253 + /*
46254 * Read/write DACs are always overridable.
46255 * Executable DACs are overridable when there is
46256 * at least one exec bit set.
46257 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46258 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46259 return 0;
46260
46261 - /*
46262 - * Searching includes executable on directories, else just read.
46263 - */
46264 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46265 - if (mask == MAY_READ)
46266 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46267 - return 0;
46268 -
46269 return -EACCES;
46270 }
46271
46272 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46273 return error;
46274 }
46275
46276 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46277 + dentry->d_inode, dentry, nd->path.mnt)) {
46278 + error = -EACCES;
46279 + *p = ERR_PTR(error); /* no ->put_link(), please */
46280 + path_put(&nd->path);
46281 + return error;
46282 + }
46283 +
46284 nd->last_type = LAST_BIND;
46285 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46286 error = PTR_ERR(*p);
46287 if (!IS_ERR(*p)) {
46288 - char *s = nd_get_link(nd);
46289 + const char *s = nd_get_link(nd);
46290 error = 0;
46291 if (s)
46292 error = __vfs_follow_link(nd, s);
46293 @@ -1355,6 +1371,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
46294 if (!res)
46295 res = walk_component(nd, path, &nd->last,
46296 nd->last_type, LOOKUP_FOLLOW);
46297 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
46298 + res = -EACCES;
46299 + }
46300 put_link(nd, &link, cookie);
46301 } while (res > 0);
46302
46303 @@ -1746,6 +1765,9 @@ static int path_lookupat(int dfd, const char *name,
46304 err = follow_link(&link, nd, &cookie);
46305 if (!err)
46306 err = lookup_last(nd, &path);
46307 + if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
46308 + err = -EACCES;
46309 + }
46310 put_link(nd, &link, cookie);
46311 }
46312 }
46313 @@ -1753,6 +1775,21 @@ static int path_lookupat(int dfd, const char *name,
46314 if (!err)
46315 err = complete_walk(nd);
46316
46317 + if (!(nd->flags & LOOKUP_PARENT)) {
46318 +#ifdef CONFIG_GRKERNSEC
46319 + if (flags & LOOKUP_RCU) {
46320 + if (!err)
46321 + path_put(&nd->path);
46322 + err = -ECHILD;
46323 + } else
46324 +#endif
46325 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46326 + if (!err)
46327 + path_put(&nd->path);
46328 + err = -ENOENT;
46329 + }
46330 + }
46331 +
46332 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46333 if (!nd->inode->i_op->lookup) {
46334 path_put(&nd->path);
46335 @@ -1780,6 +1817,15 @@ static int do_path_lookup(int dfd, const char *name,
46336 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46337
46338 if (likely(!retval)) {
46339 + if (*name != '/' && nd->path.dentry && nd->inode) {
46340 +#ifdef CONFIG_GRKERNSEC
46341 + if (flags & LOOKUP_RCU)
46342 + return -ECHILD;
46343 +#endif
46344 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46345 + return -ENOENT;
46346 + }
46347 +
46348 if (unlikely(!audit_dummy_context())) {
46349 if (nd->path.dentry && nd->inode)
46350 audit_inode(name, nd->path.dentry);
46351 @@ -2126,6 +2172,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46352 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46353 return -EPERM;
46354
46355 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46356 + return -EPERM;
46357 + if (gr_handle_rawio(inode))
46358 + return -EPERM;
46359 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46360 + return -EACCES;
46361 +
46362 return 0;
46363 }
46364
46365 @@ -2187,6 +2240,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46366 error = complete_walk(nd);
46367 if (error)
46368 return ERR_PTR(error);
46369 +#ifdef CONFIG_GRKERNSEC
46370 + if (nd->flags & LOOKUP_RCU) {
46371 + error = -ECHILD;
46372 + goto exit;
46373 + }
46374 +#endif
46375 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46376 + error = -ENOENT;
46377 + goto exit;
46378 + }
46379 audit_inode(pathname, nd->path.dentry);
46380 if (open_flag & O_CREAT) {
46381 error = -EISDIR;
46382 @@ -2197,6 +2260,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46383 error = complete_walk(nd);
46384 if (error)
46385 return ERR_PTR(error);
46386 +#ifdef CONFIG_GRKERNSEC
46387 + if (nd->flags & LOOKUP_RCU) {
46388 + error = -ECHILD;
46389 + goto exit;
46390 + }
46391 +#endif
46392 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46393 + error = -ENOENT;
46394 + goto exit;
46395 + }
46396 audit_inode(pathname, dir);
46397 goto ok;
46398 }
46399 @@ -2218,6 +2291,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46400 error = complete_walk(nd);
46401 if (error)
46402 return ERR_PTR(error);
46403 +#ifdef CONFIG_GRKERNSEC
46404 + if (nd->flags & LOOKUP_RCU) {
46405 + error = -ECHILD;
46406 + goto exit;
46407 + }
46408 +#endif
46409 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46410 + error = -ENOENT;
46411 + goto exit;
46412 + }
46413
46414 error = -ENOTDIR;
46415 if (nd->flags & LOOKUP_DIRECTORY) {
46416 @@ -2258,6 +2341,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46417 /* Negative dentry, just create the file */
46418 if (!dentry->d_inode) {
46419 umode_t mode = op->mode;
46420 +
46421 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46422 + error = -EACCES;
46423 + goto exit_mutex_unlock;
46424 + }
46425 +
46426 if (!IS_POSIXACL(dir->d_inode))
46427 mode &= ~current_umask();
46428 /*
46429 @@ -2281,6 +2370,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46430 error = vfs_create(dir->d_inode, dentry, mode, nd);
46431 if (error)
46432 goto exit_mutex_unlock;
46433 + else
46434 + gr_handle_create(path->dentry, path->mnt);
46435 mutex_unlock(&dir->d_inode->i_mutex);
46436 dput(nd->path.dentry);
46437 nd->path.dentry = dentry;
46438 @@ -2290,6 +2381,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46439 /*
46440 * It already exists.
46441 */
46442 +
46443 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46444 + error = -ENOENT;
46445 + goto exit_mutex_unlock;
46446 + }
46447 +
46448 + /* only check if O_CREAT is specified, all other checks need to go
46449 + into may_open */
46450 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46451 + error = -EACCES;
46452 + goto exit_mutex_unlock;
46453 + }
46454 +
46455 mutex_unlock(&dir->d_inode->i_mutex);
46456 audit_inode(pathname, path->dentry);
46457
46458 @@ -2407,8 +2511,14 @@ static struct file *path_openat(int dfd, const char *pathname,
46459 error = follow_link(&link, nd, &cookie);
46460 if (unlikely(error))
46461 filp = ERR_PTR(error);
46462 - else
46463 + else {
46464 filp = do_last(nd, &path, op, pathname);
46465 + if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
46466 + if (filp)
46467 + fput(filp);
46468 + filp = ERR_PTR(-EACCES);
46469 + }
46470 + }
46471 put_link(nd, &link, cookie);
46472 }
46473 out:
46474 @@ -2502,6 +2612,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46475 *path = nd.path;
46476 return dentry;
46477 eexist:
46478 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46479 + dput(dentry);
46480 + dentry = ERR_PTR(-ENOENT);
46481 + goto fail;
46482 + }
46483 dput(dentry);
46484 dentry = ERR_PTR(-EEXIST);
46485 fail:
46486 @@ -2524,6 +2639,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46487 }
46488 EXPORT_SYMBOL(user_path_create);
46489
46490 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46491 +{
46492 + char *tmp = getname(pathname);
46493 + struct dentry *res;
46494 + if (IS_ERR(tmp))
46495 + return ERR_CAST(tmp);
46496 + res = kern_path_create(dfd, tmp, path, is_dir);
46497 + if (IS_ERR(res))
46498 + putname(tmp);
46499 + else
46500 + *to = tmp;
46501 + return res;
46502 +}
46503 +
46504 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46505 {
46506 int error = may_create(dir, dentry);
46507 @@ -2591,6 +2720,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46508 error = mnt_want_write(path.mnt);
46509 if (error)
46510 goto out_dput;
46511 +
46512 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46513 + error = -EPERM;
46514 + goto out_drop_write;
46515 + }
46516 +
46517 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46518 + error = -EACCES;
46519 + goto out_drop_write;
46520 + }
46521 +
46522 error = security_path_mknod(&path, dentry, mode, dev);
46523 if (error)
46524 goto out_drop_write;
46525 @@ -2608,6 +2748,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46526 }
46527 out_drop_write:
46528 mnt_drop_write(path.mnt);
46529 +
46530 + if (!error)
46531 + gr_handle_create(dentry, path.mnt);
46532 out_dput:
46533 dput(dentry);
46534 mutex_unlock(&path.dentry->d_inode->i_mutex);
46535 @@ -2661,12 +2804,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46536 error = mnt_want_write(path.mnt);
46537 if (error)
46538 goto out_dput;
46539 +
46540 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46541 + error = -EACCES;
46542 + goto out_drop_write;
46543 + }
46544 +
46545 error = security_path_mkdir(&path, dentry, mode);
46546 if (error)
46547 goto out_drop_write;
46548 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46549 out_drop_write:
46550 mnt_drop_write(path.mnt);
46551 +
46552 + if (!error)
46553 + gr_handle_create(dentry, path.mnt);
46554 out_dput:
46555 dput(dentry);
46556 mutex_unlock(&path.dentry->d_inode->i_mutex);
46557 @@ -2746,6 +2898,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46558 char * name;
46559 struct dentry *dentry;
46560 struct nameidata nd;
46561 + ino_t saved_ino = 0;
46562 + dev_t saved_dev = 0;
46563
46564 error = user_path_parent(dfd, pathname, &nd, &name);
46565 if (error)
46566 @@ -2774,6 +2928,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46567 error = -ENOENT;
46568 goto exit3;
46569 }
46570 +
46571 + saved_ino = dentry->d_inode->i_ino;
46572 + saved_dev = gr_get_dev_from_dentry(dentry);
46573 +
46574 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46575 + error = -EACCES;
46576 + goto exit3;
46577 + }
46578 +
46579 error = mnt_want_write(nd.path.mnt);
46580 if (error)
46581 goto exit3;
46582 @@ -2781,6 +2944,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46583 if (error)
46584 goto exit4;
46585 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46586 + if (!error && (saved_dev || saved_ino))
46587 + gr_handle_delete(saved_ino, saved_dev);
46588 exit4:
46589 mnt_drop_write(nd.path.mnt);
46590 exit3:
46591 @@ -2843,6 +3008,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46592 struct dentry *dentry;
46593 struct nameidata nd;
46594 struct inode *inode = NULL;
46595 + ino_t saved_ino = 0;
46596 + dev_t saved_dev = 0;
46597
46598 error = user_path_parent(dfd, pathname, &nd, &name);
46599 if (error)
46600 @@ -2865,6 +3032,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46601 if (!inode)
46602 goto slashes;
46603 ihold(inode);
46604 +
46605 + if (inode->i_nlink <= 1) {
46606 + saved_ino = inode->i_ino;
46607 + saved_dev = gr_get_dev_from_dentry(dentry);
46608 + }
46609 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46610 + error = -EACCES;
46611 + goto exit2;
46612 + }
46613 +
46614 error = mnt_want_write(nd.path.mnt);
46615 if (error)
46616 goto exit2;
46617 @@ -2872,6 +3049,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46618 if (error)
46619 goto exit3;
46620 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46621 + if (!error && (saved_ino || saved_dev))
46622 + gr_handle_delete(saved_ino, saved_dev);
46623 exit3:
46624 mnt_drop_write(nd.path.mnt);
46625 exit2:
46626 @@ -2947,10 +3126,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46627 error = mnt_want_write(path.mnt);
46628 if (error)
46629 goto out_dput;
46630 +
46631 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46632 + error = -EACCES;
46633 + goto out_drop_write;
46634 + }
46635 +
46636 error = security_path_symlink(&path, dentry, from);
46637 if (error)
46638 goto out_drop_write;
46639 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46640 + if (!error)
46641 + gr_handle_create(dentry, path.mnt);
46642 out_drop_write:
46643 mnt_drop_write(path.mnt);
46644 out_dput:
46645 @@ -3025,6 +3212,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46646 {
46647 struct dentry *new_dentry;
46648 struct path old_path, new_path;
46649 + char *to = NULL;
46650 int how = 0;
46651 int error;
46652
46653 @@ -3048,7 +3236,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46654 if (error)
46655 return error;
46656
46657 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46658 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46659 error = PTR_ERR(new_dentry);
46660 if (IS_ERR(new_dentry))
46661 goto out;
46662 @@ -3059,13 +3247,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46663 error = mnt_want_write(new_path.mnt);
46664 if (error)
46665 goto out_dput;
46666 +
46667 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46668 + old_path.dentry->d_inode,
46669 + old_path.dentry->d_inode->i_mode, to)) {
46670 + error = -EACCES;
46671 + goto out_drop_write;
46672 + }
46673 +
46674 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46675 + old_path.dentry, old_path.mnt, to)) {
46676 + error = -EACCES;
46677 + goto out_drop_write;
46678 + }
46679 +
46680 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46681 if (error)
46682 goto out_drop_write;
46683 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46684 + if (!error)
46685 + gr_handle_create(new_dentry, new_path.mnt);
46686 out_drop_write:
46687 mnt_drop_write(new_path.mnt);
46688 out_dput:
46689 + putname(to);
46690 dput(new_dentry);
46691 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46692 path_put(&new_path);
46693 @@ -3299,6 +3504,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46694 if (new_dentry == trap)
46695 goto exit5;
46696
46697 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46698 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
46699 + to);
46700 + if (error)
46701 + goto exit5;
46702 +
46703 error = mnt_want_write(oldnd.path.mnt);
46704 if (error)
46705 goto exit5;
46706 @@ -3308,6 +3519,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46707 goto exit6;
46708 error = vfs_rename(old_dir->d_inode, old_dentry,
46709 new_dir->d_inode, new_dentry);
46710 + if (!error)
46711 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46712 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46713 exit6:
46714 mnt_drop_write(oldnd.path.mnt);
46715 exit5:
46716 @@ -3333,6 +3547,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46717
46718 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46719 {
46720 + char tmpbuf[64];
46721 + const char *newlink;
46722 int len;
46723
46724 len = PTR_ERR(link);
46725 @@ -3342,7 +3558,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46726 len = strlen(link);
46727 if (len > (unsigned) buflen)
46728 len = buflen;
46729 - if (copy_to_user(buffer, link, len))
46730 +
46731 + if (len < sizeof(tmpbuf)) {
46732 + memcpy(tmpbuf, link, len);
46733 + newlink = tmpbuf;
46734 + } else
46735 + newlink = link;
46736 +
46737 + if (copy_to_user(buffer, newlink, len))
46738 len = -EFAULT;
46739 out:
46740 return len;
46741 diff --git a/fs/namespace.c b/fs/namespace.c
46742 index 4e46539..b28253c 100644
46743 --- a/fs/namespace.c
46744 +++ b/fs/namespace.c
46745 @@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46746 if (!(sb->s_flags & MS_RDONLY))
46747 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46748 up_write(&sb->s_umount);
46749 +
46750 + gr_log_remount(mnt->mnt_devname, retval);
46751 +
46752 return retval;
46753 }
46754
46755 @@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
46756 br_write_unlock(vfsmount_lock);
46757 up_write(&namespace_sem);
46758 release_mounts(&umount_list);
46759 +
46760 + gr_log_unmount(mnt->mnt_devname, retval);
46761 +
46762 return retval;
46763 }
46764
46765 @@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46766 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46767 MS_STRICTATIME);
46768
46769 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46770 + retval = -EPERM;
46771 + goto dput_out;
46772 + }
46773 +
46774 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46775 + retval = -EPERM;
46776 + goto dput_out;
46777 + }
46778 +
46779 if (flags & MS_REMOUNT)
46780 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46781 data_page);
46782 @@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46783 dev_name, data_page);
46784 dput_out:
46785 path_put(&path);
46786 +
46787 + gr_log_mount(dev_name, dir_name, retval);
46788 +
46789 return retval;
46790 }
46791
46792 @@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46793 if (error)
46794 goto out2;
46795
46796 + if (gr_handle_chroot_pivot()) {
46797 + error = -EPERM;
46798 + goto out2;
46799 + }
46800 +
46801 get_fs_root(current->fs, &root);
46802 error = lock_mount(&old);
46803 if (error)
46804 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46805 index e8bbfa5..864f936 100644
46806 --- a/fs/nfs/inode.c
46807 +++ b/fs/nfs/inode.c
46808 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46809 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46810 nfsi->attrtimeo_timestamp = jiffies;
46811
46812 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46813 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46814 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46815 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46816 else
46817 @@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46818 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46819 }
46820
46821 -static atomic_long_t nfs_attr_generation_counter;
46822 +static atomic_long_unchecked_t nfs_attr_generation_counter;
46823
46824 static unsigned long nfs_read_attr_generation_counter(void)
46825 {
46826 - return atomic_long_read(&nfs_attr_generation_counter);
46827 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46828 }
46829
46830 unsigned long nfs_inc_attr_generation_counter(void)
46831 {
46832 - return atomic_long_inc_return(&nfs_attr_generation_counter);
46833 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46834 }
46835
46836 void nfs_fattr_init(struct nfs_fattr *fattr)
46837 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46838 index 5686661..80a9a3a 100644
46839 --- a/fs/nfsd/vfs.c
46840 +++ b/fs/nfsd/vfs.c
46841 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46842 } else {
46843 oldfs = get_fs();
46844 set_fs(KERNEL_DS);
46845 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46846 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46847 set_fs(oldfs);
46848 }
46849
46850 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46851
46852 /* Write the data. */
46853 oldfs = get_fs(); set_fs(KERNEL_DS);
46854 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46855 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46856 set_fs(oldfs);
46857 if (host_err < 0)
46858 goto out_nfserr;
46859 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46860 */
46861
46862 oldfs = get_fs(); set_fs(KERNEL_DS);
46863 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
46864 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
46865 set_fs(oldfs);
46866
46867 if (host_err < 0)
46868 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46869 index 3568c8a..e0240d8 100644
46870 --- a/fs/notify/fanotify/fanotify_user.c
46871 +++ b/fs/notify/fanotify/fanotify_user.c
46872 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46873 goto out_close_fd;
46874
46875 ret = -EFAULT;
46876 - if (copy_to_user(buf, &fanotify_event_metadata,
46877 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46878 + copy_to_user(buf, &fanotify_event_metadata,
46879 fanotify_event_metadata.event_len))
46880 goto out_kill_access_response;
46881
46882 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46883 index c887b13..0fdf472 100644
46884 --- a/fs/notify/notification.c
46885 +++ b/fs/notify/notification.c
46886 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46887 * get set to 0 so it will never get 'freed'
46888 */
46889 static struct fsnotify_event *q_overflow_event;
46890 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46891 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46892
46893 /**
46894 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46895 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46896 */
46897 u32 fsnotify_get_cookie(void)
46898 {
46899 - return atomic_inc_return(&fsnotify_sync_cookie);
46900 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46901 }
46902 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46903
46904 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46905 index 99e3610..02c1068 100644
46906 --- a/fs/ntfs/dir.c
46907 +++ b/fs/ntfs/dir.c
46908 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
46909 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46910 ~(s64)(ndir->itype.index.block_size - 1)));
46911 /* Bounds checks. */
46912 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46913 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46914 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46915 "inode 0x%lx or driver bug.", vdir->i_ino);
46916 goto err_out;
46917 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46918 index 8639169..76697aa 100644
46919 --- a/fs/ntfs/file.c
46920 +++ b/fs/ntfs/file.c
46921 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46922 #endif /* NTFS_RW */
46923 };
46924
46925 -const struct file_operations ntfs_empty_file_ops = {};
46926 +const struct file_operations ntfs_empty_file_ops __read_only;
46927
46928 -const struct inode_operations ntfs_empty_inode_ops = {};
46929 +const struct inode_operations ntfs_empty_inode_ops __read_only;
46930 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46931 index 210c352..a174f83 100644
46932 --- a/fs/ocfs2/localalloc.c
46933 +++ b/fs/ocfs2/localalloc.c
46934 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46935 goto bail;
46936 }
46937
46938 - atomic_inc(&osb->alloc_stats.moves);
46939 + atomic_inc_unchecked(&osb->alloc_stats.moves);
46940
46941 bail:
46942 if (handle)
46943 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46944 index d355e6e..578d905 100644
46945 --- a/fs/ocfs2/ocfs2.h
46946 +++ b/fs/ocfs2/ocfs2.h
46947 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
46948
46949 struct ocfs2_alloc_stats
46950 {
46951 - atomic_t moves;
46952 - atomic_t local_data;
46953 - atomic_t bitmap_data;
46954 - atomic_t bg_allocs;
46955 - atomic_t bg_extends;
46956 + atomic_unchecked_t moves;
46957 + atomic_unchecked_t local_data;
46958 + atomic_unchecked_t bitmap_data;
46959 + atomic_unchecked_t bg_allocs;
46960 + atomic_unchecked_t bg_extends;
46961 };
46962
46963 enum ocfs2_local_alloc_state
46964 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46965 index f169da4..9112253 100644
46966 --- a/fs/ocfs2/suballoc.c
46967 +++ b/fs/ocfs2/suballoc.c
46968 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46969 mlog_errno(status);
46970 goto bail;
46971 }
46972 - atomic_inc(&osb->alloc_stats.bg_extends);
46973 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46974
46975 /* You should never ask for this much metadata */
46976 BUG_ON(bits_wanted >
46977 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46978 mlog_errno(status);
46979 goto bail;
46980 }
46981 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46982 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46983
46984 *suballoc_loc = res.sr_bg_blkno;
46985 *suballoc_bit_start = res.sr_bit_offset;
46986 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46987 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46988 res->sr_bits);
46989
46990 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46991 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46992
46993 BUG_ON(res->sr_bits != 1);
46994
46995 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46996 mlog_errno(status);
46997 goto bail;
46998 }
46999 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47000 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47001
47002 BUG_ON(res.sr_bits != 1);
47003
47004 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47005 cluster_start,
47006 num_clusters);
47007 if (!status)
47008 - atomic_inc(&osb->alloc_stats.local_data);
47009 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47010 } else {
47011 if (min_clusters > (osb->bitmap_cpg - 1)) {
47012 /* The only paths asking for contiguousness
47013 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47014 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47015 res.sr_bg_blkno,
47016 res.sr_bit_offset);
47017 - atomic_inc(&osb->alloc_stats.bitmap_data);
47018 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47019 *num_clusters = res.sr_bits;
47020 }
47021 }
47022 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47023 index 68f4541..89cfe6a 100644
47024 --- a/fs/ocfs2/super.c
47025 +++ b/fs/ocfs2/super.c
47026 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47027 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47028 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47029 "Stats",
47030 - atomic_read(&osb->alloc_stats.bitmap_data),
47031 - atomic_read(&osb->alloc_stats.local_data),
47032 - atomic_read(&osb->alloc_stats.bg_allocs),
47033 - atomic_read(&osb->alloc_stats.moves),
47034 - atomic_read(&osb->alloc_stats.bg_extends));
47035 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47036 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47037 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47038 + atomic_read_unchecked(&osb->alloc_stats.moves),
47039 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47040
47041 out += snprintf(buf + out, len - out,
47042 "%10s => State: %u Descriptor: %llu Size: %u bits "
47043 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47044 spin_lock_init(&osb->osb_xattr_lock);
47045 ocfs2_init_steal_slots(osb);
47046
47047 - atomic_set(&osb->alloc_stats.moves, 0);
47048 - atomic_set(&osb->alloc_stats.local_data, 0);
47049 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47050 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47051 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47052 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47053 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47054 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47055 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47056 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47057
47058 /* Copy the blockcheck stats from the superblock probe */
47059 osb->osb_ecc_stats = *stats;
47060 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47061 index 5d22872..523db20 100644
47062 --- a/fs/ocfs2/symlink.c
47063 +++ b/fs/ocfs2/symlink.c
47064 @@ -142,7 +142,7 @@ bail:
47065
47066 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47067 {
47068 - char *link = nd_get_link(nd);
47069 + const char *link = nd_get_link(nd);
47070 if (!IS_ERR(link))
47071 kfree(link);
47072 }
47073 diff --git a/fs/open.c b/fs/open.c
47074 index 3f1108b..822d7f7 100644
47075 --- a/fs/open.c
47076 +++ b/fs/open.c
47077 @@ -31,6 +31,8 @@
47078 #include <linux/ima.h>
47079 #include <linux/dnotify.h>
47080
47081 +#define CREATE_TRACE_POINTS
47082 +#include <trace/events/fs.h>
47083 #include "internal.h"
47084
47085 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47086 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47087 error = locks_verify_truncate(inode, NULL, length);
47088 if (!error)
47089 error = security_path_truncate(&path);
47090 +
47091 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47092 + error = -EACCES;
47093 +
47094 if (!error)
47095 error = do_truncate(path.dentry, length, 0, NULL);
47096
47097 @@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47098 if (__mnt_is_readonly(path.mnt))
47099 res = -EROFS;
47100
47101 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47102 + res = -EACCES;
47103 +
47104 out_path_release:
47105 path_put(&path);
47106 out:
47107 @@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47108 if (error)
47109 goto dput_and_out;
47110
47111 + gr_log_chdir(path.dentry, path.mnt);
47112 +
47113 set_fs_pwd(current->fs, &path);
47114
47115 dput_and_out:
47116 @@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47117 goto out_putf;
47118
47119 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47120 +
47121 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47122 + error = -EPERM;
47123 +
47124 + if (!error)
47125 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47126 +
47127 if (!error)
47128 set_fs_pwd(current->fs, &file->f_path);
47129 out_putf:
47130 @@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47131 if (error)
47132 goto dput_and_out;
47133
47134 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47135 + goto dput_and_out;
47136 +
47137 set_fs_root(current->fs, &path);
47138 +
47139 + gr_handle_chroot_chdir(&path);
47140 +
47141 error = 0;
47142 dput_and_out:
47143 path_put(&path);
47144 @@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47145 if (error)
47146 return error;
47147 mutex_lock(&inode->i_mutex);
47148 +
47149 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47150 + error = -EACCES;
47151 + goto out_unlock;
47152 + }
47153 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47154 + error = -EACCES;
47155 + goto out_unlock;
47156 + }
47157 +
47158 error = security_path_chmod(path, mode);
47159 if (error)
47160 goto out_unlock;
47161 @@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47162 int error;
47163 struct iattr newattrs;
47164
47165 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47166 + return -EACCES;
47167 +
47168 newattrs.ia_valid = ATTR_CTIME;
47169 if (user != (uid_t) -1) {
47170 newattrs.ia_valid |= ATTR_UID;
47171 @@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47172 } else {
47173 fsnotify_open(f);
47174 fd_install(fd, f);
47175 + trace_do_sys_open(tmp, flags, mode);
47176 }
47177 }
47178 putname(tmp);
47179 diff --git a/fs/pipe.c b/fs/pipe.c
47180 index fec5e4a..f4210f9 100644
47181 --- a/fs/pipe.c
47182 +++ b/fs/pipe.c
47183 @@ -438,9 +438,9 @@ redo:
47184 }
47185 if (bufs) /* More to do? */
47186 continue;
47187 - if (!pipe->writers)
47188 + if (!atomic_read(&pipe->writers))
47189 break;
47190 - if (!pipe->waiting_writers) {
47191 + if (!atomic_read(&pipe->waiting_writers)) {
47192 /* syscall merging: Usually we must not sleep
47193 * if O_NONBLOCK is set, or if we got some data.
47194 * But if a writer sleeps in kernel space, then
47195 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47196 mutex_lock(&inode->i_mutex);
47197 pipe = inode->i_pipe;
47198
47199 - if (!pipe->readers) {
47200 + if (!atomic_read(&pipe->readers)) {
47201 send_sig(SIGPIPE, current, 0);
47202 ret = -EPIPE;
47203 goto out;
47204 @@ -553,7 +553,7 @@ redo1:
47205 for (;;) {
47206 int bufs;
47207
47208 - if (!pipe->readers) {
47209 + if (!atomic_read(&pipe->readers)) {
47210 send_sig(SIGPIPE, current, 0);
47211 if (!ret)
47212 ret = -EPIPE;
47213 @@ -644,9 +644,9 @@ redo2:
47214 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47215 do_wakeup = 0;
47216 }
47217 - pipe->waiting_writers++;
47218 + atomic_inc(&pipe->waiting_writers);
47219 pipe_wait(pipe);
47220 - pipe->waiting_writers--;
47221 + atomic_dec(&pipe->waiting_writers);
47222 }
47223 out:
47224 mutex_unlock(&inode->i_mutex);
47225 @@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47226 mask = 0;
47227 if (filp->f_mode & FMODE_READ) {
47228 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47229 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47230 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47231 mask |= POLLHUP;
47232 }
47233
47234 @@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47235 * Most Unices do not set POLLERR for FIFOs but on Linux they
47236 * behave exactly like pipes for poll().
47237 */
47238 - if (!pipe->readers)
47239 + if (!atomic_read(&pipe->readers))
47240 mask |= POLLERR;
47241 }
47242
47243 @@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47244
47245 mutex_lock(&inode->i_mutex);
47246 pipe = inode->i_pipe;
47247 - pipe->readers -= decr;
47248 - pipe->writers -= decw;
47249 + atomic_sub(decr, &pipe->readers);
47250 + atomic_sub(decw, &pipe->writers);
47251
47252 - if (!pipe->readers && !pipe->writers) {
47253 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47254 free_pipe_info(inode);
47255 } else {
47256 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47257 @@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47258
47259 if (inode->i_pipe) {
47260 ret = 0;
47261 - inode->i_pipe->readers++;
47262 + atomic_inc(&inode->i_pipe->readers);
47263 }
47264
47265 mutex_unlock(&inode->i_mutex);
47266 @@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47267
47268 if (inode->i_pipe) {
47269 ret = 0;
47270 - inode->i_pipe->writers++;
47271 + atomic_inc(&inode->i_pipe->writers);
47272 }
47273
47274 mutex_unlock(&inode->i_mutex);
47275 @@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47276 if (inode->i_pipe) {
47277 ret = 0;
47278 if (filp->f_mode & FMODE_READ)
47279 - inode->i_pipe->readers++;
47280 + atomic_inc(&inode->i_pipe->readers);
47281 if (filp->f_mode & FMODE_WRITE)
47282 - inode->i_pipe->writers++;
47283 + atomic_inc(&inode->i_pipe->writers);
47284 }
47285
47286 mutex_unlock(&inode->i_mutex);
47287 @@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47288 inode->i_pipe = NULL;
47289 }
47290
47291 -static struct vfsmount *pipe_mnt __read_mostly;
47292 +struct vfsmount *pipe_mnt __read_mostly;
47293
47294 /*
47295 * pipefs_dname() is called from d_path().
47296 @@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47297 goto fail_iput;
47298 inode->i_pipe = pipe;
47299
47300 - pipe->readers = pipe->writers = 1;
47301 + atomic_set(&pipe->readers, 1);
47302 + atomic_set(&pipe->writers, 1);
47303 inode->i_fop = &rdwr_pipefifo_fops;
47304
47305 /*
47306 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47307 index 15af622..0e9f4467 100644
47308 --- a/fs/proc/Kconfig
47309 +++ b/fs/proc/Kconfig
47310 @@ -30,12 +30,12 @@ config PROC_FS
47311
47312 config PROC_KCORE
47313 bool "/proc/kcore support" if !ARM
47314 - depends on PROC_FS && MMU
47315 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47316
47317 config PROC_VMCORE
47318 bool "/proc/vmcore support"
47319 - depends on PROC_FS && CRASH_DUMP
47320 - default y
47321 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47322 + default n
47323 help
47324 Exports the dump image of crashed kernel in ELF format.
47325
47326 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47327 limited in memory.
47328
47329 config PROC_PAGE_MONITOR
47330 - default y
47331 - depends on PROC_FS && MMU
47332 + default n
47333 + depends on PROC_FS && MMU && !GRKERNSEC
47334 bool "Enable /proc page monitoring" if EXPERT
47335 help
47336 Various /proc files exist to monitor process memory utilization:
47337 diff --git a/fs/proc/array.c b/fs/proc/array.c
47338 index f9bd395..acb7847 100644
47339 --- a/fs/proc/array.c
47340 +++ b/fs/proc/array.c
47341 @@ -60,6 +60,7 @@
47342 #include <linux/tty.h>
47343 #include <linux/string.h>
47344 #include <linux/mman.h>
47345 +#include <linux/grsecurity.h>
47346 #include <linux/proc_fs.h>
47347 #include <linux/ioport.h>
47348 #include <linux/uaccess.h>
47349 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47350 seq_putc(m, '\n');
47351 }
47352
47353 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47354 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47355 +{
47356 + if (p->mm)
47357 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47358 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47359 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47360 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47361 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47362 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47363 + else
47364 + seq_printf(m, "PaX:\t-----\n");
47365 +}
47366 +#endif
47367 +
47368 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47369 struct pid *pid, struct task_struct *task)
47370 {
47371 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47372 task_cpus_allowed(m, task);
47373 cpuset_task_status_allowed(m, task);
47374 task_context_switch_counts(m, task);
47375 +
47376 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47377 + task_pax(m, task);
47378 +#endif
47379 +
47380 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47381 + task_grsec_rbac(m, task);
47382 +#endif
47383 +
47384 return 0;
47385 }
47386
47387 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47388 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47389 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47390 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47391 +#endif
47392 +
47393 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47394 struct pid *pid, struct task_struct *task, int whole)
47395 {
47396 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47397 char tcomm[sizeof(task->comm)];
47398 unsigned long flags;
47399
47400 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47401 + if (current->exec_id != m->exec_id) {
47402 + gr_log_badprocpid("stat");
47403 + return 0;
47404 + }
47405 +#endif
47406 +
47407 state = *get_task_state(task);
47408 vsize = eip = esp = 0;
47409 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47410 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47411 gtime = task->gtime;
47412 }
47413
47414 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47415 + if (PAX_RAND_FLAGS(mm)) {
47416 + eip = 0;
47417 + esp = 0;
47418 + wchan = 0;
47419 + }
47420 +#endif
47421 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47422 + wchan = 0;
47423 + eip =0;
47424 + esp =0;
47425 +#endif
47426 +
47427 /* scale priority and nice values from timeslices to -20..20 */
47428 /* to make it look like a "normal" Unix priority/nice value */
47429 priority = task_prio(task);
47430 @@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47431 seq_put_decimal_ull(m, ' ', vsize);
47432 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47433 seq_put_decimal_ull(m, ' ', rsslim);
47434 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47435 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47436 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47437 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47438 +#else
47439 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47440 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47441 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47442 +#endif
47443 seq_put_decimal_ull(m, ' ', esp);
47444 seq_put_decimal_ull(m, ' ', eip);
47445 /* The signal information here is obsolete.
47446 @@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47447 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47448 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47449 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47450 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47451 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47452 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47453 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47454 +#else
47455 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47456 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47457 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47458 +#endif
47459 seq_putc(m, '\n');
47460 if (mm)
47461 mmput(mm);
47462 @@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47463 struct pid *pid, struct task_struct *task)
47464 {
47465 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47466 - struct mm_struct *mm = get_task_mm(task);
47467 + struct mm_struct *mm;
47468
47469 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47470 + if (current->exec_id != m->exec_id) {
47471 + gr_log_badprocpid("statm");
47472 + return 0;
47473 + }
47474 +#endif
47475 + mm = get_task_mm(task);
47476 if (mm) {
47477 size = task_statm(mm, &shared, &text, &data, &resident);
47478 mmput(mm);
47479 @@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47480
47481 return 0;
47482 }
47483 +
47484 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47485 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47486 +{
47487 + u32 curr_ip = 0;
47488 + unsigned long flags;
47489 +
47490 + if (lock_task_sighand(task, &flags)) {
47491 + curr_ip = task->signal->curr_ip;
47492 + unlock_task_sighand(task, &flags);
47493 + }
47494 +
47495 + return sprintf(buffer, "%pI4\n", &curr_ip);
47496 +}
47497 +#endif
47498 diff --git a/fs/proc/base.c b/fs/proc/base.c
47499 index 9fc77b4..04761b8 100644
47500 --- a/fs/proc/base.c
47501 +++ b/fs/proc/base.c
47502 @@ -109,6 +109,14 @@ struct pid_entry {
47503 union proc_op op;
47504 };
47505
47506 +struct getdents_callback {
47507 + struct linux_dirent __user * current_dir;
47508 + struct linux_dirent __user * previous;
47509 + struct file * file;
47510 + int count;
47511 + int error;
47512 +};
47513 +
47514 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47515 .name = (NAME), \
47516 .len = sizeof(NAME) - 1, \
47517 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47518 if (!mm->arg_end)
47519 goto out_mm; /* Shh! No looking before we're done */
47520
47521 + if (gr_acl_handle_procpidmem(task))
47522 + goto out_mm;
47523 +
47524 len = mm->arg_end - mm->arg_start;
47525
47526 if (len > PAGE_SIZE)
47527 @@ -240,12 +251,28 @@ out:
47528 return res;
47529 }
47530
47531 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47532 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47533 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47534 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47535 +#endif
47536 +
47537 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47538 {
47539 struct mm_struct *mm = mm_for_maps(task);
47540 int res = PTR_ERR(mm);
47541 if (mm && !IS_ERR(mm)) {
47542 unsigned int nwords = 0;
47543 +
47544 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47545 + /* allow if we're currently ptracing this task */
47546 + if (PAX_RAND_FLAGS(mm) &&
47547 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47548 + mmput(mm);
47549 + return 0;
47550 + }
47551 +#endif
47552 +
47553 do {
47554 nwords += 2;
47555 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47556 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47557 }
47558
47559
47560 -#ifdef CONFIG_KALLSYMS
47561 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47562 /*
47563 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47564 * Returns the resolved symbol. If that fails, simply return the address.
47565 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47566 mutex_unlock(&task->signal->cred_guard_mutex);
47567 }
47568
47569 -#ifdef CONFIG_STACKTRACE
47570 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47571
47572 #define MAX_STACK_TRACE_DEPTH 64
47573
47574 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47575 return count;
47576 }
47577
47578 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47579 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47580 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47581 {
47582 long nr;
47583 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47584 /************************************************************************/
47585
47586 /* permission checks */
47587 -static int proc_fd_access_allowed(struct inode *inode)
47588 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47589 {
47590 struct task_struct *task;
47591 int allowed = 0;
47592 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47593 */
47594 task = get_proc_task(inode);
47595 if (task) {
47596 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47597 + if (log)
47598 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47599 + else
47600 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47601 put_task_struct(task);
47602 }
47603 return allowed;
47604 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47605 struct task_struct *task,
47606 int hide_pid_min)
47607 {
47608 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47609 + return false;
47610 +
47611 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47612 + rcu_read_lock();
47613 + {
47614 + const struct cred *tmpcred = current_cred();
47615 + const struct cred *cred = __task_cred(task);
47616 +
47617 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47618 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47619 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47620 +#endif
47621 + ) {
47622 + rcu_read_unlock();
47623 + return true;
47624 + }
47625 + }
47626 + rcu_read_unlock();
47627 +
47628 + if (!pid->hide_pid)
47629 + return false;
47630 +#endif
47631 +
47632 if (pid->hide_pid < hide_pid_min)
47633 return true;
47634 if (in_group_p(pid->pid_gid))
47635 return true;
47636 +
47637 return ptrace_may_access(task, PTRACE_MODE_READ);
47638 }
47639
47640 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47641 put_task_struct(task);
47642
47643 if (!has_perms) {
47644 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47645 + {
47646 +#else
47647 if (pid->hide_pid == 2) {
47648 +#endif
47649 /*
47650 * Let's make getdents(), stat(), and open()
47651 * consistent with each other. If a process
47652 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47653 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47654 file->private_data = mm;
47655
47656 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47657 + file->f_version = current->exec_id;
47658 +#endif
47659 +
47660 return 0;
47661 }
47662
47663 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47664 ssize_t copied;
47665 char *page;
47666
47667 +#ifdef CONFIG_GRKERNSEC
47668 + if (write)
47669 + return -EPERM;
47670 +#endif
47671 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47672 + if (file->f_version != current->exec_id) {
47673 + gr_log_badprocpid("mem");
47674 + return 0;
47675 + }
47676 +#endif
47677 +
47678 if (!mm)
47679 return 0;
47680
47681 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47682 if (!task)
47683 goto out_no_task;
47684
47685 + if (gr_acl_handle_procpidmem(task))
47686 + goto out;
47687 +
47688 ret = -ENOMEM;
47689 page = (char *)__get_free_page(GFP_TEMPORARY);
47690 if (!page)
47691 @@ -1433,7 +1510,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47692 path_put(&nd->path);
47693
47694 /* Are we allowed to snoop on the tasks file descriptors? */
47695 - if (!proc_fd_access_allowed(inode))
47696 + if (!proc_fd_access_allowed(inode, 0))
47697 goto out;
47698
47699 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47700 @@ -1472,8 +1549,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47701 struct path path;
47702
47703 /* Are we allowed to snoop on the tasks file descriptors? */
47704 - if (!proc_fd_access_allowed(inode))
47705 - goto out;
47706 + /* logging this is needed for learning on chromium to work properly,
47707 + but we don't want to flood the logs from 'ps' which does a readlink
47708 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47709 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
47710 + */
47711 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47712 + if (!proc_fd_access_allowed(inode,0))
47713 + goto out;
47714 + } else {
47715 + if (!proc_fd_access_allowed(inode,1))
47716 + goto out;
47717 + }
47718
47719 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47720 if (error)
47721 @@ -1538,7 +1625,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47722 rcu_read_lock();
47723 cred = __task_cred(task);
47724 inode->i_uid = cred->euid;
47725 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47726 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47727 +#else
47728 inode->i_gid = cred->egid;
47729 +#endif
47730 rcu_read_unlock();
47731 }
47732 security_task_to_inode(task, inode);
47733 @@ -1574,10 +1665,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47734 return -ENOENT;
47735 }
47736 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47737 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47738 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47739 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47740 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47741 +#endif
47742 task_dumpable(task)) {
47743 cred = __task_cred(task);
47744 stat->uid = cred->euid;
47745 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47746 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47747 +#else
47748 stat->gid = cred->egid;
47749 +#endif
47750 }
47751 }
47752 rcu_read_unlock();
47753 @@ -1615,11 +1715,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47754
47755 if (task) {
47756 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47757 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47758 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47759 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47760 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47761 +#endif
47762 task_dumpable(task)) {
47763 rcu_read_lock();
47764 cred = __task_cred(task);
47765 inode->i_uid = cred->euid;
47766 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47767 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47768 +#else
47769 inode->i_gid = cred->egid;
47770 +#endif
47771 rcu_read_unlock();
47772 } else {
47773 inode->i_uid = 0;
47774 @@ -1737,7 +1846,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47775 int fd = proc_fd(inode);
47776
47777 if (task) {
47778 - files = get_files_struct(task);
47779 + if (!gr_acl_handle_procpidmem(task))
47780 + files = get_files_struct(task);
47781 put_task_struct(task);
47782 }
47783 if (files) {
47784 @@ -2338,11 +2448,21 @@ static const struct file_operations proc_map_files_operations = {
47785 */
47786 static int proc_fd_permission(struct inode *inode, int mask)
47787 {
47788 + struct task_struct *task;
47789 int rv = generic_permission(inode, mask);
47790 - if (rv == 0)
47791 - return 0;
47792 +
47793 if (task_pid(current) == proc_pid(inode))
47794 rv = 0;
47795 +
47796 + task = get_proc_task(inode);
47797 + if (task == NULL)
47798 + return rv;
47799 +
47800 + if (gr_acl_handle_procpidmem(task))
47801 + rv = -EACCES;
47802 +
47803 + put_task_struct(task);
47804 +
47805 return rv;
47806 }
47807
47808 @@ -2452,6 +2572,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47809 if (!task)
47810 goto out_no_task;
47811
47812 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47813 + goto out;
47814 +
47815 /*
47816 * Yes, it does not scale. And it should not. Don't add
47817 * new entries into /proc/<tgid>/ without very good reasons.
47818 @@ -2496,6 +2619,9 @@ static int proc_pident_readdir(struct file *filp,
47819 if (!task)
47820 goto out_no_task;
47821
47822 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47823 + goto out;
47824 +
47825 ret = 0;
47826 i = filp->f_pos;
47827 switch (i) {
47828 @@ -2766,7 +2892,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47829 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47830 void *cookie)
47831 {
47832 - char *s = nd_get_link(nd);
47833 + const char *s = nd_get_link(nd);
47834 if (!IS_ERR(s))
47835 __putname(s);
47836 }
47837 @@ -2967,7 +3093,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47838 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47839 #endif
47840 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47841 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47842 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47843 INF("syscall", S_IRUGO, proc_pid_syscall),
47844 #endif
47845 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47846 @@ -2992,10 +3118,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47847 #ifdef CONFIG_SECURITY
47848 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47849 #endif
47850 -#ifdef CONFIG_KALLSYMS
47851 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47852 INF("wchan", S_IRUGO, proc_pid_wchan),
47853 #endif
47854 -#ifdef CONFIG_STACKTRACE
47855 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47856 ONE("stack", S_IRUGO, proc_pid_stack),
47857 #endif
47858 #ifdef CONFIG_SCHEDSTATS
47859 @@ -3029,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47860 #ifdef CONFIG_HARDWALL
47861 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47862 #endif
47863 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47864 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47865 +#endif
47866 };
47867
47868 static int proc_tgid_base_readdir(struct file * filp,
47869 @@ -3155,7 +3284,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47870 if (!inode)
47871 goto out;
47872
47873 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47874 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47875 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47876 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47877 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47878 +#else
47879 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47880 +#endif
47881 inode->i_op = &proc_tgid_base_inode_operations;
47882 inode->i_fop = &proc_tgid_base_operations;
47883 inode->i_flags|=S_IMMUTABLE;
47884 @@ -3197,7 +3333,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47885 if (!task)
47886 goto out;
47887
47888 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47889 + goto out_put_task;
47890 +
47891 result = proc_pid_instantiate(dir, dentry, task, NULL);
47892 +out_put_task:
47893 put_task_struct(task);
47894 out:
47895 return result;
47896 @@ -3260,6 +3400,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47897 static int fake_filldir(void *buf, const char *name, int namelen,
47898 loff_t offset, u64 ino, unsigned d_type)
47899 {
47900 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
47901 + __buf->error = -EINVAL;
47902 return 0;
47903 }
47904
47905 @@ -3326,7 +3468,7 @@ static const struct pid_entry tid_base_stuff[] = {
47906 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47907 #endif
47908 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47909 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47910 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47911 INF("syscall", S_IRUGO, proc_pid_syscall),
47912 #endif
47913 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47914 @@ -3350,10 +3492,10 @@ static const struct pid_entry tid_base_stuff[] = {
47915 #ifdef CONFIG_SECURITY
47916 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47917 #endif
47918 -#ifdef CONFIG_KALLSYMS
47919 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47920 INF("wchan", S_IRUGO, proc_pid_wchan),
47921 #endif
47922 -#ifdef CONFIG_STACKTRACE
47923 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47924 ONE("stack", S_IRUGO, proc_pid_stack),
47925 #endif
47926 #ifdef CONFIG_SCHEDSTATS
47927 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47928 index 82676e3..5f8518a 100644
47929 --- a/fs/proc/cmdline.c
47930 +++ b/fs/proc/cmdline.c
47931 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47932
47933 static int __init proc_cmdline_init(void)
47934 {
47935 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47936 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47937 +#else
47938 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47939 +#endif
47940 return 0;
47941 }
47942 module_init(proc_cmdline_init);
47943 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47944 index b143471..bb105e5 100644
47945 --- a/fs/proc/devices.c
47946 +++ b/fs/proc/devices.c
47947 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47948
47949 static int __init proc_devices_init(void)
47950 {
47951 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47952 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47953 +#else
47954 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47955 +#endif
47956 return 0;
47957 }
47958 module_init(proc_devices_init);
47959 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47960 index 205c922..2ee4c57 100644
47961 --- a/fs/proc/inode.c
47962 +++ b/fs/proc/inode.c
47963 @@ -21,11 +21,17 @@
47964 #include <linux/seq_file.h>
47965 #include <linux/slab.h>
47966 #include <linux/mount.h>
47967 +#include <linux/grsecurity.h>
47968
47969 #include <asm/uaccess.h>
47970
47971 #include "internal.h"
47972
47973 +#ifdef CONFIG_PROC_SYSCTL
47974 +extern const struct inode_operations proc_sys_inode_operations;
47975 +extern const struct inode_operations proc_sys_dir_operations;
47976 +#endif
47977 +
47978 static void proc_evict_inode(struct inode *inode)
47979 {
47980 struct proc_dir_entry *de;
47981 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
47982 ns_ops = PROC_I(inode)->ns_ops;
47983 if (ns_ops && ns_ops->put)
47984 ns_ops->put(PROC_I(inode)->ns);
47985 +
47986 +#ifdef CONFIG_PROC_SYSCTL
47987 + if (inode->i_op == &proc_sys_inode_operations ||
47988 + inode->i_op == &proc_sys_dir_operations)
47989 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47990 +#endif
47991 +
47992 }
47993
47994 static struct kmem_cache * proc_inode_cachep;
47995 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47996 if (de->mode) {
47997 inode->i_mode = de->mode;
47998 inode->i_uid = de->uid;
47999 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48000 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48001 +#else
48002 inode->i_gid = de->gid;
48003 +#endif
48004 }
48005 if (de->size)
48006 inode->i_size = de->size;
48007 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48008 index 5f79bb8..eeccee4 100644
48009 --- a/fs/proc/internal.h
48010 +++ b/fs/proc/internal.h
48011 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48012 struct pid *pid, struct task_struct *task);
48013 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48014 struct pid *pid, struct task_struct *task);
48015 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48016 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48017 +#endif
48018 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48019
48020 extern const struct file_operations proc_pid_maps_operations;
48021 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48022 index 86c67ee..cdca321 100644
48023 --- a/fs/proc/kcore.c
48024 +++ b/fs/proc/kcore.c
48025 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48026 * the addresses in the elf_phdr on our list.
48027 */
48028 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48029 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48030 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48031 + if (tsz > buflen)
48032 tsz = buflen;
48033 -
48034 +
48035 while (buflen) {
48036 struct kcore_list *m;
48037
48038 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48039 kfree(elf_buf);
48040 } else {
48041 if (kern_addr_valid(start)) {
48042 - unsigned long n;
48043 + char *elf_buf;
48044 + mm_segment_t oldfs;
48045
48046 - n = copy_to_user(buffer, (char *)start, tsz);
48047 - /*
48048 - * We cannot distinguish between fault on source
48049 - * and fault on destination. When this happens
48050 - * we clear too and hope it will trigger the
48051 - * EFAULT again.
48052 - */
48053 - if (n) {
48054 - if (clear_user(buffer + tsz - n,
48055 - n))
48056 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48057 + if (!elf_buf)
48058 + return -ENOMEM;
48059 + oldfs = get_fs();
48060 + set_fs(KERNEL_DS);
48061 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48062 + set_fs(oldfs);
48063 + if (copy_to_user(buffer, elf_buf, tsz)) {
48064 + kfree(elf_buf);
48065 return -EFAULT;
48066 + }
48067 }
48068 + set_fs(oldfs);
48069 + kfree(elf_buf);
48070 } else {
48071 if (clear_user(buffer, tsz))
48072 return -EFAULT;
48073 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48074
48075 static int open_kcore(struct inode *inode, struct file *filp)
48076 {
48077 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48078 + return -EPERM;
48079 +#endif
48080 if (!capable(CAP_SYS_RAWIO))
48081 return -EPERM;
48082 if (kcore_need_update)
48083 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48084 index 80e4645..53e5fcf 100644
48085 --- a/fs/proc/meminfo.c
48086 +++ b/fs/proc/meminfo.c
48087 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48088 vmi.used >> 10,
48089 vmi.largest_chunk >> 10
48090 #ifdef CONFIG_MEMORY_FAILURE
48091 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48092 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48093 #endif
48094 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48095 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48096 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48097 index b1822dd..df622cb 100644
48098 --- a/fs/proc/nommu.c
48099 +++ b/fs/proc/nommu.c
48100 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48101 if (len < 1)
48102 len = 1;
48103 seq_printf(m, "%*c", len, ' ');
48104 - seq_path(m, &file->f_path, "");
48105 + seq_path(m, &file->f_path, "\n\\");
48106 }
48107
48108 seq_putc(m, '\n');
48109 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48110 index 06e1cc1..177cd98 100644
48111 --- a/fs/proc/proc_net.c
48112 +++ b/fs/proc/proc_net.c
48113 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48114 struct task_struct *task;
48115 struct nsproxy *ns;
48116 struct net *net = NULL;
48117 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48118 + const struct cred *cred = current_cred();
48119 +#endif
48120 +
48121 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48122 + if (cred->fsuid)
48123 + return net;
48124 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48125 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48126 + return net;
48127 +#endif
48128
48129 rcu_read_lock();
48130 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48131 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48132 index 21d836f..bebf3ee 100644
48133 --- a/fs/proc/proc_sysctl.c
48134 +++ b/fs/proc/proc_sysctl.c
48135 @@ -12,11 +12,15 @@
48136 #include <linux/module.h>
48137 #include "internal.h"
48138
48139 +extern int gr_handle_chroot_sysctl(const int op);
48140 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48141 + const int op);
48142 +
48143 static const struct dentry_operations proc_sys_dentry_operations;
48144 static const struct file_operations proc_sys_file_operations;
48145 -static const struct inode_operations proc_sys_inode_operations;
48146 +const struct inode_operations proc_sys_inode_operations;
48147 static const struct file_operations proc_sys_dir_file_operations;
48148 -static const struct inode_operations proc_sys_dir_operations;
48149 +const struct inode_operations proc_sys_dir_operations;
48150
48151 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48152 {
48153 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48154
48155 err = NULL;
48156 d_set_d_op(dentry, &proc_sys_dentry_operations);
48157 +
48158 + gr_handle_proc_create(dentry, inode);
48159 +
48160 d_add(dentry, inode);
48161
48162 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48163 + err = ERR_PTR(-ENOENT);
48164 +
48165 out:
48166 sysctl_head_finish(head);
48167 return err;
48168 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48169 struct inode *inode = filp->f_path.dentry->d_inode;
48170 struct ctl_table_header *head = grab_header(inode);
48171 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48172 + int op = write ? MAY_WRITE : MAY_READ;
48173 ssize_t error;
48174 size_t res;
48175
48176 if (IS_ERR(head))
48177 return PTR_ERR(head);
48178
48179 +
48180 /*
48181 * At this point we know that the sysctl was not unregistered
48182 * and won't be until we finish.
48183 */
48184 error = -EPERM;
48185 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48186 + if (sysctl_perm(head->root, table, op))
48187 goto out;
48188
48189 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48190 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48191 if (!table->proc_handler)
48192 goto out;
48193
48194 +#ifdef CONFIG_GRKERNSEC
48195 + error = -EPERM;
48196 + if (gr_handle_chroot_sysctl(op))
48197 + goto out;
48198 + dget(filp->f_path.dentry);
48199 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48200 + dput(filp->f_path.dentry);
48201 + goto out;
48202 + }
48203 + dput(filp->f_path.dentry);
48204 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48205 + goto out;
48206 + if (write && !capable(CAP_SYS_ADMIN))
48207 + goto out;
48208 +#endif
48209 +
48210 /* careful: calling conventions are nasty here */
48211 res = count;
48212 error = table->proc_handler(table, write, buf, &res, ppos);
48213 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48214 return -ENOMEM;
48215 } else {
48216 d_set_d_op(child, &proc_sys_dentry_operations);
48217 +
48218 + gr_handle_proc_create(child, inode);
48219 +
48220 d_add(child, inode);
48221 }
48222 } else {
48223 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48224 if ((*pos)++ < file->f_pos)
48225 return 0;
48226
48227 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48228 + return 0;
48229 +
48230 if (unlikely(S_ISLNK(table->mode)))
48231 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48232 else
48233 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48234 if (IS_ERR(head))
48235 return PTR_ERR(head);
48236
48237 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48238 + return -ENOENT;
48239 +
48240 generic_fillattr(inode, stat);
48241 if (table)
48242 stat->mode = (stat->mode & S_IFMT) | table->mode;
48243 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48244 .llseek = generic_file_llseek,
48245 };
48246
48247 -static const struct inode_operations proc_sys_inode_operations = {
48248 +const struct inode_operations proc_sys_inode_operations = {
48249 .permission = proc_sys_permission,
48250 .setattr = proc_sys_setattr,
48251 .getattr = proc_sys_getattr,
48252 };
48253
48254 -static const struct inode_operations proc_sys_dir_operations = {
48255 +const struct inode_operations proc_sys_dir_operations = {
48256 .lookup = proc_sys_lookup,
48257 .permission = proc_sys_permission,
48258 .setattr = proc_sys_setattr,
48259 diff --git a/fs/proc/root.c b/fs/proc/root.c
48260 index eed44bf..abeb499 100644
48261 --- a/fs/proc/root.c
48262 +++ b/fs/proc/root.c
48263 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
48264 #ifdef CONFIG_PROC_DEVICETREE
48265 proc_device_tree_init();
48266 #endif
48267 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48268 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48269 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48270 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48271 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48272 +#endif
48273 +#else
48274 proc_mkdir("bus", NULL);
48275 +#endif
48276 proc_sys_init();
48277 }
48278
48279 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48280 index 7faaf2a..096c28b 100644
48281 --- a/fs/proc/task_mmu.c
48282 +++ b/fs/proc/task_mmu.c
48283 @@ -11,12 +11,19 @@
48284 #include <linux/rmap.h>
48285 #include <linux/swap.h>
48286 #include <linux/swapops.h>
48287 +#include <linux/grsecurity.h>
48288
48289 #include <asm/elf.h>
48290 #include <asm/uaccess.h>
48291 #include <asm/tlbflush.h>
48292 #include "internal.h"
48293
48294 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48295 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48296 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48297 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48298 +#endif
48299 +
48300 void task_mem(struct seq_file *m, struct mm_struct *mm)
48301 {
48302 unsigned long data, text, lib, swap;
48303 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48304 "VmExe:\t%8lu kB\n"
48305 "VmLib:\t%8lu kB\n"
48306 "VmPTE:\t%8lu kB\n"
48307 - "VmSwap:\t%8lu kB\n",
48308 - hiwater_vm << (PAGE_SHIFT-10),
48309 + "VmSwap:\t%8lu kB\n"
48310 +
48311 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48312 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48313 +#endif
48314 +
48315 + ,hiwater_vm << (PAGE_SHIFT-10),
48316 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48317 mm->locked_vm << (PAGE_SHIFT-10),
48318 mm->pinned_vm << (PAGE_SHIFT-10),
48319 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48320 data << (PAGE_SHIFT-10),
48321 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48322 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48323 - swap << (PAGE_SHIFT-10));
48324 + swap << (PAGE_SHIFT-10)
48325 +
48326 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48327 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48328 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48329 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48330 +#else
48331 + , mm->context.user_cs_base
48332 + , mm->context.user_cs_limit
48333 +#endif
48334 +#endif
48335 +
48336 + );
48337 }
48338
48339 unsigned long task_vsize(struct mm_struct *mm)
48340 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48341 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48342 }
48343
48344 - /* We don't show the stack guard page in /proc/maps */
48345 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48346 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48347 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48348 +#else
48349 start = vma->vm_start;
48350 - if (stack_guard_page_start(vma, start))
48351 - start += PAGE_SIZE;
48352 end = vma->vm_end;
48353 - if (stack_guard_page_end(vma, end))
48354 - end -= PAGE_SIZE;
48355 +#endif
48356
48357 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48358 start,
48359 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48360 flags & VM_WRITE ? 'w' : '-',
48361 flags & VM_EXEC ? 'x' : '-',
48362 flags & VM_MAYSHARE ? 's' : 'p',
48363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48364 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48365 +#else
48366 pgoff,
48367 +#endif
48368 MAJOR(dev), MINOR(dev), ino, &len);
48369
48370 /*
48371 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48372 */
48373 if (file) {
48374 pad_len_spaces(m, len);
48375 - seq_path(m, &file->f_path, "\n");
48376 + seq_path(m, &file->f_path, "\n\\");
48377 goto done;
48378 }
48379
48380 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48381 * Thread stack in /proc/PID/task/TID/maps or
48382 * the main process stack.
48383 */
48384 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
48385 - vma->vm_end >= mm->start_stack)) {
48386 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48387 + (vma->vm_start <= mm->start_stack &&
48388 + vma->vm_end >= mm->start_stack)) {
48389 name = "[stack]";
48390 } else {
48391 /* Thread stack in /proc/PID/maps */
48392 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48393 struct proc_maps_private *priv = m->private;
48394 struct task_struct *task = priv->task;
48395
48396 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48397 + if (current->exec_id != m->exec_id) {
48398 + gr_log_badprocpid("maps");
48399 + return 0;
48400 + }
48401 +#endif
48402 +
48403 show_map_vma(m, vma, is_pid);
48404
48405 if (m->count < m->size) /* vma is copied successfully */
48406 @@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48407 .private = &mss,
48408 };
48409
48410 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48411 + if (current->exec_id != m->exec_id) {
48412 + gr_log_badprocpid("smaps");
48413 + return 0;
48414 + }
48415 +#endif
48416 memset(&mss, 0, sizeof mss);
48417 - mss.vma = vma;
48418 - /* mmap_sem is held in m_start */
48419 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48420 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48421 -
48422 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48423 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48424 +#endif
48425 + mss.vma = vma;
48426 + /* mmap_sem is held in m_start */
48427 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48428 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48429 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48430 + }
48431 +#endif
48432 show_map_vma(m, vma, is_pid);
48433
48434 seq_printf(m,
48435 @@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48436 "KernelPageSize: %8lu kB\n"
48437 "MMUPageSize: %8lu kB\n"
48438 "Locked: %8lu kB\n",
48439 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48440 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48441 +#else
48442 (vma->vm_end - vma->vm_start) >> 10,
48443 +#endif
48444 mss.resident >> 10,
48445 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48446 mss.shared_clean >> 10,
48447 @@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48448 int n;
48449 char buffer[50];
48450
48451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48452 + if (current->exec_id != m->exec_id) {
48453 + gr_log_badprocpid("numa_maps");
48454 + return 0;
48455 + }
48456 +#endif
48457 +
48458 if (!mm)
48459 return 0;
48460
48461 @@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48462 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48463 mpol_cond_put(pol);
48464
48465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48466 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48467 +#else
48468 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48469 +#endif
48470
48471 if (file) {
48472 seq_printf(m, " file=");
48473 - seq_path(m, &file->f_path, "\n\t= ");
48474 + seq_path(m, &file->f_path, "\n\t\\= ");
48475 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48476 seq_printf(m, " heap");
48477 } else {
48478 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48479 index 74fe164..899e77b 100644
48480 --- a/fs/proc/task_nommu.c
48481 +++ b/fs/proc/task_nommu.c
48482 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48483 else
48484 bytes += kobjsize(mm);
48485
48486 - if (current->fs && current->fs->users > 1)
48487 + if (current->fs && atomic_read(&current->fs->users) > 1)
48488 sbytes += kobjsize(current->fs);
48489 else
48490 bytes += kobjsize(current->fs);
48491 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48492
48493 if (file) {
48494 pad_len_spaces(m, len);
48495 - seq_path(m, &file->f_path, "");
48496 + seq_path(m, &file->f_path, "\n\\");
48497 } else if (mm) {
48498 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48499
48500 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48501 index d67908b..d13f6a6 100644
48502 --- a/fs/quota/netlink.c
48503 +++ b/fs/quota/netlink.c
48504 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48505 void quota_send_warning(short type, unsigned int id, dev_t dev,
48506 const char warntype)
48507 {
48508 - static atomic_t seq;
48509 + static atomic_unchecked_t seq;
48510 struct sk_buff *skb;
48511 void *msg_head;
48512 int ret;
48513 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48514 "VFS: Not enough memory to send quota warning.\n");
48515 return;
48516 }
48517 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48518 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48519 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48520 if (!msg_head) {
48521 printk(KERN_ERR
48522 diff --git a/fs/readdir.c b/fs/readdir.c
48523 index cc0a822..43cb195 100644
48524 --- a/fs/readdir.c
48525 +++ b/fs/readdir.c
48526 @@ -17,6 +17,7 @@
48527 #include <linux/security.h>
48528 #include <linux/syscalls.h>
48529 #include <linux/unistd.h>
48530 +#include <linux/namei.h>
48531
48532 #include <asm/uaccess.h>
48533
48534 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48535
48536 struct readdir_callback {
48537 struct old_linux_dirent __user * dirent;
48538 + struct file * file;
48539 int result;
48540 };
48541
48542 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48543 buf->result = -EOVERFLOW;
48544 return -EOVERFLOW;
48545 }
48546 +
48547 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48548 + return 0;
48549 +
48550 buf->result++;
48551 dirent = buf->dirent;
48552 if (!access_ok(VERIFY_WRITE, dirent,
48553 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48554
48555 buf.result = 0;
48556 buf.dirent = dirent;
48557 + buf.file = file;
48558
48559 error = vfs_readdir(file, fillonedir, &buf);
48560 if (buf.result)
48561 @@ -142,6 +149,7 @@ struct linux_dirent {
48562 struct getdents_callback {
48563 struct linux_dirent __user * current_dir;
48564 struct linux_dirent __user * previous;
48565 + struct file * file;
48566 int count;
48567 int error;
48568 };
48569 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48570 buf->error = -EOVERFLOW;
48571 return -EOVERFLOW;
48572 }
48573 +
48574 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48575 + return 0;
48576 +
48577 dirent = buf->previous;
48578 if (dirent) {
48579 if (__put_user(offset, &dirent->d_off))
48580 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48581 buf.previous = NULL;
48582 buf.count = count;
48583 buf.error = 0;
48584 + buf.file = file;
48585
48586 error = vfs_readdir(file, filldir, &buf);
48587 if (error >= 0)
48588 @@ -229,6 +242,7 @@ out:
48589 struct getdents_callback64 {
48590 struct linux_dirent64 __user * current_dir;
48591 struct linux_dirent64 __user * previous;
48592 + struct file *file;
48593 int count;
48594 int error;
48595 };
48596 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48597 buf->error = -EINVAL; /* only used if we fail.. */
48598 if (reclen > buf->count)
48599 return -EINVAL;
48600 +
48601 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48602 + return 0;
48603 +
48604 dirent = buf->previous;
48605 if (dirent) {
48606 if (__put_user(offset, &dirent->d_off))
48607 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48608
48609 buf.current_dir = dirent;
48610 buf.previous = NULL;
48611 + buf.file = file;
48612 buf.count = count;
48613 buf.error = 0;
48614
48615 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48616 error = buf.error;
48617 lastdirent = buf.previous;
48618 if (lastdirent) {
48619 - typeof(lastdirent->d_off) d_off = file->f_pos;
48620 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48621 if (__put_user(d_off, &lastdirent->d_off))
48622 error = -EFAULT;
48623 else
48624 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48625 index 2b7882b..1c5ef48 100644
48626 --- a/fs/reiserfs/do_balan.c
48627 +++ b/fs/reiserfs/do_balan.c
48628 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48629 return;
48630 }
48631
48632 - atomic_inc(&(fs_generation(tb->tb_sb)));
48633 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48634 do_balance_starts(tb);
48635
48636 /* balance leaf returns 0 except if combining L R and S into
48637 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48638 index 2c1ade6..8c59d8d 100644
48639 --- a/fs/reiserfs/procfs.c
48640 +++ b/fs/reiserfs/procfs.c
48641 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48642 "SMALL_TAILS " : "NO_TAILS ",
48643 replay_only(sb) ? "REPLAY_ONLY " : "",
48644 convert_reiserfs(sb) ? "CONV " : "",
48645 - atomic_read(&r->s_generation_counter),
48646 + atomic_read_unchecked(&r->s_generation_counter),
48647 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48648 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48649 SF(s_good_search_by_key_reada), SF(s_bmaps),
48650 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
48651 index a59d271..e12d1cf 100644
48652 --- a/fs/reiserfs/reiserfs.h
48653 +++ b/fs/reiserfs/reiserfs.h
48654 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
48655 /* Comment? -Hans */
48656 wait_queue_head_t s_wait;
48657 /* To be obsoleted soon by per buffer seals.. -Hans */
48658 - atomic_t s_generation_counter; // increased by one every time the
48659 + atomic_unchecked_t s_generation_counter; // increased by one every time the
48660 // tree gets re-balanced
48661 unsigned long s_properties; /* File system properties. Currently holds
48662 on-disk FS format */
48663 @@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
48664 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
48665
48666 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
48667 -#define get_generation(s) atomic_read (&fs_generation(s))
48668 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
48669 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
48670 #define __fs_changed(gen,s) (gen != get_generation (s))
48671 #define fs_changed(gen,s) \
48672 diff --git a/fs/select.c b/fs/select.c
48673 index 17d33d0..da0bf5c 100644
48674 --- a/fs/select.c
48675 +++ b/fs/select.c
48676 @@ -20,6 +20,7 @@
48677 #include <linux/export.h>
48678 #include <linux/slab.h>
48679 #include <linux/poll.h>
48680 +#include <linux/security.h>
48681 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48682 #include <linux/file.h>
48683 #include <linux/fdtable.h>
48684 @@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48685 struct poll_list *walk = head;
48686 unsigned long todo = nfds;
48687
48688 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48689 if (nfds > rlimit(RLIMIT_NOFILE))
48690 return -EINVAL;
48691
48692 diff --git a/fs/seq_file.c b/fs/seq_file.c
48693 index 0cbd049..cab1127 100644
48694 --- a/fs/seq_file.c
48695 +++ b/fs/seq_file.c
48696 @@ -9,6 +9,7 @@
48697 #include <linux/export.h>
48698 #include <linux/seq_file.h>
48699 #include <linux/slab.h>
48700 +#include <linux/sched.h>
48701
48702 #include <asm/uaccess.h>
48703 #include <asm/page.h>
48704 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48705 memset(p, 0, sizeof(*p));
48706 mutex_init(&p->lock);
48707 p->op = op;
48708 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48709 + p->exec_id = current->exec_id;
48710 +#endif
48711
48712 /*
48713 * Wrappers around seq_open(e.g. swaps_open) need to be
48714 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
48715 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48716 void *data)
48717 {
48718 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48719 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48720 int res = -ENOMEM;
48721
48722 if (op) {
48723 diff --git a/fs/splice.c b/fs/splice.c
48724 index 5cac690..f833a99 100644
48725 --- a/fs/splice.c
48726 +++ b/fs/splice.c
48727 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48728 pipe_lock(pipe);
48729
48730 for (;;) {
48731 - if (!pipe->readers) {
48732 + if (!atomic_read(&pipe->readers)) {
48733 send_sig(SIGPIPE, current, 0);
48734 if (!ret)
48735 ret = -EPIPE;
48736 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48737 do_wakeup = 0;
48738 }
48739
48740 - pipe->waiting_writers++;
48741 + atomic_inc(&pipe->waiting_writers);
48742 pipe_wait(pipe);
48743 - pipe->waiting_writers--;
48744 + atomic_dec(&pipe->waiting_writers);
48745 }
48746
48747 pipe_unlock(pipe);
48748 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48749 old_fs = get_fs();
48750 set_fs(get_ds());
48751 /* The cast to a user pointer is valid due to the set_fs() */
48752 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48753 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48754 set_fs(old_fs);
48755
48756 return res;
48757 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48758 old_fs = get_fs();
48759 set_fs(get_ds());
48760 /* The cast to a user pointer is valid due to the set_fs() */
48761 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48762 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48763 set_fs(old_fs);
48764
48765 return res;
48766 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48767 goto err;
48768
48769 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48770 - vec[i].iov_base = (void __user *) page_address(page);
48771 + vec[i].iov_base = (void __force_user *) page_address(page);
48772 vec[i].iov_len = this_len;
48773 spd.pages[i] = page;
48774 spd.nr_pages++;
48775 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48776 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48777 {
48778 while (!pipe->nrbufs) {
48779 - if (!pipe->writers)
48780 + if (!atomic_read(&pipe->writers))
48781 return 0;
48782
48783 - if (!pipe->waiting_writers && sd->num_spliced)
48784 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48785 return 0;
48786
48787 if (sd->flags & SPLICE_F_NONBLOCK)
48788 @@ -1185,7 +1185,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48789 * out of the pipe right after the splice_to_pipe(). So set
48790 * PIPE_READERS appropriately.
48791 */
48792 - pipe->readers = 1;
48793 + atomic_set(&pipe->readers, 1);
48794
48795 current->splice_pipe = pipe;
48796 }
48797 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48798 ret = -ERESTARTSYS;
48799 break;
48800 }
48801 - if (!pipe->writers)
48802 + if (!atomic_read(&pipe->writers))
48803 break;
48804 - if (!pipe->waiting_writers) {
48805 + if (!atomic_read(&pipe->waiting_writers)) {
48806 if (flags & SPLICE_F_NONBLOCK) {
48807 ret = -EAGAIN;
48808 break;
48809 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48810 pipe_lock(pipe);
48811
48812 while (pipe->nrbufs >= pipe->buffers) {
48813 - if (!pipe->readers) {
48814 + if (!atomic_read(&pipe->readers)) {
48815 send_sig(SIGPIPE, current, 0);
48816 ret = -EPIPE;
48817 break;
48818 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48819 ret = -ERESTARTSYS;
48820 break;
48821 }
48822 - pipe->waiting_writers++;
48823 + atomic_inc(&pipe->waiting_writers);
48824 pipe_wait(pipe);
48825 - pipe->waiting_writers--;
48826 + atomic_dec(&pipe->waiting_writers);
48827 }
48828
48829 pipe_unlock(pipe);
48830 @@ -1823,14 +1823,14 @@ retry:
48831 pipe_double_lock(ipipe, opipe);
48832
48833 do {
48834 - if (!opipe->readers) {
48835 + if (!atomic_read(&opipe->readers)) {
48836 send_sig(SIGPIPE, current, 0);
48837 if (!ret)
48838 ret = -EPIPE;
48839 break;
48840 }
48841
48842 - if (!ipipe->nrbufs && !ipipe->writers)
48843 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48844 break;
48845
48846 /*
48847 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48848 pipe_double_lock(ipipe, opipe);
48849
48850 do {
48851 - if (!opipe->readers) {
48852 + if (!atomic_read(&opipe->readers)) {
48853 send_sig(SIGPIPE, current, 0);
48854 if (!ret)
48855 ret = -EPIPE;
48856 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48857 * return EAGAIN if we have the potential of some data in the
48858 * future, otherwise just return 0
48859 */
48860 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48861 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48862 ret = -EAGAIN;
48863
48864 pipe_unlock(ipipe);
48865 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48866 index 35a36d3..23424b2 100644
48867 --- a/fs/sysfs/dir.c
48868 +++ b/fs/sysfs/dir.c
48869 @@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48870 struct sysfs_dirent *sd;
48871 int rc;
48872
48873 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48874 + const char *parent_name = parent_sd->s_name;
48875 +
48876 + mode = S_IFDIR | S_IRWXU;
48877 +
48878 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48879 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48880 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48881 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48882 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48883 +#endif
48884 +
48885 /* allocate */
48886 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48887 if (!sd)
48888 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48889 index 00012e3..8392349 100644
48890 --- a/fs/sysfs/file.c
48891 +++ b/fs/sysfs/file.c
48892 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48893
48894 struct sysfs_open_dirent {
48895 atomic_t refcnt;
48896 - atomic_t event;
48897 + atomic_unchecked_t event;
48898 wait_queue_head_t poll;
48899 struct list_head buffers; /* goes through sysfs_buffer.list */
48900 };
48901 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48902 if (!sysfs_get_active(attr_sd))
48903 return -ENODEV;
48904
48905 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48906 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48907 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48908
48909 sysfs_put_active(attr_sd);
48910 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48911 return -ENOMEM;
48912
48913 atomic_set(&new_od->refcnt, 0);
48914 - atomic_set(&new_od->event, 1);
48915 + atomic_set_unchecked(&new_od->event, 1);
48916 init_waitqueue_head(&new_od->poll);
48917 INIT_LIST_HEAD(&new_od->buffers);
48918 goto retry;
48919 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48920
48921 sysfs_put_active(attr_sd);
48922
48923 - if (buffer->event != atomic_read(&od->event))
48924 + if (buffer->event != atomic_read_unchecked(&od->event))
48925 goto trigger;
48926
48927 return DEFAULT_POLLMASK;
48928 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48929
48930 od = sd->s_attr.open;
48931 if (od) {
48932 - atomic_inc(&od->event);
48933 + atomic_inc_unchecked(&od->event);
48934 wake_up_interruptible(&od->poll);
48935 }
48936
48937 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48938 index a7ac78f..02158e1 100644
48939 --- a/fs/sysfs/symlink.c
48940 +++ b/fs/sysfs/symlink.c
48941 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48942
48943 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48944 {
48945 - char *page = nd_get_link(nd);
48946 + const char *page = nd_get_link(nd);
48947 if (!IS_ERR(page))
48948 free_page((unsigned long)page);
48949 }
48950 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48951 index c175b4d..8f36a16 100644
48952 --- a/fs/udf/misc.c
48953 +++ b/fs/udf/misc.c
48954 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48955
48956 u8 udf_tag_checksum(const struct tag *t)
48957 {
48958 - u8 *data = (u8 *)t;
48959 + const u8 *data = (const u8 *)t;
48960 u8 checksum = 0;
48961 int i;
48962 for (i = 0; i < sizeof(struct tag); ++i)
48963 diff --git a/fs/utimes.c b/fs/utimes.c
48964 index ba653f3..06ea4b1 100644
48965 --- a/fs/utimes.c
48966 +++ b/fs/utimes.c
48967 @@ -1,6 +1,7 @@
48968 #include <linux/compiler.h>
48969 #include <linux/file.h>
48970 #include <linux/fs.h>
48971 +#include <linux/security.h>
48972 #include <linux/linkage.h>
48973 #include <linux/mount.h>
48974 #include <linux/namei.h>
48975 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48976 goto mnt_drop_write_and_out;
48977 }
48978 }
48979 +
48980 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48981 + error = -EACCES;
48982 + goto mnt_drop_write_and_out;
48983 + }
48984 +
48985 mutex_lock(&inode->i_mutex);
48986 error = notify_change(path->dentry, &newattrs);
48987 mutex_unlock(&inode->i_mutex);
48988 diff --git a/fs/xattr.c b/fs/xattr.c
48989 index 3c8c1cc..a83c398 100644
48990 --- a/fs/xattr.c
48991 +++ b/fs/xattr.c
48992 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48993 * Extended attribute SET operations
48994 */
48995 static long
48996 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
48997 +setxattr(struct path *path, const char __user *name, const void __user *value,
48998 size_t size, int flags)
48999 {
49000 int error;
49001 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49002 }
49003 }
49004
49005 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49006 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49007 + error = -EACCES;
49008 + goto out;
49009 + }
49010 +
49011 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49012 out:
49013 if (vvalue)
49014 vfree(vvalue);
49015 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49016 return error;
49017 error = mnt_want_write(path.mnt);
49018 if (!error) {
49019 - error = setxattr(path.dentry, name, value, size, flags);
49020 + error = setxattr(&path, name, value, size, flags);
49021 mnt_drop_write(path.mnt);
49022 }
49023 path_put(&path);
49024 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49025 return error;
49026 error = mnt_want_write(path.mnt);
49027 if (!error) {
49028 - error = setxattr(path.dentry, name, value, size, flags);
49029 + error = setxattr(&path, name, value, size, flags);
49030 mnt_drop_write(path.mnt);
49031 }
49032 path_put(&path);
49033 @@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49034 const void __user *,value, size_t, size, int, flags)
49035 {
49036 struct file *f;
49037 - struct dentry *dentry;
49038 int error = -EBADF;
49039
49040 f = fget(fd);
49041 if (!f)
49042 return error;
49043 - dentry = f->f_path.dentry;
49044 - audit_inode(NULL, dentry);
49045 + audit_inode(NULL, f->f_path.dentry);
49046 error = mnt_want_write_file(f);
49047 if (!error) {
49048 - error = setxattr(dentry, name, value, size, flags);
49049 + error = setxattr(&f->f_path, name, value, size, flags);
49050 mnt_drop_write_file(f);
49051 }
49052 fput(f);
49053 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49054 index 69d06b0..c0996e5 100644
49055 --- a/fs/xattr_acl.c
49056 +++ b/fs/xattr_acl.c
49057 @@ -17,8 +17,8 @@
49058 struct posix_acl *
49059 posix_acl_from_xattr(const void *value, size_t size)
49060 {
49061 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49062 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49063 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49064 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49065 int count;
49066 struct posix_acl *acl;
49067 struct posix_acl_entry *acl_e;
49068 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49069 index 85e7e32..5344e52 100644
49070 --- a/fs/xfs/xfs_bmap.c
49071 +++ b/fs/xfs/xfs_bmap.c
49072 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49073 int nmap,
49074 int ret_nmap);
49075 #else
49076 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49077 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49078 #endif /* DEBUG */
49079
49080 STATIC int
49081 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49082 index 79d05e8..e3e5861 100644
49083 --- a/fs/xfs/xfs_dir2_sf.c
49084 +++ b/fs/xfs/xfs_dir2_sf.c
49085 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49086 }
49087
49088 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49089 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49090 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49091 + char name[sfep->namelen];
49092 + memcpy(name, sfep->name, sfep->namelen);
49093 + if (filldir(dirent, name, sfep->namelen,
49094 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49095 + *offset = off & 0x7fffffff;
49096 + return 0;
49097 + }
49098 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49099 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49100 *offset = off & 0x7fffffff;
49101 return 0;
49102 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49103 index 91f8ff5..0ce68f9 100644
49104 --- a/fs/xfs/xfs_ioctl.c
49105 +++ b/fs/xfs/xfs_ioctl.c
49106 @@ -128,7 +128,7 @@ xfs_find_handle(
49107 }
49108
49109 error = -EFAULT;
49110 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49111 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49112 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49113 goto out_put;
49114
49115 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49116 index 3011b87..1ab03e9 100644
49117 --- a/fs/xfs/xfs_iops.c
49118 +++ b/fs/xfs/xfs_iops.c
49119 @@ -397,7 +397,7 @@ xfs_vn_put_link(
49120 struct nameidata *nd,
49121 void *p)
49122 {
49123 - char *s = nd_get_link(nd);
49124 + const char *s = nd_get_link(nd);
49125
49126 if (!IS_ERR(s))
49127 kfree(s);
49128 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49129 new file mode 100644
49130 index 0000000..b9e7d6f
49131 --- /dev/null
49132 +++ b/grsecurity/Kconfig
49133 @@ -0,0 +1,940 @@
49134 +#
49135 +# grecurity configuration
49136 +#
49137 +menu "Memory Protections"
49138 +depends on GRKERNSEC
49139 +
49140 +config GRKERNSEC_KMEM
49141 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49142 + default y if GRKERNSEC_CONFIG_AUTO
49143 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49144 + help
49145 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49146 + be written to or read from to modify or leak the contents of the running
49147 + kernel. /dev/port will also not be allowed to be opened. If you have module
49148 + support disabled, enabling this will close up four ways that are
49149 + currently used to insert malicious code into the running kernel.
49150 + Even with all these features enabled, we still highly recommend that
49151 + you use the RBAC system, as it is still possible for an attacker to
49152 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49153 + If you are not using XFree86, you may be able to stop this additional
49154 + case by enabling the 'Disable privileged I/O' option. Though nothing
49155 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49156 + but only to video memory, which is the only writing we allow in this
49157 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49158 + not be allowed to mprotect it with PROT_WRITE later.
49159 + It is highly recommended that you say Y here if you meet all the
49160 + conditions above.
49161 +
49162 +config GRKERNSEC_VM86
49163 + bool "Restrict VM86 mode"
49164 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49165 + depends on X86_32
49166 +
49167 + help
49168 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49169 + make use of a special execution mode on 32bit x86 processors called
49170 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49171 + video cards and will still work with this option enabled. The purpose
49172 + of the option is to prevent exploitation of emulation errors in
49173 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49174 + Nearly all users should be able to enable this option.
49175 +
49176 +config GRKERNSEC_IO
49177 + bool "Disable privileged I/O"
49178 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49179 + depends on X86
49180 + select RTC_CLASS
49181 + select RTC_INTF_DEV
49182 + select RTC_DRV_CMOS
49183 +
49184 + help
49185 + If you say Y here, all ioperm and iopl calls will return an error.
49186 + Ioperm and iopl can be used to modify the running kernel.
49187 + Unfortunately, some programs need this access to operate properly,
49188 + the most notable of which are XFree86 and hwclock. hwclock can be
49189 + remedied by having RTC support in the kernel, so real-time
49190 + clock support is enabled if this option is enabled, to ensure
49191 + that hwclock operates correctly. XFree86 still will not
49192 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49193 + IF YOU USE XFree86. If you use XFree86 and you still want to
49194 + protect your kernel against modification, use the RBAC system.
49195 +
49196 +config GRKERNSEC_PROC_MEMMAP
49197 + bool "Harden ASLR against information leaks and entropy reduction"
49198 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
49199 + depends on PAX_NOEXEC || PAX_ASLR
49200 + help
49201 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49202 + give no information about the addresses of its mappings if
49203 + PaX features that rely on random addresses are enabled on the task.
49204 + In addition to sanitizing this information and disabling other
49205 + dangerous sources of information, this option causes reads of sensitive
49206 + /proc/<pid> entries where the file descriptor was opened in a different
49207 + task than the one performing the read. Such attempts are logged.
49208 + This option also limits argv/env strings for suid/sgid binaries
49209 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49210 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49211 + binaries to prevent alternative mmap layouts from being abused.
49212 +
49213 + If you use PaX it is essential that you say Y here as it closes up
49214 + several holes that make full ASLR useless locally.
49215 +
49216 +config GRKERNSEC_BRUTE
49217 + bool "Deter exploit bruteforcing"
49218 + default y if GRKERNSEC_CONFIG_AUTO
49219 + help
49220 + If you say Y here, attempts to bruteforce exploits against forking
49221 + daemons such as apache or sshd, as well as against suid/sgid binaries
49222 + will be deterred. When a child of a forking daemon is killed by PaX
49223 + or crashes due to an illegal instruction or other suspicious signal,
49224 + the parent process will be delayed 30 seconds upon every subsequent
49225 + fork until the administrator is able to assess the situation and
49226 + restart the daemon.
49227 + In the suid/sgid case, the attempt is logged, the user has all their
49228 + processes terminated, and they are prevented from executing any further
49229 + processes for 15 minutes.
49230 + It is recommended that you also enable signal logging in the auditing
49231 + section so that logs are generated when a process triggers a suspicious
49232 + signal.
49233 + If the sysctl option is enabled, a sysctl option with name
49234 + "deter_bruteforce" is created.
49235 +
49236 +
49237 +config GRKERNSEC_MODHARDEN
49238 + bool "Harden module auto-loading"
49239 + default y if GRKERNSEC_CONFIG_AUTO
49240 + depends on MODULES
49241 + help
49242 + If you say Y here, module auto-loading in response to use of some
49243 + feature implemented by an unloaded module will be restricted to
49244 + root users. Enabling this option helps defend against attacks
49245 + by unprivileged users who abuse the auto-loading behavior to
49246 + cause a vulnerable module to load that is then exploited.
49247 +
49248 + If this option prevents a legitimate use of auto-loading for a
49249 + non-root user, the administrator can execute modprobe manually
49250 + with the exact name of the module mentioned in the alert log.
49251 + Alternatively, the administrator can add the module to the list
49252 + of modules loaded at boot by modifying init scripts.
49253 +
49254 + Modification of init scripts will most likely be needed on
49255 + Ubuntu servers with encrypted home directory support enabled,
49256 + as the first non-root user logging in will cause the ecb(aes),
49257 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49258 +
49259 +config GRKERNSEC_HIDESYM
49260 + bool "Hide kernel symbols"
49261 + default y if GRKERNSEC_CONFIG_AUTO
49262 + help
49263 + If you say Y here, getting information on loaded modules, and
49264 + displaying all kernel symbols through a syscall will be restricted
49265 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49266 + /proc/kallsyms will be restricted to the root user. The RBAC
49267 + system can hide that entry even from root.
49268 +
49269 + This option also prevents leaking of kernel addresses through
49270 + several /proc entries.
49271 +
49272 + Note that this option is only effective provided the following
49273 + conditions are met:
49274 + 1) The kernel using grsecurity is not precompiled by some distribution
49275 + 2) You have also enabled GRKERNSEC_DMESG
49276 + 3) You are using the RBAC system and hiding other files such as your
49277 + kernel image and System.map. Alternatively, enabling this option
49278 + causes the permissions on /boot, /lib/modules, and the kernel
49279 + source directory to change at compile time to prevent
49280 + reading by non-root users.
49281 + If the above conditions are met, this option will aid in providing a
49282 + useful protection against local kernel exploitation of overflows
49283 + and arbitrary read/write vulnerabilities.
49284 +
49285 +config GRKERNSEC_KERN_LOCKOUT
49286 + bool "Active kernel exploit response"
49287 + default y if GRKERNSEC_CONFIG_AUTO
49288 + depends on X86 || ARM || PPC || SPARC
49289 + help
49290 + If you say Y here, when a PaX alert is triggered due to suspicious
49291 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49292 + or an OOPS occurs due to bad memory accesses, instead of just
49293 + terminating the offending process (and potentially allowing
49294 + a subsequent exploit from the same user), we will take one of two
49295 + actions:
49296 + If the user was root, we will panic the system
49297 + If the user was non-root, we will log the attempt, terminate
49298 + all processes owned by the user, then prevent them from creating
49299 + any new processes until the system is restarted
49300 + This deters repeated kernel exploitation/bruteforcing attempts
49301 + and is useful for later forensics.
49302 +
49303 +endmenu
49304 +menu "Role Based Access Control Options"
49305 +depends on GRKERNSEC
49306 +
49307 +config GRKERNSEC_RBAC_DEBUG
49308 + bool
49309 +
49310 +config GRKERNSEC_NO_RBAC
49311 + bool "Disable RBAC system"
49312 + help
49313 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49314 + preventing the RBAC system from being enabled. You should only say Y
49315 + here if you have no intention of using the RBAC system, so as to prevent
49316 + an attacker with root access from misusing the RBAC system to hide files
49317 + and processes when loadable module support and /dev/[k]mem have been
49318 + locked down.
49319 +
49320 +config GRKERNSEC_ACL_HIDEKERN
49321 + bool "Hide kernel processes"
49322 + help
49323 + If you say Y here, all kernel threads will be hidden to all
49324 + processes but those whose subject has the "view hidden processes"
49325 + flag.
49326 +
49327 +config GRKERNSEC_ACL_MAXTRIES
49328 + int "Maximum tries before password lockout"
49329 + default 3
49330 + help
49331 + This option enforces the maximum number of times a user can attempt
49332 + to authorize themselves with the grsecurity RBAC system before being
49333 + denied the ability to attempt authorization again for a specified time.
49334 + The lower the number, the harder it will be to brute-force a password.
49335 +
49336 +config GRKERNSEC_ACL_TIMEOUT
49337 + int "Time to wait after max password tries, in seconds"
49338 + default 30
49339 + help
49340 + This option specifies the time the user must wait after attempting to
49341 + authorize to the RBAC system with the maximum number of invalid
49342 + passwords. The higher the number, the harder it will be to brute-force
49343 + a password.
49344 +
49345 +endmenu
49346 +menu "Filesystem Protections"
49347 +depends on GRKERNSEC
49348 +
49349 +config GRKERNSEC_PROC
49350 + bool "Proc restrictions"
49351 + default y if GRKERNSEC_CONFIG_AUTO
49352 + help
49353 + If you say Y here, the permissions of the /proc filesystem
49354 + will be altered to enhance system security and privacy. You MUST
49355 + choose either a user only restriction or a user and group restriction.
49356 + Depending upon the option you choose, you can either restrict users to
49357 + see only the processes they themselves run, or choose a group that can
49358 + view all processes and files normally restricted to root if you choose
49359 + the "restrict to user only" option. NOTE: If you're running identd or
49360 + ntpd as a non-root user, you will have to run it as the group you
49361 + specify here.
49362 +
49363 +config GRKERNSEC_PROC_USER
49364 + bool "Restrict /proc to user only"
49365 + depends on GRKERNSEC_PROC
49366 + help
49367 + If you say Y here, non-root users will only be able to view their own
49368 + processes, and restricts them from viewing network-related information,
49369 + and viewing kernel symbol and module information.
49370 +
49371 +config GRKERNSEC_PROC_USERGROUP
49372 + bool "Allow special group"
49373 + default y if GRKERNSEC_CONFIG_AUTO
49374 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49375 + help
49376 + If you say Y here, you will be able to select a group that will be
49377 + able to view all processes and network-related information. If you've
49378 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49379 + remain hidden. This option is useful if you want to run identd as
49380 + a non-root user.
49381 +
49382 +config GRKERNSEC_PROC_GID
49383 + int "GID for special group"
49384 + depends on GRKERNSEC_PROC_USERGROUP
49385 + default 1001
49386 +
49387 +config GRKERNSEC_PROC_ADD
49388 + bool "Additional restrictions"
49389 + default y if GRKERNSEC_CONFIG_AUTO
49390 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49391 + help
49392 + If you say Y here, additional restrictions will be placed on
49393 + /proc that keep normal users from viewing device information and
49394 + slabinfo information that could be useful for exploits.
49395 +
49396 +config GRKERNSEC_LINK
49397 + bool "Linking restrictions"
49398 + default y if GRKERNSEC_CONFIG_AUTO
49399 + help
49400 + If you say Y here, /tmp race exploits will be prevented, since users
49401 + will no longer be able to follow symlinks owned by other users in
49402 + world-writable +t directories (e.g. /tmp), unless the owner of the
49403 + symlink is the owner of the directory. users will also not be
49404 + able to hardlink to files they do not own. If the sysctl option is
49405 + enabled, a sysctl option with name "linking_restrictions" is created.
49406 +
49407 +config GRKERNSEC_SYMLINKOWN
49408 + bool "Kernel-enforced SymlinksIfOwnerMatch"
49409 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49410 + help
49411 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
49412 + that prevents it from being used as a security feature. As Apache
49413 + verifies the symlink by performing a stat() against the target of
49414 + the symlink before it is followed, an attacker can setup a symlink
49415 + to point to a same-owned file, then replace the symlink with one
49416 + that targets another user's file just after Apache "validates" the
49417 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
49418 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
49419 + will be in place for the group you specify. If the sysctl option
49420 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
49421 + created.
49422 +
49423 +config GRKERNSEC_SYMLINKOWN_GID
49424 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
49425 + depends on GRKERNSEC_SYMLINKOWN
49426 + default 1006
49427 + help
49428 + Setting this GID determines what group kernel-enforced
49429 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
49430 + is enabled, a sysctl option with name "symlinkown_gid" is created.
49431 +
49432 +config GRKERNSEC_FIFO
49433 + bool "FIFO restrictions"
49434 + default y if GRKERNSEC_CONFIG_AUTO
49435 + help
49436 + If you say Y here, users will not be able to write to FIFOs they don't
49437 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49438 + the FIFO is the same owner of the directory it's held in. If the sysctl
49439 + option is enabled, a sysctl option with name "fifo_restrictions" is
49440 + created.
49441 +
49442 +config GRKERNSEC_SYSFS_RESTRICT
49443 + bool "Sysfs/debugfs restriction"
49444 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49445 + depends on SYSFS
49446 + help
49447 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49448 + any filesystem normally mounted under it (e.g. debugfs) will be
49449 + mostly accessible only by root. These filesystems generally provide access
49450 + to hardware and debug information that isn't appropriate for unprivileged
49451 + users of the system. Sysfs and debugfs have also become a large source
49452 + of new vulnerabilities, ranging from infoleaks to local compromise.
49453 + There has been very little oversight with an eye toward security involved
49454 + in adding new exporters of information to these filesystems, so their
49455 + use is discouraged.
49456 + For reasons of compatibility, a few directories have been whitelisted
49457 + for access by non-root users:
49458 + /sys/fs/selinux
49459 + /sys/fs/fuse
49460 + /sys/devices/system/cpu
49461 +
49462 +config GRKERNSEC_ROFS
49463 + bool "Runtime read-only mount protection"
49464 + help
49465 + If you say Y here, a sysctl option with name "romount_protect" will
49466 + be created. By setting this option to 1 at runtime, filesystems
49467 + will be protected in the following ways:
49468 + * No new writable mounts will be allowed
49469 + * Existing read-only mounts won't be able to be remounted read/write
49470 + * Write operations will be denied on all block devices
49471 + This option acts independently of grsec_lock: once it is set to 1,
49472 + it cannot be turned off. Therefore, please be mindful of the resulting
49473 + behavior if this option is enabled in an init script on a read-only
49474 + filesystem. This feature is mainly intended for secure embedded systems.
49475 +
49476 +config GRKERNSEC_CHROOT
49477 + bool "Chroot jail restrictions"
49478 + default y if GRKERNSEC_CONFIG_AUTO
49479 + help
49480 + If you say Y here, you will be able to choose several options that will
49481 + make breaking out of a chrooted jail much more difficult. If you
49482 + encounter no software incompatibilities with the following options, it
49483 + is recommended that you enable each one.
49484 +
49485 +config GRKERNSEC_CHROOT_MOUNT
49486 + bool "Deny mounts"
49487 + default y if GRKERNSEC_CONFIG_AUTO
49488 + depends on GRKERNSEC_CHROOT
49489 + help
49490 + If you say Y here, processes inside a chroot will not be able to
49491 + mount or remount filesystems. If the sysctl option is enabled, a
49492 + sysctl option with name "chroot_deny_mount" is created.
49493 +
49494 +config GRKERNSEC_CHROOT_DOUBLE
49495 + bool "Deny double-chroots"
49496 + default y if GRKERNSEC_CONFIG_AUTO
49497 + depends on GRKERNSEC_CHROOT
49498 + help
49499 + If you say Y here, processes inside a chroot will not be able to chroot
49500 + again outside the chroot. This is a widely used method of breaking
49501 + out of a chroot jail and should not be allowed. If the sysctl
49502 + option is enabled, a sysctl option with name
49503 + "chroot_deny_chroot" is created.
49504 +
49505 +config GRKERNSEC_CHROOT_PIVOT
49506 + bool "Deny pivot_root in chroot"
49507 + default y if GRKERNSEC_CONFIG_AUTO
49508 + depends on GRKERNSEC_CHROOT
49509 + help
49510 + If you say Y here, processes inside a chroot will not be able to use
49511 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49512 + works similar to chroot in that it changes the root filesystem. This
49513 + function could be misused in a chrooted process to attempt to break out
49514 + of the chroot, and therefore should not be allowed. If the sysctl
49515 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49516 + created.
49517 +
49518 +config GRKERNSEC_CHROOT_CHDIR
49519 + bool "Enforce chdir(\"/\") on all chroots"
49520 + default y if GRKERNSEC_CONFIG_AUTO
49521 + depends on GRKERNSEC_CHROOT
49522 + help
49523 + If you say Y here, the current working directory of all newly-chrooted
49524 + applications will be set to the the root directory of the chroot.
49525 + The man page on chroot(2) states:
49526 + Note that this call does not change the current working
49527 + directory, so that `.' can be outside the tree rooted at
49528 + `/'. In particular, the super-user can escape from a
49529 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49530 +
49531 + It is recommended that you say Y here, since it's not known to break
49532 + any software. If the sysctl option is enabled, a sysctl option with
49533 + name "chroot_enforce_chdir" is created.
49534 +
49535 +config GRKERNSEC_CHROOT_CHMOD
49536 + bool "Deny (f)chmod +s"
49537 + default y if GRKERNSEC_CONFIG_AUTO
49538 + depends on GRKERNSEC_CHROOT
49539 + help
49540 + If you say Y here, processes inside a chroot will not be able to chmod
49541 + or fchmod files to make them have suid or sgid bits. This protects
49542 + against another published method of breaking a chroot. If the sysctl
49543 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
49544 + created.
49545 +
49546 +config GRKERNSEC_CHROOT_FCHDIR
49547 + bool "Deny fchdir out of chroot"
49548 + default y if GRKERNSEC_CONFIG_AUTO
49549 + depends on GRKERNSEC_CHROOT
49550 + help
49551 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
49552 + to a file descriptor of the chrooting process that points to a directory
49553 + outside the filesystem will be stopped. If the sysctl option
49554 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49555 +
49556 +config GRKERNSEC_CHROOT_MKNOD
49557 + bool "Deny mknod"
49558 + default y if GRKERNSEC_CONFIG_AUTO
49559 + depends on GRKERNSEC_CHROOT
49560 + help
49561 + If you say Y here, processes inside a chroot will not be allowed to
49562 + mknod. The problem with using mknod inside a chroot is that it
49563 + would allow an attacker to create a device entry that is the same
49564 + as one on the physical root of your system, which could range from
49565 + anything from the console device to a device for your harddrive (which
49566 + they could then use to wipe the drive or steal data). It is recommended
49567 + that you say Y here, unless you run into software incompatibilities.
49568 + If the sysctl option is enabled, a sysctl option with name
49569 + "chroot_deny_mknod" is created.
49570 +
49571 +config GRKERNSEC_CHROOT_SHMAT
49572 + bool "Deny shmat() out of chroot"
49573 + default y if GRKERNSEC_CONFIG_AUTO
49574 + depends on GRKERNSEC_CHROOT
49575 + help
49576 + If you say Y here, processes inside a chroot will not be able to attach
49577 + to shared memory segments that were created outside of the chroot jail.
49578 + It is recommended that you say Y here. If the sysctl option is enabled,
49579 + a sysctl option with name "chroot_deny_shmat" is created.
49580 +
49581 +config GRKERNSEC_CHROOT_UNIX
49582 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49583 + default y if GRKERNSEC_CONFIG_AUTO
49584 + depends on GRKERNSEC_CHROOT
49585 + help
49586 + If you say Y here, processes inside a chroot will not be able to
49587 + connect to abstract (meaning not belonging to a filesystem) Unix
49588 + domain sockets that were bound outside of a chroot. It is recommended
49589 + that you say Y here. If the sysctl option is enabled, a sysctl option
49590 + with name "chroot_deny_unix" is created.
49591 +
49592 +config GRKERNSEC_CHROOT_FINDTASK
49593 + bool "Protect outside processes"
49594 + default y if GRKERNSEC_CONFIG_AUTO
49595 + depends on GRKERNSEC_CHROOT
49596 + help
49597 + If you say Y here, processes inside a chroot will not be able to
49598 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49599 + getsid, or view any process outside of the chroot. If the sysctl
49600 + option is enabled, a sysctl option with name "chroot_findtask" is
49601 + created.
49602 +
49603 +config GRKERNSEC_CHROOT_NICE
49604 + bool "Restrict priority changes"
49605 + default y if GRKERNSEC_CONFIG_AUTO
49606 + depends on GRKERNSEC_CHROOT
49607 + help
49608 + If you say Y here, processes inside a chroot will not be able to raise
49609 + the priority of processes in the chroot, or alter the priority of
49610 + processes outside the chroot. This provides more security than simply
49611 + removing CAP_SYS_NICE from the process' capability set. If the
49612 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49613 + is created.
49614 +
49615 +config GRKERNSEC_CHROOT_SYSCTL
49616 + bool "Deny sysctl writes"
49617 + default y if GRKERNSEC_CONFIG_AUTO
49618 + depends on GRKERNSEC_CHROOT
49619 + help
49620 + If you say Y here, an attacker in a chroot will not be able to
49621 + write to sysctl entries, either by sysctl(2) or through a /proc
49622 + interface. It is strongly recommended that you say Y here. If the
49623 + sysctl option is enabled, a sysctl option with name
49624 + "chroot_deny_sysctl" is created.
49625 +
49626 +config GRKERNSEC_CHROOT_CAPS
49627 + bool "Capability restrictions"
49628 + default y if GRKERNSEC_CONFIG_AUTO
49629 + depends on GRKERNSEC_CHROOT
49630 + help
49631 + If you say Y here, the capabilities on all processes within a
49632 + chroot jail will be lowered to stop module insertion, raw i/o,
49633 + system and net admin tasks, rebooting the system, modifying immutable
49634 + files, modifying IPC owned by another, and changing the system time.
49635 + This is left an option because it can break some apps. Disable this
49636 + if your chrooted apps are having problems performing those kinds of
49637 + tasks. If the sysctl option is enabled, a sysctl option with
49638 + name "chroot_caps" is created.
49639 +
49640 +endmenu
49641 +menu "Kernel Auditing"
49642 +depends on GRKERNSEC
49643 +
49644 +config GRKERNSEC_AUDIT_GROUP
49645 + bool "Single group for auditing"
49646 + help
49647 + If you say Y here, the exec, chdir, and (un)mount logging features
49648 + will only operate on a group you specify. This option is recommended
49649 + if you only want to watch certain users instead of having a large
49650 + amount of logs from the entire system. If the sysctl option is enabled,
49651 + a sysctl option with name "audit_group" is created.
49652 +
49653 +config GRKERNSEC_AUDIT_GID
49654 + int "GID for auditing"
49655 + depends on GRKERNSEC_AUDIT_GROUP
49656 + default 1007
49657 +
49658 +config GRKERNSEC_EXECLOG
49659 + bool "Exec logging"
49660 + help
49661 + If you say Y here, all execve() calls will be logged (since the
49662 + other exec*() calls are frontends to execve(), all execution
49663 + will be logged). Useful for shell-servers that like to keep track
49664 + of their users. If the sysctl option is enabled, a sysctl option with
49665 + name "exec_logging" is created.
49666 + WARNING: This option when enabled will produce a LOT of logs, especially
49667 + on an active system.
49668 +
49669 +config GRKERNSEC_RESLOG
49670 + bool "Resource logging"
49671 + default y if GRKERNSEC_CONFIG_AUTO
49672 + help
49673 + If you say Y here, all attempts to overstep resource limits will
49674 + be logged with the resource name, the requested size, and the current
49675 + limit. It is highly recommended that you say Y here. If the sysctl
49676 + option is enabled, a sysctl option with name "resource_logging" is
49677 + created. If the RBAC system is enabled, the sysctl value is ignored.
49678 +
49679 +config GRKERNSEC_CHROOT_EXECLOG
49680 + bool "Log execs within chroot"
49681 + help
49682 + If you say Y here, all executions inside a chroot jail will be logged
49683 + to syslog. This can cause a large amount of logs if certain
49684 + applications (eg. djb's daemontools) are installed on the system, and
49685 + is therefore left as an option. If the sysctl option is enabled, a
49686 + sysctl option with name "chroot_execlog" is created.
49687 +
49688 +config GRKERNSEC_AUDIT_PTRACE
49689 + bool "Ptrace logging"
49690 + help
49691 + If you say Y here, all attempts to attach to a process via ptrace
49692 + will be logged. If the sysctl option is enabled, a sysctl option
49693 + with name "audit_ptrace" is created.
49694 +
49695 +config GRKERNSEC_AUDIT_CHDIR
49696 + bool "Chdir logging"
49697 + help
49698 + If you say Y here, all chdir() calls will be logged. If the sysctl
49699 + option is enabled, a sysctl option with name "audit_chdir" is created.
49700 +
49701 +config GRKERNSEC_AUDIT_MOUNT
49702 + bool "(Un)Mount logging"
49703 + help
49704 + If you say Y here, all mounts and unmounts will be logged. If the
49705 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49706 + created.
49707 +
49708 +config GRKERNSEC_SIGNAL
49709 + bool "Signal logging"
49710 + default y if GRKERNSEC_CONFIG_AUTO
49711 + help
49712 + If you say Y here, certain important signals will be logged, such as
49713 + SIGSEGV, which will as a result inform you of when a error in a program
49714 + occurred, which in some cases could mean a possible exploit attempt.
49715 + If the sysctl option is enabled, a sysctl option with name
49716 + "signal_logging" is created.
49717 +
49718 +config GRKERNSEC_FORKFAIL
49719 + bool "Fork failure logging"
49720 + help
49721 + If you say Y here, all failed fork() attempts will be logged.
49722 + This could suggest a fork bomb, or someone attempting to overstep
49723 + their process limit. If the sysctl option is enabled, a sysctl option
49724 + with name "forkfail_logging" is created.
49725 +
49726 +config GRKERNSEC_TIME
49727 + bool "Time change logging"
49728 + default y if GRKERNSEC_CONFIG_AUTO
49729 + help
49730 + If you say Y here, any changes of the system clock will be logged.
49731 + If the sysctl option is enabled, a sysctl option with name
49732 + "timechange_logging" is created.
49733 +
49734 +config GRKERNSEC_PROC_IPADDR
49735 + bool "/proc/<pid>/ipaddr support"
49736 + default y if GRKERNSEC_CONFIG_AUTO
49737 + help
49738 + If you say Y here, a new entry will be added to each /proc/<pid>
49739 + directory that contains the IP address of the person using the task.
49740 + The IP is carried across local TCP and AF_UNIX stream sockets.
49741 + This information can be useful for IDS/IPSes to perform remote response
49742 + to a local attack. The entry is readable by only the owner of the
49743 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49744 + the RBAC system), and thus does not create privacy concerns.
49745 +
49746 +config GRKERNSEC_RWXMAP_LOG
49747 + bool 'Denied RWX mmap/mprotect logging'
49748 + default y if GRKERNSEC_CONFIG_AUTO
49749 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49750 + help
49751 + If you say Y here, calls to mmap() and mprotect() with explicit
49752 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49753 + denied by the PAX_MPROTECT feature. If the sysctl option is
49754 + enabled, a sysctl option with name "rwxmap_logging" is created.
49755 +
49756 +config GRKERNSEC_AUDIT_TEXTREL
49757 + bool 'ELF text relocations logging (READ HELP)'
49758 + depends on PAX_MPROTECT
49759 + help
49760 + If you say Y here, text relocations will be logged with the filename
49761 + of the offending library or binary. The purpose of the feature is
49762 + to help Linux distribution developers get rid of libraries and
49763 + binaries that need text relocations which hinder the future progress
49764 + of PaX. Only Linux distribution developers should say Y here, and
49765 + never on a production machine, as this option creates an information
49766 + leak that could aid an attacker in defeating the randomization of
49767 + a single memory region. If the sysctl option is enabled, a sysctl
49768 + option with name "audit_textrel" is created.
49769 +
49770 +endmenu
49771 +
49772 +menu "Executable Protections"
49773 +depends on GRKERNSEC
49774 +
49775 +config GRKERNSEC_DMESG
49776 + bool "Dmesg(8) restriction"
49777 + default y if GRKERNSEC_CONFIG_AUTO
49778 + help
49779 + If you say Y here, non-root users will not be able to use dmesg(8)
49780 + to view up to the last 4kb of messages in the kernel's log buffer.
49781 + The kernel's log buffer often contains kernel addresses and other
49782 + identifying information useful to an attacker in fingerprinting a
49783 + system for a targeted exploit.
49784 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49785 + created.
49786 +
49787 +config GRKERNSEC_HARDEN_PTRACE
49788 + bool "Deter ptrace-based process snooping"
49789 + default y if GRKERNSEC_CONFIG_AUTO
49790 + help
49791 + If you say Y here, TTY sniffers and other malicious monitoring
49792 + programs implemented through ptrace will be defeated. If you
49793 + have been using the RBAC system, this option has already been
49794 + enabled for several years for all users, with the ability to make
49795 + fine-grained exceptions.
49796 +
49797 + This option only affects the ability of non-root users to ptrace
49798 + processes that are not a descendent of the ptracing process.
49799 + This means that strace ./binary and gdb ./binary will still work,
49800 + but attaching to arbitrary processes will not. If the sysctl
49801 + option is enabled, a sysctl option with name "harden_ptrace" is
49802 + created.
49803 +
49804 +config GRKERNSEC_PTRACE_READEXEC
49805 + bool "Require read access to ptrace sensitive binaries"
49806 + default y if GRKERNSEC_CONFIG_AUTO
49807 + help
49808 + If you say Y here, unprivileged users will not be able to ptrace unreadable
49809 + binaries. This option is useful in environments that
49810 + remove the read bits (e.g. file mode 4711) from suid binaries to
49811 + prevent infoleaking of their contents. This option adds
49812 + consistency to the use of that file mode, as the binary could normally
49813 + be read out when run without privileges while ptracing.
49814 +
49815 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49816 + is created.
49817 +
49818 +config GRKERNSEC_SETXID
49819 + bool "Enforce consistent multithreaded privileges"
49820 + default y if GRKERNSEC_CONFIG_AUTO
49821 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
49822 + help
49823 + If you say Y here, a change from a root uid to a non-root uid
49824 + in a multithreaded application will cause the resulting uids,
49825 + gids, supplementary groups, and capabilities in that thread
49826 + to be propagated to the other threads of the process. In most
49827 + cases this is unnecessary, as glibc will emulate this behavior
49828 + on behalf of the application. Other libcs do not act in the
49829 + same way, allowing the other threads of the process to continue
49830 + running with root privileges. If the sysctl option is enabled,
49831 + a sysctl option with name "consistent_setxid" is created.
49832 +
49833 +config GRKERNSEC_TPE
49834 + bool "Trusted Path Execution (TPE)"
49835 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49836 + help
49837 + If you say Y here, you will be able to choose a gid to add to the
49838 + supplementary groups of users you want to mark as "untrusted."
49839 + These users will not be able to execute any files that are not in
49840 + root-owned directories writable only by root. If the sysctl option
49841 + is enabled, a sysctl option with name "tpe" is created.
49842 +
49843 +config GRKERNSEC_TPE_ALL
49844 + bool "Partially restrict all non-root users"
49845 + depends on GRKERNSEC_TPE
49846 + help
49847 + If you say Y here, all non-root users will be covered under
49848 + a weaker TPE restriction. This is separate from, and in addition to,
49849 + the main TPE options that you have selected elsewhere. Thus, if a
49850 + "trusted" GID is chosen, this restriction applies to even that GID.
49851 + Under this restriction, all non-root users will only be allowed to
49852 + execute files in directories they own that are not group or
49853 + world-writable, or in directories owned by root and writable only by
49854 + root. If the sysctl option is enabled, a sysctl option with name
49855 + "tpe_restrict_all" is created.
49856 +
49857 +config GRKERNSEC_TPE_INVERT
49858 + bool "Invert GID option"
49859 + depends on GRKERNSEC_TPE
49860 + help
49861 + If you say Y here, the group you specify in the TPE configuration will
49862 + decide what group TPE restrictions will be *disabled* for. This
49863 + option is useful if you want TPE restrictions to be applied to most
49864 + users on the system. If the sysctl option is enabled, a sysctl option
49865 + with name "tpe_invert" is created. Unlike other sysctl options, this
49866 + entry will default to on for backward-compatibility.
49867 +
49868 +config GRKERNSEC_TPE_GID
49869 + int "GID for untrusted users"
49870 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49871 + default 1005
49872 + help
49873 + Setting this GID determines what group TPE restrictions will be
49874 + *enabled* for. If the sysctl option is enabled, a sysctl option
49875 + with name "tpe_gid" is created.
49876 +
49877 +config GRKERNSEC_TPE_GID
49878 + int "GID for trusted users"
49879 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49880 + default 1005
49881 + help
49882 + Setting this GID determines what group TPE restrictions will be
49883 + *disabled* for. If the sysctl option is enabled, a sysctl option
49884 + with name "tpe_gid" is created.
49885 +
49886 +endmenu
49887 +menu "Network Protections"
49888 +depends on GRKERNSEC
49889 +
49890 +config GRKERNSEC_RANDNET
49891 + bool "Larger entropy pools"
49892 + default y if GRKERNSEC_CONFIG_AUTO
49893 + help
49894 + If you say Y here, the entropy pools used for many features of Linux
49895 + and grsecurity will be doubled in size. Since several grsecurity
49896 + features use additional randomness, it is recommended that you say Y
49897 + here. Saying Y here has a similar effect as modifying
49898 + /proc/sys/kernel/random/poolsize.
49899 +
49900 +config GRKERNSEC_BLACKHOLE
49901 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49902 + default y if GRKERNSEC_CONFIG_AUTO
49903 + depends on NET
49904 + help
49905 + If you say Y here, neither TCP resets nor ICMP
49906 + destination-unreachable packets will be sent in response to packets
49907 + sent to ports for which no associated listening process exists.
49908 + This feature supports both IPV4 and IPV6 and exempts the
49909 + loopback interface from blackholing. Enabling this feature
49910 + makes a host more resilient to DoS attacks and reduces network
49911 + visibility against scanners.
49912 +
49913 + The blackhole feature as-implemented is equivalent to the FreeBSD
49914 + blackhole feature, as it prevents RST responses to all packets, not
49915 + just SYNs. Under most application behavior this causes no
49916 + problems, but applications (like haproxy) may not close certain
49917 + connections in a way that cleanly terminates them on the remote
49918 + end, leaving the remote host in LAST_ACK state. Because of this
49919 + side-effect and to prevent intentional LAST_ACK DoSes, this
49920 + feature also adds automatic mitigation against such attacks.
49921 + The mitigation drastically reduces the amount of time a socket
49922 + can spend in LAST_ACK state. If you're using haproxy and not
49923 + all servers it connects to have this option enabled, consider
49924 + disabling this feature on the haproxy host.
49925 +
49926 + If the sysctl option is enabled, two sysctl options with names
49927 + "ip_blackhole" and "lastack_retries" will be created.
49928 + While "ip_blackhole" takes the standard zero/non-zero on/off
49929 + toggle, "lastack_retries" uses the same kinds of values as
49930 + "tcp_retries1" and "tcp_retries2". The default value of 4
49931 + prevents a socket from lasting more than 45 seconds in LAST_ACK
49932 + state.
49933 +
49934 +config GRKERNSEC_SOCKET
49935 + bool "Socket restrictions"
49936 + depends on NET
49937 + help
49938 + If you say Y here, you will be able to choose from several options.
49939 + If you assign a GID on your system and add it to the supplementary
49940 + groups of users you want to restrict socket access to, this patch
49941 + will perform up to three things, based on the option(s) you choose.
49942 +
49943 +config GRKERNSEC_SOCKET_ALL
49944 + bool "Deny any sockets to group"
49945 + depends on GRKERNSEC_SOCKET
49946 + help
49947 + If you say Y here, you will be able to choose a GID of whose users will
49948 + be unable to connect to other hosts from your machine or run server
49949 + applications from your machine. If the sysctl option is enabled, a
49950 + sysctl option with name "socket_all" is created.
49951 +
49952 +config GRKERNSEC_SOCKET_ALL_GID
49953 + int "GID to deny all sockets for"
49954 + depends on GRKERNSEC_SOCKET_ALL
49955 + default 1004
49956 + help
49957 + Here you can choose the GID to disable socket access for. Remember to
49958 + add the users you want socket access disabled for to the GID
49959 + specified here. If the sysctl option is enabled, a sysctl option
49960 + with name "socket_all_gid" is created.
49961 +
49962 +config GRKERNSEC_SOCKET_CLIENT
49963 + bool "Deny client sockets to group"
49964 + depends on GRKERNSEC_SOCKET
49965 + help
49966 + If you say Y here, you will be able to choose a GID of whose users will
49967 + be unable to connect to other hosts from your machine, but will be
49968 + able to run servers. If this option is enabled, all users in the group
49969 + you specify will have to use passive mode when initiating ftp transfers
49970 + from the shell on your machine. If the sysctl option is enabled, a
49971 + sysctl option with name "socket_client" is created.
49972 +
49973 +config GRKERNSEC_SOCKET_CLIENT_GID
49974 + int "GID to deny client sockets for"
49975 + depends on GRKERNSEC_SOCKET_CLIENT
49976 + default 1003
49977 + help
49978 + Here you can choose the GID to disable client socket access for.
49979 + Remember to add the users you want client socket access disabled for to
49980 + the GID specified here. If the sysctl option is enabled, a sysctl
49981 + option with name "socket_client_gid" is created.
49982 +
49983 +config GRKERNSEC_SOCKET_SERVER
49984 + bool "Deny server sockets to group"
49985 + depends on GRKERNSEC_SOCKET
49986 + help
49987 + If you say Y here, you will be able to choose a GID of whose users will
49988 + be unable to run server applications from your machine. If the sysctl
49989 + option is enabled, a sysctl option with name "socket_server" is created.
49990 +
49991 +config GRKERNSEC_SOCKET_SERVER_GID
49992 + int "GID to deny server sockets for"
49993 + depends on GRKERNSEC_SOCKET_SERVER
49994 + default 1002
49995 + help
49996 + Here you can choose the GID to disable server socket access for.
49997 + Remember to add the users you want server socket access disabled for to
49998 + the GID specified here. If the sysctl option is enabled, a sysctl
49999 + option with name "socket_server_gid" is created.
50000 +
50001 +endmenu
50002 +menu "Sysctl Support"
50003 +depends on GRKERNSEC && SYSCTL
50004 +
50005 +config GRKERNSEC_SYSCTL
50006 + bool "Sysctl support"
50007 + default y if GRKERNSEC_CONFIG_AUTO
50008 + help
50009 + If you say Y here, you will be able to change the options that
50010 + grsecurity runs with at bootup, without having to recompile your
50011 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50012 + to enable (1) or disable (0) various features. All the sysctl entries
50013 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50014 + All features enabled in the kernel configuration are disabled at boot
50015 + if you do not say Y to the "Turn on features by default" option.
50016 + All options should be set at startup, and the grsec_lock entry should
50017 + be set to a non-zero value after all the options are set.
50018 + *THIS IS EXTREMELY IMPORTANT*
50019 +
50020 +config GRKERNSEC_SYSCTL_DISTRO
50021 + bool "Extra sysctl support for distro makers (READ HELP)"
50022 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50023 + help
50024 + If you say Y here, additional sysctl options will be created
50025 + for features that affect processes running as root. Therefore,
50026 + it is critical when using this option that the grsec_lock entry be
50027 + enabled after boot. Only distros with prebuilt kernel packages
50028 + with this option enabled that can ensure grsec_lock is enabled
50029 + after boot should use this option.
50030 + *Failure to set grsec_lock after boot makes all grsec features
50031 + this option covers useless*
50032 +
50033 + Currently this option creates the following sysctl entries:
50034 + "Disable Privileged I/O": "disable_priv_io"
50035 +
50036 +config GRKERNSEC_SYSCTL_ON
50037 + bool "Turn on features by default"
50038 + default y if GRKERNSEC_CONFIG_AUTO
50039 + depends on GRKERNSEC_SYSCTL
50040 + help
50041 + If you say Y here, instead of having all features enabled in the
50042 + kernel configuration disabled at boot time, the features will be
50043 + enabled at boot time. It is recommended you say Y here unless
50044 + there is some reason you would want all sysctl-tunable features to
50045 + be disabled by default. As mentioned elsewhere, it is important
50046 + to enable the grsec_lock entry once you have finished modifying
50047 + the sysctl entries.
50048 +
50049 +endmenu
50050 +menu "Logging Options"
50051 +depends on GRKERNSEC
50052 +
50053 +config GRKERNSEC_FLOODTIME
50054 + int "Seconds in between log messages (minimum)"
50055 + default 10
50056 + help
50057 + This option allows you to enforce the number of seconds between
50058 + grsecurity log messages. The default should be suitable for most
50059 + people, however, if you choose to change it, choose a value small enough
50060 + to allow informative logs to be produced, but large enough to
50061 + prevent flooding.
50062 +
50063 +config GRKERNSEC_FLOODBURST
50064 + int "Number of messages in a burst (maximum)"
50065 + default 6
50066 + help
50067 + This option allows you to choose the maximum number of messages allowed
50068 + within the flood time interval you chose in a separate option. The
50069 + default should be suitable for most people, however if you find that
50070 + many of your logs are being interpreted as flooding, you may want to
50071 + raise this value.
50072 +
50073 +endmenu
50074 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50075 new file mode 100644
50076 index 0000000..1b9afa9
50077 --- /dev/null
50078 +++ b/grsecurity/Makefile
50079 @@ -0,0 +1,38 @@
50080 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50081 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50082 +# into an RBAC system
50083 +#
50084 +# All code in this directory and various hooks inserted throughout the kernel
50085 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50086 +# under the GPL v2 or higher
50087 +
50088 +KBUILD_CFLAGS += -Werror
50089 +
50090 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50091 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50092 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50093 +
50094 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50095 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50096 + gracl_learn.o grsec_log.o
50097 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50098 +
50099 +ifdef CONFIG_NET
50100 +obj-y += grsec_sock.o
50101 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50102 +endif
50103 +
50104 +ifndef CONFIG_GRKERNSEC
50105 +obj-y += grsec_disabled.o
50106 +endif
50107 +
50108 +ifdef CONFIG_GRKERNSEC_HIDESYM
50109 +extra-y := grsec_hidesym.o
50110 +$(obj)/grsec_hidesym.o:
50111 + @-chmod -f 500 /boot
50112 + @-chmod -f 500 /lib/modules
50113 + @-chmod -f 500 /lib64/modules
50114 + @-chmod -f 500 /lib32/modules
50115 + @-chmod -f 700 .
50116 + @echo ' grsec: protected kernel image paths'
50117 +endif
50118 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50119 new file mode 100644
50120 index 0000000..7a5922f
50121 --- /dev/null
50122 +++ b/grsecurity/gracl.c
50123 @@ -0,0 +1,4016 @@
50124 +#include <linux/kernel.h>
50125 +#include <linux/module.h>
50126 +#include <linux/sched.h>
50127 +#include <linux/mm.h>
50128 +#include <linux/file.h>
50129 +#include <linux/fs.h>
50130 +#include <linux/namei.h>
50131 +#include <linux/mount.h>
50132 +#include <linux/tty.h>
50133 +#include <linux/proc_fs.h>
50134 +#include <linux/lglock.h>
50135 +#include <linux/slab.h>
50136 +#include <linux/vmalloc.h>
50137 +#include <linux/types.h>
50138 +#include <linux/sysctl.h>
50139 +#include <linux/netdevice.h>
50140 +#include <linux/ptrace.h>
50141 +#include <linux/gracl.h>
50142 +#include <linux/gralloc.h>
50143 +#include <linux/security.h>
50144 +#include <linux/grinternal.h>
50145 +#include <linux/pid_namespace.h>
50146 +#include <linux/stop_machine.h>
50147 +#include <linux/fdtable.h>
50148 +#include <linux/percpu.h>
50149 +#include "../fs/mount.h"
50150 +
50151 +#include <asm/uaccess.h>
50152 +#include <asm/errno.h>
50153 +#include <asm/mman.h>
50154 +
50155 +static struct acl_role_db acl_role_set;
50156 +static struct name_db name_set;
50157 +static struct inodev_db inodev_set;
50158 +
50159 +/* for keeping track of userspace pointers used for subjects, so we
50160 + can share references in the kernel as well
50161 +*/
50162 +
50163 +static struct path real_root;
50164 +
50165 +static struct acl_subj_map_db subj_map_set;
50166 +
50167 +static struct acl_role_label *default_role;
50168 +
50169 +static struct acl_role_label *role_list;
50170 +
50171 +static u16 acl_sp_role_value;
50172 +
50173 +extern char *gr_shared_page[4];
50174 +static DEFINE_MUTEX(gr_dev_mutex);
50175 +DEFINE_RWLOCK(gr_inode_lock);
50176 +
50177 +struct gr_arg *gr_usermode;
50178 +
50179 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50180 +
50181 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50182 +extern void gr_clear_learn_entries(void);
50183 +
50184 +#ifdef CONFIG_GRKERNSEC_RESLOG
50185 +extern void gr_log_resource(const struct task_struct *task,
50186 + const int res, const unsigned long wanted, const int gt);
50187 +#endif
50188 +
50189 +unsigned char *gr_system_salt;
50190 +unsigned char *gr_system_sum;
50191 +
50192 +static struct sprole_pw **acl_special_roles = NULL;
50193 +static __u16 num_sprole_pws = 0;
50194 +
50195 +static struct acl_role_label *kernel_role = NULL;
50196 +
50197 +static unsigned int gr_auth_attempts = 0;
50198 +static unsigned long gr_auth_expires = 0UL;
50199 +
50200 +#ifdef CONFIG_NET
50201 +extern struct vfsmount *sock_mnt;
50202 +#endif
50203 +
50204 +extern struct vfsmount *pipe_mnt;
50205 +extern struct vfsmount *shm_mnt;
50206 +#ifdef CONFIG_HUGETLBFS
50207 +extern struct vfsmount *hugetlbfs_vfsmount;
50208 +#endif
50209 +
50210 +static struct acl_object_label *fakefs_obj_rw;
50211 +static struct acl_object_label *fakefs_obj_rwx;
50212 +
50213 +extern int gr_init_uidset(void);
50214 +extern void gr_free_uidset(void);
50215 +extern void gr_remove_uid(uid_t uid);
50216 +extern int gr_find_uid(uid_t uid);
50217 +
50218 +DECLARE_BRLOCK(vfsmount_lock);
50219 +
50220 +__inline__ int
50221 +gr_acl_is_enabled(void)
50222 +{
50223 + return (gr_status & GR_READY);
50224 +}
50225 +
50226 +#ifdef CONFIG_BTRFS_FS
50227 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50228 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50229 +#endif
50230 +
50231 +static inline dev_t __get_dev(const struct dentry *dentry)
50232 +{
50233 +#ifdef CONFIG_BTRFS_FS
50234 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50235 + return get_btrfs_dev_from_inode(dentry->d_inode);
50236 + else
50237 +#endif
50238 + return dentry->d_inode->i_sb->s_dev;
50239 +}
50240 +
50241 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50242 +{
50243 + return __get_dev(dentry);
50244 +}
50245 +
50246 +static char gr_task_roletype_to_char(struct task_struct *task)
50247 +{
50248 + switch (task->role->roletype &
50249 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50250 + GR_ROLE_SPECIAL)) {
50251 + case GR_ROLE_DEFAULT:
50252 + return 'D';
50253 + case GR_ROLE_USER:
50254 + return 'U';
50255 + case GR_ROLE_GROUP:
50256 + return 'G';
50257 + case GR_ROLE_SPECIAL:
50258 + return 'S';
50259 + }
50260 +
50261 + return 'X';
50262 +}
50263 +
50264 +char gr_roletype_to_char(void)
50265 +{
50266 + return gr_task_roletype_to_char(current);
50267 +}
50268 +
50269 +__inline__ int
50270 +gr_acl_tpe_check(void)
50271 +{
50272 + if (unlikely(!(gr_status & GR_READY)))
50273 + return 0;
50274 + if (current->role->roletype & GR_ROLE_TPE)
50275 + return 1;
50276 + else
50277 + return 0;
50278 +}
50279 +
50280 +int
50281 +gr_handle_rawio(const struct inode *inode)
50282 +{
50283 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50284 + if (inode && S_ISBLK(inode->i_mode) &&
50285 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50286 + !capable(CAP_SYS_RAWIO))
50287 + return 1;
50288 +#endif
50289 + return 0;
50290 +}
50291 +
50292 +static int
50293 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50294 +{
50295 + if (likely(lena != lenb))
50296 + return 0;
50297 +
50298 + return !memcmp(a, b, lena);
50299 +}
50300 +
50301 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50302 +{
50303 + *buflen -= namelen;
50304 + if (*buflen < 0)
50305 + return -ENAMETOOLONG;
50306 + *buffer -= namelen;
50307 + memcpy(*buffer, str, namelen);
50308 + return 0;
50309 +}
50310 +
50311 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50312 +{
50313 + return prepend(buffer, buflen, name->name, name->len);
50314 +}
50315 +
50316 +static int prepend_path(const struct path *path, struct path *root,
50317 + char **buffer, int *buflen)
50318 +{
50319 + struct dentry *dentry = path->dentry;
50320 + struct vfsmount *vfsmnt = path->mnt;
50321 + struct mount *mnt = real_mount(vfsmnt);
50322 + bool slash = false;
50323 + int error = 0;
50324 +
50325 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50326 + struct dentry * parent;
50327 +
50328 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50329 + /* Global root? */
50330 + if (!mnt_has_parent(mnt)) {
50331 + goto out;
50332 + }
50333 + dentry = mnt->mnt_mountpoint;
50334 + mnt = mnt->mnt_parent;
50335 + vfsmnt = &mnt->mnt;
50336 + continue;
50337 + }
50338 + parent = dentry->d_parent;
50339 + prefetch(parent);
50340 + spin_lock(&dentry->d_lock);
50341 + error = prepend_name(buffer, buflen, &dentry->d_name);
50342 + spin_unlock(&dentry->d_lock);
50343 + if (!error)
50344 + error = prepend(buffer, buflen, "/", 1);
50345 + if (error)
50346 + break;
50347 +
50348 + slash = true;
50349 + dentry = parent;
50350 + }
50351 +
50352 +out:
50353 + if (!error && !slash)
50354 + error = prepend(buffer, buflen, "/", 1);
50355 +
50356 + return error;
50357 +}
50358 +
50359 +/* this must be called with vfsmount_lock and rename_lock held */
50360 +
50361 +static char *__our_d_path(const struct path *path, struct path *root,
50362 + char *buf, int buflen)
50363 +{
50364 + char *res = buf + buflen;
50365 + int error;
50366 +
50367 + prepend(&res, &buflen, "\0", 1);
50368 + error = prepend_path(path, root, &res, &buflen);
50369 + if (error)
50370 + return ERR_PTR(error);
50371 +
50372 + return res;
50373 +}
50374 +
50375 +static char *
50376 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50377 +{
50378 + char *retval;
50379 +
50380 + retval = __our_d_path(path, root, buf, buflen);
50381 + if (unlikely(IS_ERR(retval)))
50382 + retval = strcpy(buf, "<path too long>");
50383 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50384 + retval[1] = '\0';
50385 +
50386 + return retval;
50387 +}
50388 +
50389 +static char *
50390 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50391 + char *buf, int buflen)
50392 +{
50393 + struct path path;
50394 + char *res;
50395 +
50396 + path.dentry = (struct dentry *)dentry;
50397 + path.mnt = (struct vfsmount *)vfsmnt;
50398 +
50399 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50400 + by the RBAC system */
50401 + res = gen_full_path(&path, &real_root, buf, buflen);
50402 +
50403 + return res;
50404 +}
50405 +
50406 +static char *
50407 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50408 + char *buf, int buflen)
50409 +{
50410 + char *res;
50411 + struct path path;
50412 + struct path root;
50413 + struct task_struct *reaper = init_pid_ns.child_reaper;
50414 +
50415 + path.dentry = (struct dentry *)dentry;
50416 + path.mnt = (struct vfsmount *)vfsmnt;
50417 +
50418 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50419 + get_fs_root(reaper->fs, &root);
50420 +
50421 + write_seqlock(&rename_lock);
50422 + br_read_lock(vfsmount_lock);
50423 + res = gen_full_path(&path, &root, buf, buflen);
50424 + br_read_unlock(vfsmount_lock);
50425 + write_sequnlock(&rename_lock);
50426 +
50427 + path_put(&root);
50428 + return res;
50429 +}
50430 +
50431 +static char *
50432 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50433 +{
50434 + char *ret;
50435 + write_seqlock(&rename_lock);
50436 + br_read_lock(vfsmount_lock);
50437 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50438 + PAGE_SIZE);
50439 + br_read_unlock(vfsmount_lock);
50440 + write_sequnlock(&rename_lock);
50441 + return ret;
50442 +}
50443 +
50444 +static char *
50445 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50446 +{
50447 + char *ret;
50448 + char *buf;
50449 + int buflen;
50450 +
50451 + write_seqlock(&rename_lock);
50452 + br_read_lock(vfsmount_lock);
50453 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50454 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50455 + buflen = (int)(ret - buf);
50456 + if (buflen >= 5)
50457 + prepend(&ret, &buflen, "/proc", 5);
50458 + else
50459 + ret = strcpy(buf, "<path too long>");
50460 + br_read_unlock(vfsmount_lock);
50461 + write_sequnlock(&rename_lock);
50462 + return ret;
50463 +}
50464 +
50465 +char *
50466 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50467 +{
50468 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50469 + PAGE_SIZE);
50470 +}
50471 +
50472 +char *
50473 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50474 +{
50475 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50476 + PAGE_SIZE);
50477 +}
50478 +
50479 +char *
50480 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50481 +{
50482 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50483 + PAGE_SIZE);
50484 +}
50485 +
50486 +char *
50487 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50488 +{
50489 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50490 + PAGE_SIZE);
50491 +}
50492 +
50493 +char *
50494 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50495 +{
50496 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50497 + PAGE_SIZE);
50498 +}
50499 +
50500 +__inline__ __u32
50501 +to_gr_audit(const __u32 reqmode)
50502 +{
50503 + /* masks off auditable permission flags, then shifts them to create
50504 + auditing flags, and adds the special case of append auditing if
50505 + we're requesting write */
50506 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50507 +}
50508 +
50509 +struct acl_subject_label *
50510 +lookup_subject_map(const struct acl_subject_label *userp)
50511 +{
50512 + unsigned int index = shash(userp, subj_map_set.s_size);
50513 + struct subject_map *match;
50514 +
50515 + match = subj_map_set.s_hash[index];
50516 +
50517 + while (match && match->user != userp)
50518 + match = match->next;
50519 +
50520 + if (match != NULL)
50521 + return match->kernel;
50522 + else
50523 + return NULL;
50524 +}
50525 +
50526 +static void
50527 +insert_subj_map_entry(struct subject_map *subjmap)
50528 +{
50529 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50530 + struct subject_map **curr;
50531 +
50532 + subjmap->prev = NULL;
50533 +
50534 + curr = &subj_map_set.s_hash[index];
50535 + if (*curr != NULL)
50536 + (*curr)->prev = subjmap;
50537 +
50538 + subjmap->next = *curr;
50539 + *curr = subjmap;
50540 +
50541 + return;
50542 +}
50543 +
50544 +static struct acl_role_label *
50545 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50546 + const gid_t gid)
50547 +{
50548 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50549 + struct acl_role_label *match;
50550 + struct role_allowed_ip *ipp;
50551 + unsigned int x;
50552 + u32 curr_ip = task->signal->curr_ip;
50553 +
50554 + task->signal->saved_ip = curr_ip;
50555 +
50556 + match = acl_role_set.r_hash[index];
50557 +
50558 + while (match) {
50559 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50560 + for (x = 0; x < match->domain_child_num; x++) {
50561 + if (match->domain_children[x] == uid)
50562 + goto found;
50563 + }
50564 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50565 + break;
50566 + match = match->next;
50567 + }
50568 +found:
50569 + if (match == NULL) {
50570 + try_group:
50571 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50572 + match = acl_role_set.r_hash[index];
50573 +
50574 + while (match) {
50575 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50576 + for (x = 0; x < match->domain_child_num; x++) {
50577 + if (match->domain_children[x] == gid)
50578 + goto found2;
50579 + }
50580 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50581 + break;
50582 + match = match->next;
50583 + }
50584 +found2:
50585 + if (match == NULL)
50586 + match = default_role;
50587 + if (match->allowed_ips == NULL)
50588 + return match;
50589 + else {
50590 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50591 + if (likely
50592 + ((ntohl(curr_ip) & ipp->netmask) ==
50593 + (ntohl(ipp->addr) & ipp->netmask)))
50594 + return match;
50595 + }
50596 + match = default_role;
50597 + }
50598 + } else if (match->allowed_ips == NULL) {
50599 + return match;
50600 + } else {
50601 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50602 + if (likely
50603 + ((ntohl(curr_ip) & ipp->netmask) ==
50604 + (ntohl(ipp->addr) & ipp->netmask)))
50605 + return match;
50606 + }
50607 + goto try_group;
50608 + }
50609 +
50610 + return match;
50611 +}
50612 +
50613 +struct acl_subject_label *
50614 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50615 + const struct acl_role_label *role)
50616 +{
50617 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50618 + struct acl_subject_label *match;
50619 +
50620 + match = role->subj_hash[index];
50621 +
50622 + while (match && (match->inode != ino || match->device != dev ||
50623 + (match->mode & GR_DELETED))) {
50624 + match = match->next;
50625 + }
50626 +
50627 + if (match && !(match->mode & GR_DELETED))
50628 + return match;
50629 + else
50630 + return NULL;
50631 +}
50632 +
50633 +struct acl_subject_label *
50634 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50635 + const struct acl_role_label *role)
50636 +{
50637 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50638 + struct acl_subject_label *match;
50639 +
50640 + match = role->subj_hash[index];
50641 +
50642 + while (match && (match->inode != ino || match->device != dev ||
50643 + !(match->mode & GR_DELETED))) {
50644 + match = match->next;
50645 + }
50646 +
50647 + if (match && (match->mode & GR_DELETED))
50648 + return match;
50649 + else
50650 + return NULL;
50651 +}
50652 +
50653 +static struct acl_object_label *
50654 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50655 + const struct acl_subject_label *subj)
50656 +{
50657 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50658 + struct acl_object_label *match;
50659 +
50660 + match = subj->obj_hash[index];
50661 +
50662 + while (match && (match->inode != ino || match->device != dev ||
50663 + (match->mode & GR_DELETED))) {
50664 + match = match->next;
50665 + }
50666 +
50667 + if (match && !(match->mode & GR_DELETED))
50668 + return match;
50669 + else
50670 + return NULL;
50671 +}
50672 +
50673 +static struct acl_object_label *
50674 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50675 + const struct acl_subject_label *subj)
50676 +{
50677 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50678 + struct acl_object_label *match;
50679 +
50680 + match = subj->obj_hash[index];
50681 +
50682 + while (match && (match->inode != ino || match->device != dev ||
50683 + !(match->mode & GR_DELETED))) {
50684 + match = match->next;
50685 + }
50686 +
50687 + if (match && (match->mode & GR_DELETED))
50688 + return match;
50689 +
50690 + match = subj->obj_hash[index];
50691 +
50692 + while (match && (match->inode != ino || match->device != dev ||
50693 + (match->mode & GR_DELETED))) {
50694 + match = match->next;
50695 + }
50696 +
50697 + if (match && !(match->mode & GR_DELETED))
50698 + return match;
50699 + else
50700 + return NULL;
50701 +}
50702 +
50703 +static struct name_entry *
50704 +lookup_name_entry(const char *name)
50705 +{
50706 + unsigned int len = strlen(name);
50707 + unsigned int key = full_name_hash(name, len);
50708 + unsigned int index = key % name_set.n_size;
50709 + struct name_entry *match;
50710 +
50711 + match = name_set.n_hash[index];
50712 +
50713 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50714 + match = match->next;
50715 +
50716 + return match;
50717 +}
50718 +
50719 +static struct name_entry *
50720 +lookup_name_entry_create(const char *name)
50721 +{
50722 + unsigned int len = strlen(name);
50723 + unsigned int key = full_name_hash(name, len);
50724 + unsigned int index = key % name_set.n_size;
50725 + struct name_entry *match;
50726 +
50727 + match = name_set.n_hash[index];
50728 +
50729 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50730 + !match->deleted))
50731 + match = match->next;
50732 +
50733 + if (match && match->deleted)
50734 + return match;
50735 +
50736 + match = name_set.n_hash[index];
50737 +
50738 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50739 + match->deleted))
50740 + match = match->next;
50741 +
50742 + if (match && !match->deleted)
50743 + return match;
50744 + else
50745 + return NULL;
50746 +}
50747 +
50748 +static struct inodev_entry *
50749 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50750 +{
50751 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50752 + struct inodev_entry *match;
50753 +
50754 + match = inodev_set.i_hash[index];
50755 +
50756 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50757 + match = match->next;
50758 +
50759 + return match;
50760 +}
50761 +
50762 +static void
50763 +insert_inodev_entry(struct inodev_entry *entry)
50764 +{
50765 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50766 + inodev_set.i_size);
50767 + struct inodev_entry **curr;
50768 +
50769 + entry->prev = NULL;
50770 +
50771 + curr = &inodev_set.i_hash[index];
50772 + if (*curr != NULL)
50773 + (*curr)->prev = entry;
50774 +
50775 + entry->next = *curr;
50776 + *curr = entry;
50777 +
50778 + return;
50779 +}
50780 +
50781 +static void
50782 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50783 +{
50784 + unsigned int index =
50785 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50786 + struct acl_role_label **curr;
50787 + struct acl_role_label *tmp, *tmp2;
50788 +
50789 + curr = &acl_role_set.r_hash[index];
50790 +
50791 + /* simple case, slot is empty, just set it to our role */
50792 + if (*curr == NULL) {
50793 + *curr = role;
50794 + } else {
50795 + /* example:
50796 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
50797 + 2 -> 3
50798 + */
50799 + /* first check to see if we can already be reached via this slot */
50800 + tmp = *curr;
50801 + while (tmp && tmp != role)
50802 + tmp = tmp->next;
50803 + if (tmp == role) {
50804 + /* we don't need to add ourselves to this slot's chain */
50805 + return;
50806 + }
50807 + /* we need to add ourselves to this chain, two cases */
50808 + if (role->next == NULL) {
50809 + /* simple case, append the current chain to our role */
50810 + role->next = *curr;
50811 + *curr = role;
50812 + } else {
50813 + /* 1 -> 2 -> 3 -> 4
50814 + 2 -> 3 -> 4
50815 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50816 + */
50817 + /* trickier case: walk our role's chain until we find
50818 + the role for the start of the current slot's chain */
50819 + tmp = role;
50820 + tmp2 = *curr;
50821 + while (tmp->next && tmp->next != tmp2)
50822 + tmp = tmp->next;
50823 + if (tmp->next == tmp2) {
50824 + /* from example above, we found 3, so just
50825 + replace this slot's chain with ours */
50826 + *curr = role;
50827 + } else {
50828 + /* we didn't find a subset of our role's chain
50829 + in the current slot's chain, so append their
50830 + chain to ours, and set us as the first role in
50831 + the slot's chain
50832 +
50833 + we could fold this case with the case above,
50834 + but making it explicit for clarity
50835 + */
50836 + tmp->next = tmp2;
50837 + *curr = role;
50838 + }
50839 + }
50840 + }
50841 +
50842 + return;
50843 +}
50844 +
50845 +static void
50846 +insert_acl_role_label(struct acl_role_label *role)
50847 +{
50848 + int i;
50849 +
50850 + if (role_list == NULL) {
50851 + role_list = role;
50852 + role->prev = NULL;
50853 + } else {
50854 + role->prev = role_list;
50855 + role_list = role;
50856 + }
50857 +
50858 + /* used for hash chains */
50859 + role->next = NULL;
50860 +
50861 + if (role->roletype & GR_ROLE_DOMAIN) {
50862 + for (i = 0; i < role->domain_child_num; i++)
50863 + __insert_acl_role_label(role, role->domain_children[i]);
50864 + } else
50865 + __insert_acl_role_label(role, role->uidgid);
50866 +}
50867 +
50868 +static int
50869 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50870 +{
50871 + struct name_entry **curr, *nentry;
50872 + struct inodev_entry *ientry;
50873 + unsigned int len = strlen(name);
50874 + unsigned int key = full_name_hash(name, len);
50875 + unsigned int index = key % name_set.n_size;
50876 +
50877 + curr = &name_set.n_hash[index];
50878 +
50879 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50880 + curr = &((*curr)->next);
50881 +
50882 + if (*curr != NULL)
50883 + return 1;
50884 +
50885 + nentry = acl_alloc(sizeof (struct name_entry));
50886 + if (nentry == NULL)
50887 + return 0;
50888 + ientry = acl_alloc(sizeof (struct inodev_entry));
50889 + if (ientry == NULL)
50890 + return 0;
50891 + ientry->nentry = nentry;
50892 +
50893 + nentry->key = key;
50894 + nentry->name = name;
50895 + nentry->inode = inode;
50896 + nentry->device = device;
50897 + nentry->len = len;
50898 + nentry->deleted = deleted;
50899 +
50900 + nentry->prev = NULL;
50901 + curr = &name_set.n_hash[index];
50902 + if (*curr != NULL)
50903 + (*curr)->prev = nentry;
50904 + nentry->next = *curr;
50905 + *curr = nentry;
50906 +
50907 + /* insert us into the table searchable by inode/dev */
50908 + insert_inodev_entry(ientry);
50909 +
50910 + return 1;
50911 +}
50912 +
50913 +static void
50914 +insert_acl_obj_label(struct acl_object_label *obj,
50915 + struct acl_subject_label *subj)
50916 +{
50917 + unsigned int index =
50918 + fhash(obj->inode, obj->device, subj->obj_hash_size);
50919 + struct acl_object_label **curr;
50920 +
50921 +
50922 + obj->prev = NULL;
50923 +
50924 + curr = &subj->obj_hash[index];
50925 + if (*curr != NULL)
50926 + (*curr)->prev = obj;
50927 +
50928 + obj->next = *curr;
50929 + *curr = obj;
50930 +
50931 + return;
50932 +}
50933 +
50934 +static void
50935 +insert_acl_subj_label(struct acl_subject_label *obj,
50936 + struct acl_role_label *role)
50937 +{
50938 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50939 + struct acl_subject_label **curr;
50940 +
50941 + obj->prev = NULL;
50942 +
50943 + curr = &role->subj_hash[index];
50944 + if (*curr != NULL)
50945 + (*curr)->prev = obj;
50946 +
50947 + obj->next = *curr;
50948 + *curr = obj;
50949 +
50950 + return;
50951 +}
50952 +
50953 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50954 +
50955 +static void *
50956 +create_table(__u32 * len, int elementsize)
50957 +{
50958 + unsigned int table_sizes[] = {
50959 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50960 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50961 + 4194301, 8388593, 16777213, 33554393, 67108859
50962 + };
50963 + void *newtable = NULL;
50964 + unsigned int pwr = 0;
50965 +
50966 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50967 + table_sizes[pwr] <= *len)
50968 + pwr++;
50969 +
50970 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50971 + return newtable;
50972 +
50973 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50974 + newtable =
50975 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50976 + else
50977 + newtable = vmalloc(table_sizes[pwr] * elementsize);
50978 +
50979 + *len = table_sizes[pwr];
50980 +
50981 + return newtable;
50982 +}
50983 +
50984 +static int
50985 +init_variables(const struct gr_arg *arg)
50986 +{
50987 + struct task_struct *reaper = init_pid_ns.child_reaper;
50988 + unsigned int stacksize;
50989 +
50990 + subj_map_set.s_size = arg->role_db.num_subjects;
50991 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
50992 + name_set.n_size = arg->role_db.num_objects;
50993 + inodev_set.i_size = arg->role_db.num_objects;
50994 +
50995 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
50996 + !name_set.n_size || !inodev_set.i_size)
50997 + return 1;
50998 +
50999 + if (!gr_init_uidset())
51000 + return 1;
51001 +
51002 + /* set up the stack that holds allocation info */
51003 +
51004 + stacksize = arg->role_db.num_pointers + 5;
51005 +
51006 + if (!acl_alloc_stack_init(stacksize))
51007 + return 1;
51008 +
51009 + /* grab reference for the real root dentry and vfsmount */
51010 + get_fs_root(reaper->fs, &real_root);
51011 +
51012 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51013 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51014 +#endif
51015 +
51016 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51017 + if (fakefs_obj_rw == NULL)
51018 + return 1;
51019 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51020 +
51021 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51022 + if (fakefs_obj_rwx == NULL)
51023 + return 1;
51024 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51025 +
51026 + subj_map_set.s_hash =
51027 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51028 + acl_role_set.r_hash =
51029 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51030 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51031 + inodev_set.i_hash =
51032 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51033 +
51034 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51035 + !name_set.n_hash || !inodev_set.i_hash)
51036 + return 1;
51037 +
51038 + memset(subj_map_set.s_hash, 0,
51039 + sizeof(struct subject_map *) * subj_map_set.s_size);
51040 + memset(acl_role_set.r_hash, 0,
51041 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51042 + memset(name_set.n_hash, 0,
51043 + sizeof (struct name_entry *) * name_set.n_size);
51044 + memset(inodev_set.i_hash, 0,
51045 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51046 +
51047 + return 0;
51048 +}
51049 +
51050 +/* free information not needed after startup
51051 + currently contains user->kernel pointer mappings for subjects
51052 +*/
51053 +
51054 +static void
51055 +free_init_variables(void)
51056 +{
51057 + __u32 i;
51058 +
51059 + if (subj_map_set.s_hash) {
51060 + for (i = 0; i < subj_map_set.s_size; i++) {
51061 + if (subj_map_set.s_hash[i]) {
51062 + kfree(subj_map_set.s_hash[i]);
51063 + subj_map_set.s_hash[i] = NULL;
51064 + }
51065 + }
51066 +
51067 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51068 + PAGE_SIZE)
51069 + kfree(subj_map_set.s_hash);
51070 + else
51071 + vfree(subj_map_set.s_hash);
51072 + }
51073 +
51074 + return;
51075 +}
51076 +
51077 +static void
51078 +free_variables(void)
51079 +{
51080 + struct acl_subject_label *s;
51081 + struct acl_role_label *r;
51082 + struct task_struct *task, *task2;
51083 + unsigned int x;
51084 +
51085 + gr_clear_learn_entries();
51086 +
51087 + read_lock(&tasklist_lock);
51088 + do_each_thread(task2, task) {
51089 + task->acl_sp_role = 0;
51090 + task->acl_role_id = 0;
51091 + task->acl = NULL;
51092 + task->role = NULL;
51093 + } while_each_thread(task2, task);
51094 + read_unlock(&tasklist_lock);
51095 +
51096 + /* release the reference to the real root dentry and vfsmount */
51097 + path_put(&real_root);
51098 + memset(&real_root, 0, sizeof(real_root));
51099 +
51100 + /* free all object hash tables */
51101 +
51102 + FOR_EACH_ROLE_START(r)
51103 + if (r->subj_hash == NULL)
51104 + goto next_role;
51105 + FOR_EACH_SUBJECT_START(r, s, x)
51106 + if (s->obj_hash == NULL)
51107 + break;
51108 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51109 + kfree(s->obj_hash);
51110 + else
51111 + vfree(s->obj_hash);
51112 + FOR_EACH_SUBJECT_END(s, x)
51113 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51114 + if (s->obj_hash == NULL)
51115 + break;
51116 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51117 + kfree(s->obj_hash);
51118 + else
51119 + vfree(s->obj_hash);
51120 + FOR_EACH_NESTED_SUBJECT_END(s)
51121 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51122 + kfree(r->subj_hash);
51123 + else
51124 + vfree(r->subj_hash);
51125 + r->subj_hash = NULL;
51126 +next_role:
51127 + FOR_EACH_ROLE_END(r)
51128 +
51129 + acl_free_all();
51130 +
51131 + if (acl_role_set.r_hash) {
51132 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51133 + PAGE_SIZE)
51134 + kfree(acl_role_set.r_hash);
51135 + else
51136 + vfree(acl_role_set.r_hash);
51137 + }
51138 + if (name_set.n_hash) {
51139 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51140 + PAGE_SIZE)
51141 + kfree(name_set.n_hash);
51142 + else
51143 + vfree(name_set.n_hash);
51144 + }
51145 +
51146 + if (inodev_set.i_hash) {
51147 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51148 + PAGE_SIZE)
51149 + kfree(inodev_set.i_hash);
51150 + else
51151 + vfree(inodev_set.i_hash);
51152 + }
51153 +
51154 + gr_free_uidset();
51155 +
51156 + memset(&name_set, 0, sizeof (struct name_db));
51157 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51158 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51159 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51160 +
51161 + default_role = NULL;
51162 + kernel_role = NULL;
51163 + role_list = NULL;
51164 +
51165 + return;
51166 +}
51167 +
51168 +static __u32
51169 +count_user_objs(struct acl_object_label *userp)
51170 +{
51171 + struct acl_object_label o_tmp;
51172 + __u32 num = 0;
51173 +
51174 + while (userp) {
51175 + if (copy_from_user(&o_tmp, userp,
51176 + sizeof (struct acl_object_label)))
51177 + break;
51178 +
51179 + userp = o_tmp.prev;
51180 + num++;
51181 + }
51182 +
51183 + return num;
51184 +}
51185 +
51186 +static struct acl_subject_label *
51187 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51188 +
51189 +static int
51190 +copy_user_glob(struct acl_object_label *obj)
51191 +{
51192 + struct acl_object_label *g_tmp, **guser;
51193 + unsigned int len;
51194 + char *tmp;
51195 +
51196 + if (obj->globbed == NULL)
51197 + return 0;
51198 +
51199 + guser = &obj->globbed;
51200 + while (*guser) {
51201 + g_tmp = (struct acl_object_label *)
51202 + acl_alloc(sizeof (struct acl_object_label));
51203 + if (g_tmp == NULL)
51204 + return -ENOMEM;
51205 +
51206 + if (copy_from_user(g_tmp, *guser,
51207 + sizeof (struct acl_object_label)))
51208 + return -EFAULT;
51209 +
51210 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51211 +
51212 + if (!len || len >= PATH_MAX)
51213 + return -EINVAL;
51214 +
51215 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51216 + return -ENOMEM;
51217 +
51218 + if (copy_from_user(tmp, g_tmp->filename, len))
51219 + return -EFAULT;
51220 + tmp[len-1] = '\0';
51221 + g_tmp->filename = tmp;
51222 +
51223 + *guser = g_tmp;
51224 + guser = &(g_tmp->next);
51225 + }
51226 +
51227 + return 0;
51228 +}
51229 +
51230 +static int
51231 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51232 + struct acl_role_label *role)
51233 +{
51234 + struct acl_object_label *o_tmp;
51235 + unsigned int len;
51236 + int ret;
51237 + char *tmp;
51238 +
51239 + while (userp) {
51240 + if ((o_tmp = (struct acl_object_label *)
51241 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51242 + return -ENOMEM;
51243 +
51244 + if (copy_from_user(o_tmp, userp,
51245 + sizeof (struct acl_object_label)))
51246 + return -EFAULT;
51247 +
51248 + userp = o_tmp->prev;
51249 +
51250 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51251 +
51252 + if (!len || len >= PATH_MAX)
51253 + return -EINVAL;
51254 +
51255 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51256 + return -ENOMEM;
51257 +
51258 + if (copy_from_user(tmp, o_tmp->filename, len))
51259 + return -EFAULT;
51260 + tmp[len-1] = '\0';
51261 + o_tmp->filename = tmp;
51262 +
51263 + insert_acl_obj_label(o_tmp, subj);
51264 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51265 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51266 + return -ENOMEM;
51267 +
51268 + ret = copy_user_glob(o_tmp);
51269 + if (ret)
51270 + return ret;
51271 +
51272 + if (o_tmp->nested) {
51273 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51274 + if (IS_ERR(o_tmp->nested))
51275 + return PTR_ERR(o_tmp->nested);
51276 +
51277 + /* insert into nested subject list */
51278 + o_tmp->nested->next = role->hash->first;
51279 + role->hash->first = o_tmp->nested;
51280 + }
51281 + }
51282 +
51283 + return 0;
51284 +}
51285 +
51286 +static __u32
51287 +count_user_subjs(struct acl_subject_label *userp)
51288 +{
51289 + struct acl_subject_label s_tmp;
51290 + __u32 num = 0;
51291 +
51292 + while (userp) {
51293 + if (copy_from_user(&s_tmp, userp,
51294 + sizeof (struct acl_subject_label)))
51295 + break;
51296 +
51297 + userp = s_tmp.prev;
51298 + /* do not count nested subjects against this count, since
51299 + they are not included in the hash table, but are
51300 + attached to objects. We have already counted
51301 + the subjects in userspace for the allocation
51302 + stack
51303 + */
51304 + if (!(s_tmp.mode & GR_NESTED))
51305 + num++;
51306 + }
51307 +
51308 + return num;
51309 +}
51310 +
51311 +static int
51312 +copy_user_allowedips(struct acl_role_label *rolep)
51313 +{
51314 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51315 +
51316 + ruserip = rolep->allowed_ips;
51317 +
51318 + while (ruserip) {
51319 + rlast = rtmp;
51320 +
51321 + if ((rtmp = (struct role_allowed_ip *)
51322 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51323 + return -ENOMEM;
51324 +
51325 + if (copy_from_user(rtmp, ruserip,
51326 + sizeof (struct role_allowed_ip)))
51327 + return -EFAULT;
51328 +
51329 + ruserip = rtmp->prev;
51330 +
51331 + if (!rlast) {
51332 + rtmp->prev = NULL;
51333 + rolep->allowed_ips = rtmp;
51334 + } else {
51335 + rlast->next = rtmp;
51336 + rtmp->prev = rlast;
51337 + }
51338 +
51339 + if (!ruserip)
51340 + rtmp->next = NULL;
51341 + }
51342 +
51343 + return 0;
51344 +}
51345 +
51346 +static int
51347 +copy_user_transitions(struct acl_role_label *rolep)
51348 +{
51349 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51350 +
51351 + unsigned int len;
51352 + char *tmp;
51353 +
51354 + rusertp = rolep->transitions;
51355 +
51356 + while (rusertp) {
51357 + rlast = rtmp;
51358 +
51359 + if ((rtmp = (struct role_transition *)
51360 + acl_alloc(sizeof (struct role_transition))) == NULL)
51361 + return -ENOMEM;
51362 +
51363 + if (copy_from_user(rtmp, rusertp,
51364 + sizeof (struct role_transition)))
51365 + return -EFAULT;
51366 +
51367 + rusertp = rtmp->prev;
51368 +
51369 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51370 +
51371 + if (!len || len >= GR_SPROLE_LEN)
51372 + return -EINVAL;
51373 +
51374 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51375 + return -ENOMEM;
51376 +
51377 + if (copy_from_user(tmp, rtmp->rolename, len))
51378 + return -EFAULT;
51379 + tmp[len-1] = '\0';
51380 + rtmp->rolename = tmp;
51381 +
51382 + if (!rlast) {
51383 + rtmp->prev = NULL;
51384 + rolep->transitions = rtmp;
51385 + } else {
51386 + rlast->next = rtmp;
51387 + rtmp->prev = rlast;
51388 + }
51389 +
51390 + if (!rusertp)
51391 + rtmp->next = NULL;
51392 + }
51393 +
51394 + return 0;
51395 +}
51396 +
51397 +static struct acl_subject_label *
51398 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51399 +{
51400 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51401 + unsigned int len;
51402 + char *tmp;
51403 + __u32 num_objs;
51404 + struct acl_ip_label **i_tmp, *i_utmp2;
51405 + struct gr_hash_struct ghash;
51406 + struct subject_map *subjmap;
51407 + unsigned int i_num;
51408 + int err;
51409 +
51410 + s_tmp = lookup_subject_map(userp);
51411 +
51412 + /* we've already copied this subject into the kernel, just return
51413 + the reference to it, and don't copy it over again
51414 + */
51415 + if (s_tmp)
51416 + return(s_tmp);
51417 +
51418 + if ((s_tmp = (struct acl_subject_label *)
51419 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51420 + return ERR_PTR(-ENOMEM);
51421 +
51422 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51423 + if (subjmap == NULL)
51424 + return ERR_PTR(-ENOMEM);
51425 +
51426 + subjmap->user = userp;
51427 + subjmap->kernel = s_tmp;
51428 + insert_subj_map_entry(subjmap);
51429 +
51430 + if (copy_from_user(s_tmp, userp,
51431 + sizeof (struct acl_subject_label)))
51432 + return ERR_PTR(-EFAULT);
51433 +
51434 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51435 +
51436 + if (!len || len >= PATH_MAX)
51437 + return ERR_PTR(-EINVAL);
51438 +
51439 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51440 + return ERR_PTR(-ENOMEM);
51441 +
51442 + if (copy_from_user(tmp, s_tmp->filename, len))
51443 + return ERR_PTR(-EFAULT);
51444 + tmp[len-1] = '\0';
51445 + s_tmp->filename = tmp;
51446 +
51447 + if (!strcmp(s_tmp->filename, "/"))
51448 + role->root_label = s_tmp;
51449 +
51450 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51451 + return ERR_PTR(-EFAULT);
51452 +
51453 + /* copy user and group transition tables */
51454 +
51455 + if (s_tmp->user_trans_num) {
51456 + uid_t *uidlist;
51457 +
51458 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51459 + if (uidlist == NULL)
51460 + return ERR_PTR(-ENOMEM);
51461 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51462 + return ERR_PTR(-EFAULT);
51463 +
51464 + s_tmp->user_transitions = uidlist;
51465 + }
51466 +
51467 + if (s_tmp->group_trans_num) {
51468 + gid_t *gidlist;
51469 +
51470 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51471 + if (gidlist == NULL)
51472 + return ERR_PTR(-ENOMEM);
51473 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51474 + return ERR_PTR(-EFAULT);
51475 +
51476 + s_tmp->group_transitions = gidlist;
51477 + }
51478 +
51479 + /* set up object hash table */
51480 + num_objs = count_user_objs(ghash.first);
51481 +
51482 + s_tmp->obj_hash_size = num_objs;
51483 + s_tmp->obj_hash =
51484 + (struct acl_object_label **)
51485 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51486 +
51487 + if (!s_tmp->obj_hash)
51488 + return ERR_PTR(-ENOMEM);
51489 +
51490 + memset(s_tmp->obj_hash, 0,
51491 + s_tmp->obj_hash_size *
51492 + sizeof (struct acl_object_label *));
51493 +
51494 + /* add in objects */
51495 + err = copy_user_objs(ghash.first, s_tmp, role);
51496 +
51497 + if (err)
51498 + return ERR_PTR(err);
51499 +
51500 + /* set pointer for parent subject */
51501 + if (s_tmp->parent_subject) {
51502 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51503 +
51504 + if (IS_ERR(s_tmp2))
51505 + return s_tmp2;
51506 +
51507 + s_tmp->parent_subject = s_tmp2;
51508 + }
51509 +
51510 + /* add in ip acls */
51511 +
51512 + if (!s_tmp->ip_num) {
51513 + s_tmp->ips = NULL;
51514 + goto insert;
51515 + }
51516 +
51517 + i_tmp =
51518 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51519 + sizeof (struct acl_ip_label *));
51520 +
51521 + if (!i_tmp)
51522 + return ERR_PTR(-ENOMEM);
51523 +
51524 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51525 + *(i_tmp + i_num) =
51526 + (struct acl_ip_label *)
51527 + acl_alloc(sizeof (struct acl_ip_label));
51528 + if (!*(i_tmp + i_num))
51529 + return ERR_PTR(-ENOMEM);
51530 +
51531 + if (copy_from_user
51532 + (&i_utmp2, s_tmp->ips + i_num,
51533 + sizeof (struct acl_ip_label *)))
51534 + return ERR_PTR(-EFAULT);
51535 +
51536 + if (copy_from_user
51537 + (*(i_tmp + i_num), i_utmp2,
51538 + sizeof (struct acl_ip_label)))
51539 + return ERR_PTR(-EFAULT);
51540 +
51541 + if ((*(i_tmp + i_num))->iface == NULL)
51542 + continue;
51543 +
51544 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51545 + if (!len || len >= IFNAMSIZ)
51546 + return ERR_PTR(-EINVAL);
51547 + tmp = acl_alloc(len);
51548 + if (tmp == NULL)
51549 + return ERR_PTR(-ENOMEM);
51550 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51551 + return ERR_PTR(-EFAULT);
51552 + (*(i_tmp + i_num))->iface = tmp;
51553 + }
51554 +
51555 + s_tmp->ips = i_tmp;
51556 +
51557 +insert:
51558 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51559 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51560 + return ERR_PTR(-ENOMEM);
51561 +
51562 + return s_tmp;
51563 +}
51564 +
51565 +static int
51566 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51567 +{
51568 + struct acl_subject_label s_pre;
51569 + struct acl_subject_label * ret;
51570 + int err;
51571 +
51572 + while (userp) {
51573 + if (copy_from_user(&s_pre, userp,
51574 + sizeof (struct acl_subject_label)))
51575 + return -EFAULT;
51576 +
51577 + /* do not add nested subjects here, add
51578 + while parsing objects
51579 + */
51580 +
51581 + if (s_pre.mode & GR_NESTED) {
51582 + userp = s_pre.prev;
51583 + continue;
51584 + }
51585 +
51586 + ret = do_copy_user_subj(userp, role);
51587 +
51588 + err = PTR_ERR(ret);
51589 + if (IS_ERR(ret))
51590 + return err;
51591 +
51592 + insert_acl_subj_label(ret, role);
51593 +
51594 + userp = s_pre.prev;
51595 + }
51596 +
51597 + return 0;
51598 +}
51599 +
51600 +static int
51601 +copy_user_acl(struct gr_arg *arg)
51602 +{
51603 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51604 + struct sprole_pw *sptmp;
51605 + struct gr_hash_struct *ghash;
51606 + uid_t *domainlist;
51607 + unsigned int r_num;
51608 + unsigned int len;
51609 + char *tmp;
51610 + int err = 0;
51611 + __u16 i;
51612 + __u32 num_subjs;
51613 +
51614 + /* we need a default and kernel role */
51615 + if (arg->role_db.num_roles < 2)
51616 + return -EINVAL;
51617 +
51618 + /* copy special role authentication info from userspace */
51619 +
51620 + num_sprole_pws = arg->num_sprole_pws;
51621 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51622 +
51623 + if (!acl_special_roles && num_sprole_pws)
51624 + return -ENOMEM;
51625 +
51626 + for (i = 0; i < num_sprole_pws; i++) {
51627 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51628 + if (!sptmp)
51629 + return -ENOMEM;
51630 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51631 + sizeof (struct sprole_pw)))
51632 + return -EFAULT;
51633 +
51634 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51635 +
51636 + if (!len || len >= GR_SPROLE_LEN)
51637 + return -EINVAL;
51638 +
51639 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51640 + return -ENOMEM;
51641 +
51642 + if (copy_from_user(tmp, sptmp->rolename, len))
51643 + return -EFAULT;
51644 +
51645 + tmp[len-1] = '\0';
51646 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51647 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51648 +#endif
51649 + sptmp->rolename = tmp;
51650 + acl_special_roles[i] = sptmp;
51651 + }
51652 +
51653 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51654 +
51655 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51656 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51657 +
51658 + if (!r_tmp)
51659 + return -ENOMEM;
51660 +
51661 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51662 + sizeof (struct acl_role_label *)))
51663 + return -EFAULT;
51664 +
51665 + if (copy_from_user(r_tmp, r_utmp2,
51666 + sizeof (struct acl_role_label)))
51667 + return -EFAULT;
51668 +
51669 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51670 +
51671 + if (!len || len >= PATH_MAX)
51672 + return -EINVAL;
51673 +
51674 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51675 + return -ENOMEM;
51676 +
51677 + if (copy_from_user(tmp, r_tmp->rolename, len))
51678 + return -EFAULT;
51679 +
51680 + tmp[len-1] = '\0';
51681 + r_tmp->rolename = tmp;
51682 +
51683 + if (!strcmp(r_tmp->rolename, "default")
51684 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51685 + default_role = r_tmp;
51686 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51687 + kernel_role = r_tmp;
51688 + }
51689 +
51690 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51691 + return -ENOMEM;
51692 +
51693 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51694 + return -EFAULT;
51695 +
51696 + r_tmp->hash = ghash;
51697 +
51698 + num_subjs = count_user_subjs(r_tmp->hash->first);
51699 +
51700 + r_tmp->subj_hash_size = num_subjs;
51701 + r_tmp->subj_hash =
51702 + (struct acl_subject_label **)
51703 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51704 +
51705 + if (!r_tmp->subj_hash)
51706 + return -ENOMEM;
51707 +
51708 + err = copy_user_allowedips(r_tmp);
51709 + if (err)
51710 + return err;
51711 +
51712 + /* copy domain info */
51713 + if (r_tmp->domain_children != NULL) {
51714 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51715 + if (domainlist == NULL)
51716 + return -ENOMEM;
51717 +
51718 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51719 + return -EFAULT;
51720 +
51721 + r_tmp->domain_children = domainlist;
51722 + }
51723 +
51724 + err = copy_user_transitions(r_tmp);
51725 + if (err)
51726 + return err;
51727 +
51728 + memset(r_tmp->subj_hash, 0,
51729 + r_tmp->subj_hash_size *
51730 + sizeof (struct acl_subject_label *));
51731 +
51732 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51733 +
51734 + if (err)
51735 + return err;
51736 +
51737 + /* set nested subject list to null */
51738 + r_tmp->hash->first = NULL;
51739 +
51740 + insert_acl_role_label(r_tmp);
51741 + }
51742 +
51743 + if (default_role == NULL || kernel_role == NULL)
51744 + return -EINVAL;
51745 +
51746 + return err;
51747 +}
51748 +
51749 +static int
51750 +gracl_init(struct gr_arg *args)
51751 +{
51752 + int error = 0;
51753 +
51754 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51755 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51756 +
51757 + if (init_variables(args)) {
51758 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51759 + error = -ENOMEM;
51760 + free_variables();
51761 + goto out;
51762 + }
51763 +
51764 + error = copy_user_acl(args);
51765 + free_init_variables();
51766 + if (error) {
51767 + free_variables();
51768 + goto out;
51769 + }
51770 +
51771 + if ((error = gr_set_acls(0))) {
51772 + free_variables();
51773 + goto out;
51774 + }
51775 +
51776 + pax_open_kernel();
51777 + gr_status |= GR_READY;
51778 + pax_close_kernel();
51779 +
51780 + out:
51781 + return error;
51782 +}
51783 +
51784 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51785 +
51786 +static int
51787 +glob_match(const char *p, const char *n)
51788 +{
51789 + char c;
51790 +
51791 + while ((c = *p++) != '\0') {
51792 + switch (c) {
51793 + case '?':
51794 + if (*n == '\0')
51795 + return 1;
51796 + else if (*n == '/')
51797 + return 1;
51798 + break;
51799 + case '\\':
51800 + if (*n != c)
51801 + return 1;
51802 + break;
51803 + case '*':
51804 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51805 + if (*n == '/')
51806 + return 1;
51807 + else if (c == '?') {
51808 + if (*n == '\0')
51809 + return 1;
51810 + else
51811 + ++n;
51812 + }
51813 + }
51814 + if (c == '\0') {
51815 + return 0;
51816 + } else {
51817 + const char *endp;
51818 +
51819 + if ((endp = strchr(n, '/')) == NULL)
51820 + endp = n + strlen(n);
51821 +
51822 + if (c == '[') {
51823 + for (--p; n < endp; ++n)
51824 + if (!glob_match(p, n))
51825 + return 0;
51826 + } else if (c == '/') {
51827 + while (*n != '\0' && *n != '/')
51828 + ++n;
51829 + if (*n == '/' && !glob_match(p, n + 1))
51830 + return 0;
51831 + } else {
51832 + for (--p; n < endp; ++n)
51833 + if (*n == c && !glob_match(p, n))
51834 + return 0;
51835 + }
51836 +
51837 + return 1;
51838 + }
51839 + case '[':
51840 + {
51841 + int not;
51842 + char cold;
51843 +
51844 + if (*n == '\0' || *n == '/')
51845 + return 1;
51846 +
51847 + not = (*p == '!' || *p == '^');
51848 + if (not)
51849 + ++p;
51850 +
51851 + c = *p++;
51852 + for (;;) {
51853 + unsigned char fn = (unsigned char)*n;
51854 +
51855 + if (c == '\0')
51856 + return 1;
51857 + else {
51858 + if (c == fn)
51859 + goto matched;
51860 + cold = c;
51861 + c = *p++;
51862 +
51863 + if (c == '-' && *p != ']') {
51864 + unsigned char cend = *p++;
51865 +
51866 + if (cend == '\0')
51867 + return 1;
51868 +
51869 + if (cold <= fn && fn <= cend)
51870 + goto matched;
51871 +
51872 + c = *p++;
51873 + }
51874 + }
51875 +
51876 + if (c == ']')
51877 + break;
51878 + }
51879 + if (!not)
51880 + return 1;
51881 + break;
51882 + matched:
51883 + while (c != ']') {
51884 + if (c == '\0')
51885 + return 1;
51886 +
51887 + c = *p++;
51888 + }
51889 + if (not)
51890 + return 1;
51891 + }
51892 + break;
51893 + default:
51894 + if (c != *n)
51895 + return 1;
51896 + }
51897 +
51898 + ++n;
51899 + }
51900 +
51901 + if (*n == '\0')
51902 + return 0;
51903 +
51904 + if (*n == '/')
51905 + return 0;
51906 +
51907 + return 1;
51908 +}
51909 +
51910 +static struct acl_object_label *
51911 +chk_glob_label(struct acl_object_label *globbed,
51912 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51913 +{
51914 + struct acl_object_label *tmp;
51915 +
51916 + if (*path == NULL)
51917 + *path = gr_to_filename_nolock(dentry, mnt);
51918 +
51919 + tmp = globbed;
51920 +
51921 + while (tmp) {
51922 + if (!glob_match(tmp->filename, *path))
51923 + return tmp;
51924 + tmp = tmp->next;
51925 + }
51926 +
51927 + return NULL;
51928 +}
51929 +
51930 +static struct acl_object_label *
51931 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51932 + const ino_t curr_ino, const dev_t curr_dev,
51933 + const struct acl_subject_label *subj, char **path, const int checkglob)
51934 +{
51935 + struct acl_subject_label *tmpsubj;
51936 + struct acl_object_label *retval;
51937 + struct acl_object_label *retval2;
51938 +
51939 + tmpsubj = (struct acl_subject_label *) subj;
51940 + read_lock(&gr_inode_lock);
51941 + do {
51942 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51943 + if (retval) {
51944 + if (checkglob && retval->globbed) {
51945 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51946 + if (retval2)
51947 + retval = retval2;
51948 + }
51949 + break;
51950 + }
51951 + } while ((tmpsubj = tmpsubj->parent_subject));
51952 + read_unlock(&gr_inode_lock);
51953 +
51954 + return retval;
51955 +}
51956 +
51957 +static __inline__ struct acl_object_label *
51958 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51959 + struct dentry *curr_dentry,
51960 + const struct acl_subject_label *subj, char **path, const int checkglob)
51961 +{
51962 + int newglob = checkglob;
51963 + ino_t inode;
51964 + dev_t device;
51965 +
51966 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51967 + as we don't want a / * rule to match instead of the / object
51968 + don't do this for create lookups that call this function though, since they're looking up
51969 + on the parent and thus need globbing checks on all paths
51970 + */
51971 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51972 + newglob = GR_NO_GLOB;
51973 +
51974 + spin_lock(&curr_dentry->d_lock);
51975 + inode = curr_dentry->d_inode->i_ino;
51976 + device = __get_dev(curr_dentry);
51977 + spin_unlock(&curr_dentry->d_lock);
51978 +
51979 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51980 +}
51981 +
51982 +static struct acl_object_label *
51983 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51984 + const struct acl_subject_label *subj, char *path, const int checkglob)
51985 +{
51986 + struct dentry *dentry = (struct dentry *) l_dentry;
51987 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51988 + struct mount *real_mnt = real_mount(mnt);
51989 + struct acl_object_label *retval;
51990 + struct dentry *parent;
51991 +
51992 + write_seqlock(&rename_lock);
51993 + br_read_lock(vfsmount_lock);
51994 +
51995 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
51996 +#ifdef CONFIG_NET
51997 + mnt == sock_mnt ||
51998 +#endif
51999 +#ifdef CONFIG_HUGETLBFS
52000 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52001 +#endif
52002 + /* ignore Eric Biederman */
52003 + IS_PRIVATE(l_dentry->d_inode))) {
52004 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52005 + goto out;
52006 + }
52007 +
52008 + for (;;) {
52009 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52010 + break;
52011 +
52012 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52013 + if (!mnt_has_parent(real_mnt))
52014 + break;
52015 +
52016 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52017 + if (retval != NULL)
52018 + goto out;
52019 +
52020 + dentry = real_mnt->mnt_mountpoint;
52021 + real_mnt = real_mnt->mnt_parent;
52022 + mnt = &real_mnt->mnt;
52023 + continue;
52024 + }
52025 +
52026 + parent = dentry->d_parent;
52027 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52028 + if (retval != NULL)
52029 + goto out;
52030 +
52031 + dentry = parent;
52032 + }
52033 +
52034 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52035 +
52036 + /* real_root is pinned so we don't have to hold a reference */
52037 + if (retval == NULL)
52038 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52039 +out:
52040 + br_read_unlock(vfsmount_lock);
52041 + write_sequnlock(&rename_lock);
52042 +
52043 + BUG_ON(retval == NULL);
52044 +
52045 + return retval;
52046 +}
52047 +
52048 +static __inline__ struct acl_object_label *
52049 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52050 + const struct acl_subject_label *subj)
52051 +{
52052 + char *path = NULL;
52053 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52054 +}
52055 +
52056 +static __inline__ struct acl_object_label *
52057 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52058 + const struct acl_subject_label *subj)
52059 +{
52060 + char *path = NULL;
52061 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52062 +}
52063 +
52064 +static __inline__ struct acl_object_label *
52065 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52066 + const struct acl_subject_label *subj, char *path)
52067 +{
52068 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52069 +}
52070 +
52071 +static struct acl_subject_label *
52072 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52073 + const struct acl_role_label *role)
52074 +{
52075 + struct dentry *dentry = (struct dentry *) l_dentry;
52076 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52077 + struct mount *real_mnt = real_mount(mnt);
52078 + struct acl_subject_label *retval;
52079 + struct dentry *parent;
52080 +
52081 + write_seqlock(&rename_lock);
52082 + br_read_lock(vfsmount_lock);
52083 +
52084 + for (;;) {
52085 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52086 + break;
52087 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52088 + if (!mnt_has_parent(real_mnt))
52089 + break;
52090 +
52091 + spin_lock(&dentry->d_lock);
52092 + read_lock(&gr_inode_lock);
52093 + retval =
52094 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52095 + __get_dev(dentry), role);
52096 + read_unlock(&gr_inode_lock);
52097 + spin_unlock(&dentry->d_lock);
52098 + if (retval != NULL)
52099 + goto out;
52100 +
52101 + dentry = real_mnt->mnt_mountpoint;
52102 + real_mnt = real_mnt->mnt_parent;
52103 + mnt = &real_mnt->mnt;
52104 + continue;
52105 + }
52106 +
52107 + spin_lock(&dentry->d_lock);
52108 + read_lock(&gr_inode_lock);
52109 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52110 + __get_dev(dentry), role);
52111 + read_unlock(&gr_inode_lock);
52112 + parent = dentry->d_parent;
52113 + spin_unlock(&dentry->d_lock);
52114 +
52115 + if (retval != NULL)
52116 + goto out;
52117 +
52118 + dentry = parent;
52119 + }
52120 +
52121 + spin_lock(&dentry->d_lock);
52122 + read_lock(&gr_inode_lock);
52123 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52124 + __get_dev(dentry), role);
52125 + read_unlock(&gr_inode_lock);
52126 + spin_unlock(&dentry->d_lock);
52127 +
52128 + if (unlikely(retval == NULL)) {
52129 + /* real_root is pinned, we don't need to hold a reference */
52130 + read_lock(&gr_inode_lock);
52131 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52132 + __get_dev(real_root.dentry), role);
52133 + read_unlock(&gr_inode_lock);
52134 + }
52135 +out:
52136 + br_read_unlock(vfsmount_lock);
52137 + write_sequnlock(&rename_lock);
52138 +
52139 + BUG_ON(retval == NULL);
52140 +
52141 + return retval;
52142 +}
52143 +
52144 +static void
52145 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52146 +{
52147 + struct task_struct *task = current;
52148 + const struct cred *cred = current_cred();
52149 +
52150 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52151 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52152 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52153 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52154 +
52155 + return;
52156 +}
52157 +
52158 +static void
52159 +gr_log_learn_id_change(const char type, const unsigned int real,
52160 + const unsigned int effective, const unsigned int fs)
52161 +{
52162 + struct task_struct *task = current;
52163 + const struct cred *cred = current_cred();
52164 +
52165 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52166 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52167 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52168 + type, real, effective, fs, &task->signal->saved_ip);
52169 +
52170 + return;
52171 +}
52172 +
52173 +__u32
52174 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52175 + const struct vfsmount * mnt)
52176 +{
52177 + __u32 retval = mode;
52178 + struct acl_subject_label *curracl;
52179 + struct acl_object_label *currobj;
52180 +
52181 + if (unlikely(!(gr_status & GR_READY)))
52182 + return (mode & ~GR_AUDITS);
52183 +
52184 + curracl = current->acl;
52185 +
52186 + currobj = chk_obj_label(dentry, mnt, curracl);
52187 + retval = currobj->mode & mode;
52188 +
52189 + /* if we're opening a specified transfer file for writing
52190 + (e.g. /dev/initctl), then transfer our role to init
52191 + */
52192 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52193 + current->role->roletype & GR_ROLE_PERSIST)) {
52194 + struct task_struct *task = init_pid_ns.child_reaper;
52195 +
52196 + if (task->role != current->role) {
52197 + task->acl_sp_role = 0;
52198 + task->acl_role_id = current->acl_role_id;
52199 + task->role = current->role;
52200 + rcu_read_lock();
52201 + read_lock(&grsec_exec_file_lock);
52202 + gr_apply_subject_to_task(task);
52203 + read_unlock(&grsec_exec_file_lock);
52204 + rcu_read_unlock();
52205 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52206 + }
52207 + }
52208 +
52209 + if (unlikely
52210 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52211 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52212 + __u32 new_mode = mode;
52213 +
52214 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52215 +
52216 + retval = new_mode;
52217 +
52218 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52219 + new_mode |= GR_INHERIT;
52220 +
52221 + if (!(mode & GR_NOLEARN))
52222 + gr_log_learn(dentry, mnt, new_mode);
52223 + }
52224 +
52225 + return retval;
52226 +}
52227 +
52228 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52229 + const struct dentry *parent,
52230 + const struct vfsmount *mnt)
52231 +{
52232 + struct name_entry *match;
52233 + struct acl_object_label *matchpo;
52234 + struct acl_subject_label *curracl;
52235 + char *path;
52236 +
52237 + if (unlikely(!(gr_status & GR_READY)))
52238 + return NULL;
52239 +
52240 + preempt_disable();
52241 + path = gr_to_filename_rbac(new_dentry, mnt);
52242 + match = lookup_name_entry_create(path);
52243 +
52244 + curracl = current->acl;
52245 +
52246 + if (match) {
52247 + read_lock(&gr_inode_lock);
52248 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52249 + read_unlock(&gr_inode_lock);
52250 +
52251 + if (matchpo) {
52252 + preempt_enable();
52253 + return matchpo;
52254 + }
52255 + }
52256 +
52257 + // lookup parent
52258 +
52259 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52260 +
52261 + preempt_enable();
52262 + return matchpo;
52263 +}
52264 +
52265 +__u32
52266 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52267 + const struct vfsmount * mnt, const __u32 mode)
52268 +{
52269 + struct acl_object_label *matchpo;
52270 + __u32 retval;
52271 +
52272 + if (unlikely(!(gr_status & GR_READY)))
52273 + return (mode & ~GR_AUDITS);
52274 +
52275 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52276 +
52277 + retval = matchpo->mode & mode;
52278 +
52279 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52280 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52281 + __u32 new_mode = mode;
52282 +
52283 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52284 +
52285 + gr_log_learn(new_dentry, mnt, new_mode);
52286 + return new_mode;
52287 + }
52288 +
52289 + return retval;
52290 +}
52291 +
52292 +__u32
52293 +gr_check_link(const struct dentry * new_dentry,
52294 + const struct dentry * parent_dentry,
52295 + const struct vfsmount * parent_mnt,
52296 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52297 +{
52298 + struct acl_object_label *obj;
52299 + __u32 oldmode, newmode;
52300 + __u32 needmode;
52301 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52302 + GR_DELETE | GR_INHERIT;
52303 +
52304 + if (unlikely(!(gr_status & GR_READY)))
52305 + return (GR_CREATE | GR_LINK);
52306 +
52307 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52308 + oldmode = obj->mode;
52309 +
52310 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52311 + newmode = obj->mode;
52312 +
52313 + needmode = newmode & checkmodes;
52314 +
52315 + // old name for hardlink must have at least the permissions of the new name
52316 + if ((oldmode & needmode) != needmode)
52317 + goto bad;
52318 +
52319 + // if old name had restrictions/auditing, make sure the new name does as well
52320 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52321 +
52322 + // don't allow hardlinking of suid/sgid files without permission
52323 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52324 + needmode |= GR_SETID;
52325 +
52326 + if ((newmode & needmode) != needmode)
52327 + goto bad;
52328 +
52329 + // enforce minimum permissions
52330 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52331 + return newmode;
52332 +bad:
52333 + needmode = oldmode;
52334 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52335 + needmode |= GR_SETID;
52336 +
52337 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52338 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52339 + return (GR_CREATE | GR_LINK);
52340 + } else if (newmode & GR_SUPPRESS)
52341 + return GR_SUPPRESS;
52342 + else
52343 + return 0;
52344 +}
52345 +
52346 +int
52347 +gr_check_hidden_task(const struct task_struct *task)
52348 +{
52349 + if (unlikely(!(gr_status & GR_READY)))
52350 + return 0;
52351 +
52352 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52353 + return 1;
52354 +
52355 + return 0;
52356 +}
52357 +
52358 +int
52359 +gr_check_protected_task(const struct task_struct *task)
52360 +{
52361 + if (unlikely(!(gr_status & GR_READY) || !task))
52362 + return 0;
52363 +
52364 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52365 + task->acl != current->acl)
52366 + return 1;
52367 +
52368 + return 0;
52369 +}
52370 +
52371 +int
52372 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52373 +{
52374 + struct task_struct *p;
52375 + int ret = 0;
52376 +
52377 + if (unlikely(!(gr_status & GR_READY) || !pid))
52378 + return ret;
52379 +
52380 + read_lock(&tasklist_lock);
52381 + do_each_pid_task(pid, type, p) {
52382 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52383 + p->acl != current->acl) {
52384 + ret = 1;
52385 + goto out;
52386 + }
52387 + } while_each_pid_task(pid, type, p);
52388 +out:
52389 + read_unlock(&tasklist_lock);
52390 +
52391 + return ret;
52392 +}
52393 +
52394 +void
52395 +gr_copy_label(struct task_struct *tsk)
52396 +{
52397 + tsk->signal->used_accept = 0;
52398 + tsk->acl_sp_role = 0;
52399 + tsk->acl_role_id = current->acl_role_id;
52400 + tsk->acl = current->acl;
52401 + tsk->role = current->role;
52402 + tsk->signal->curr_ip = current->signal->curr_ip;
52403 + tsk->signal->saved_ip = current->signal->saved_ip;
52404 + if (current->exec_file)
52405 + get_file(current->exec_file);
52406 + tsk->exec_file = current->exec_file;
52407 + tsk->is_writable = current->is_writable;
52408 + if (unlikely(current->signal->used_accept)) {
52409 + current->signal->curr_ip = 0;
52410 + current->signal->saved_ip = 0;
52411 + }
52412 +
52413 + return;
52414 +}
52415 +
52416 +static void
52417 +gr_set_proc_res(struct task_struct *task)
52418 +{
52419 + struct acl_subject_label *proc;
52420 + unsigned short i;
52421 +
52422 + proc = task->acl;
52423 +
52424 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52425 + return;
52426 +
52427 + for (i = 0; i < RLIM_NLIMITS; i++) {
52428 + if (!(proc->resmask & (1 << i)))
52429 + continue;
52430 +
52431 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52432 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52433 + }
52434 +
52435 + return;
52436 +}
52437 +
52438 +extern int __gr_process_user_ban(struct user_struct *user);
52439 +
52440 +int
52441 +gr_check_user_change(int real, int effective, int fs)
52442 +{
52443 + unsigned int i;
52444 + __u16 num;
52445 + uid_t *uidlist;
52446 + int curuid;
52447 + int realok = 0;
52448 + int effectiveok = 0;
52449 + int fsok = 0;
52450 +
52451 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52452 + struct user_struct *user;
52453 +
52454 + if (real == -1)
52455 + goto skipit;
52456 +
52457 + user = find_user(real);
52458 + if (user == NULL)
52459 + goto skipit;
52460 +
52461 + if (__gr_process_user_ban(user)) {
52462 + /* for find_user */
52463 + free_uid(user);
52464 + return 1;
52465 + }
52466 +
52467 + /* for find_user */
52468 + free_uid(user);
52469 +
52470 +skipit:
52471 +#endif
52472 +
52473 + if (unlikely(!(gr_status & GR_READY)))
52474 + return 0;
52475 +
52476 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52477 + gr_log_learn_id_change('u', real, effective, fs);
52478 +
52479 + num = current->acl->user_trans_num;
52480 + uidlist = current->acl->user_transitions;
52481 +
52482 + if (uidlist == NULL)
52483 + return 0;
52484 +
52485 + if (real == -1)
52486 + realok = 1;
52487 + if (effective == -1)
52488 + effectiveok = 1;
52489 + if (fs == -1)
52490 + fsok = 1;
52491 +
52492 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52493 + for (i = 0; i < num; i++) {
52494 + curuid = (int)uidlist[i];
52495 + if (real == curuid)
52496 + realok = 1;
52497 + if (effective == curuid)
52498 + effectiveok = 1;
52499 + if (fs == curuid)
52500 + fsok = 1;
52501 + }
52502 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52503 + for (i = 0; i < num; i++) {
52504 + curuid = (int)uidlist[i];
52505 + if (real == curuid)
52506 + break;
52507 + if (effective == curuid)
52508 + break;
52509 + if (fs == curuid)
52510 + break;
52511 + }
52512 + /* not in deny list */
52513 + if (i == num) {
52514 + realok = 1;
52515 + effectiveok = 1;
52516 + fsok = 1;
52517 + }
52518 + }
52519 +
52520 + if (realok && effectiveok && fsok)
52521 + return 0;
52522 + else {
52523 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52524 + return 1;
52525 + }
52526 +}
52527 +
52528 +int
52529 +gr_check_group_change(int real, int effective, int fs)
52530 +{
52531 + unsigned int i;
52532 + __u16 num;
52533 + gid_t *gidlist;
52534 + int curgid;
52535 + int realok = 0;
52536 + int effectiveok = 0;
52537 + int fsok = 0;
52538 +
52539 + if (unlikely(!(gr_status & GR_READY)))
52540 + return 0;
52541 +
52542 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52543 + gr_log_learn_id_change('g', real, effective, fs);
52544 +
52545 + num = current->acl->group_trans_num;
52546 + gidlist = current->acl->group_transitions;
52547 +
52548 + if (gidlist == NULL)
52549 + return 0;
52550 +
52551 + if (real == -1)
52552 + realok = 1;
52553 + if (effective == -1)
52554 + effectiveok = 1;
52555 + if (fs == -1)
52556 + fsok = 1;
52557 +
52558 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
52559 + for (i = 0; i < num; i++) {
52560 + curgid = (int)gidlist[i];
52561 + if (real == curgid)
52562 + realok = 1;
52563 + if (effective == curgid)
52564 + effectiveok = 1;
52565 + if (fs == curgid)
52566 + fsok = 1;
52567 + }
52568 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52569 + for (i = 0; i < num; i++) {
52570 + curgid = (int)gidlist[i];
52571 + if (real == curgid)
52572 + break;
52573 + if (effective == curgid)
52574 + break;
52575 + if (fs == curgid)
52576 + break;
52577 + }
52578 + /* not in deny list */
52579 + if (i == num) {
52580 + realok = 1;
52581 + effectiveok = 1;
52582 + fsok = 1;
52583 + }
52584 + }
52585 +
52586 + if (realok && effectiveok && fsok)
52587 + return 0;
52588 + else {
52589 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52590 + return 1;
52591 + }
52592 +}
52593 +
52594 +extern int gr_acl_is_capable(const int cap);
52595 +
52596 +void
52597 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52598 +{
52599 + struct acl_role_label *role = task->role;
52600 + struct acl_subject_label *subj = NULL;
52601 + struct acl_object_label *obj;
52602 + struct file *filp;
52603 +
52604 + if (unlikely(!(gr_status & GR_READY)))
52605 + return;
52606 +
52607 + filp = task->exec_file;
52608 +
52609 + /* kernel process, we'll give them the kernel role */
52610 + if (unlikely(!filp)) {
52611 + task->role = kernel_role;
52612 + task->acl = kernel_role->root_label;
52613 + return;
52614 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52615 + role = lookup_acl_role_label(task, uid, gid);
52616 +
52617 + /* don't change the role if we're not a privileged process */
52618 + if (role && task->role != role &&
52619 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52620 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52621 + return;
52622 +
52623 + /* perform subject lookup in possibly new role
52624 + we can use this result below in the case where role == task->role
52625 + */
52626 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52627 +
52628 + /* if we changed uid/gid, but result in the same role
52629 + and are using inheritance, don't lose the inherited subject
52630 + if current subject is other than what normal lookup
52631 + would result in, we arrived via inheritance, don't
52632 + lose subject
52633 + */
52634 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52635 + (subj == task->acl)))
52636 + task->acl = subj;
52637 +
52638 + task->role = role;
52639 +
52640 + task->is_writable = 0;
52641 +
52642 + /* ignore additional mmap checks for processes that are writable
52643 + by the default ACL */
52644 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52645 + if (unlikely(obj->mode & GR_WRITE))
52646 + task->is_writable = 1;
52647 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52648 + if (unlikely(obj->mode & GR_WRITE))
52649 + task->is_writable = 1;
52650 +
52651 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52652 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52653 +#endif
52654 +
52655 + gr_set_proc_res(task);
52656 +
52657 + return;
52658 +}
52659 +
52660 +int
52661 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52662 + const int unsafe_flags)
52663 +{
52664 + struct task_struct *task = current;
52665 + struct acl_subject_label *newacl;
52666 + struct acl_object_label *obj;
52667 + __u32 retmode;
52668 +
52669 + if (unlikely(!(gr_status & GR_READY)))
52670 + return 0;
52671 +
52672 + newacl = chk_subj_label(dentry, mnt, task->role);
52673 +
52674 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
52675 + did an exec
52676 + */
52677 + rcu_read_lock();
52678 + read_lock(&tasklist_lock);
52679 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
52680 + (task->parent->acl->mode & GR_POVERRIDE))) {
52681 + read_unlock(&tasklist_lock);
52682 + rcu_read_unlock();
52683 + goto skip_check;
52684 + }
52685 + read_unlock(&tasklist_lock);
52686 + rcu_read_unlock();
52687 +
52688 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52689 + !(task->role->roletype & GR_ROLE_GOD) &&
52690 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52691 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52692 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52693 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52694 + else
52695 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52696 + return -EACCES;
52697 + }
52698 +
52699 +skip_check:
52700 +
52701 + obj = chk_obj_label(dentry, mnt, task->acl);
52702 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52703 +
52704 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52705 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52706 + if (obj->nested)
52707 + task->acl = obj->nested;
52708 + else
52709 + task->acl = newacl;
52710 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52711 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52712 +
52713 + task->is_writable = 0;
52714 +
52715 + /* ignore additional mmap checks for processes that are writable
52716 + by the default ACL */
52717 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52718 + if (unlikely(obj->mode & GR_WRITE))
52719 + task->is_writable = 1;
52720 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52721 + if (unlikely(obj->mode & GR_WRITE))
52722 + task->is_writable = 1;
52723 +
52724 + gr_set_proc_res(task);
52725 +
52726 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52727 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52728 +#endif
52729 + return 0;
52730 +}
52731 +
52732 +/* always called with valid inodev ptr */
52733 +static void
52734 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52735 +{
52736 + struct acl_object_label *matchpo;
52737 + struct acl_subject_label *matchps;
52738 + struct acl_subject_label *subj;
52739 + struct acl_role_label *role;
52740 + unsigned int x;
52741 +
52742 + FOR_EACH_ROLE_START(role)
52743 + FOR_EACH_SUBJECT_START(role, subj, x)
52744 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52745 + matchpo->mode |= GR_DELETED;
52746 + FOR_EACH_SUBJECT_END(subj,x)
52747 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52748 + if (subj->inode == ino && subj->device == dev)
52749 + subj->mode |= GR_DELETED;
52750 + FOR_EACH_NESTED_SUBJECT_END(subj)
52751 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52752 + matchps->mode |= GR_DELETED;
52753 + FOR_EACH_ROLE_END(role)
52754 +
52755 + inodev->nentry->deleted = 1;
52756 +
52757 + return;
52758 +}
52759 +
52760 +void
52761 +gr_handle_delete(const ino_t ino, const dev_t dev)
52762 +{
52763 + struct inodev_entry *inodev;
52764 +
52765 + if (unlikely(!(gr_status & GR_READY)))
52766 + return;
52767 +
52768 + write_lock(&gr_inode_lock);
52769 + inodev = lookup_inodev_entry(ino, dev);
52770 + if (inodev != NULL)
52771 + do_handle_delete(inodev, ino, dev);
52772 + write_unlock(&gr_inode_lock);
52773 +
52774 + return;
52775 +}
52776 +
52777 +static void
52778 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52779 + const ino_t newinode, const dev_t newdevice,
52780 + struct acl_subject_label *subj)
52781 +{
52782 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52783 + struct acl_object_label *match;
52784 +
52785 + match = subj->obj_hash[index];
52786 +
52787 + while (match && (match->inode != oldinode ||
52788 + match->device != olddevice ||
52789 + !(match->mode & GR_DELETED)))
52790 + match = match->next;
52791 +
52792 + if (match && (match->inode == oldinode)
52793 + && (match->device == olddevice)
52794 + && (match->mode & GR_DELETED)) {
52795 + if (match->prev == NULL) {
52796 + subj->obj_hash[index] = match->next;
52797 + if (match->next != NULL)
52798 + match->next->prev = NULL;
52799 + } else {
52800 + match->prev->next = match->next;
52801 + if (match->next != NULL)
52802 + match->next->prev = match->prev;
52803 + }
52804 + match->prev = NULL;
52805 + match->next = NULL;
52806 + match->inode = newinode;
52807 + match->device = newdevice;
52808 + match->mode &= ~GR_DELETED;
52809 +
52810 + insert_acl_obj_label(match, subj);
52811 + }
52812 +
52813 + return;
52814 +}
52815 +
52816 +static void
52817 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52818 + const ino_t newinode, const dev_t newdevice,
52819 + struct acl_role_label *role)
52820 +{
52821 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52822 + struct acl_subject_label *match;
52823 +
52824 + match = role->subj_hash[index];
52825 +
52826 + while (match && (match->inode != oldinode ||
52827 + match->device != olddevice ||
52828 + !(match->mode & GR_DELETED)))
52829 + match = match->next;
52830 +
52831 + if (match && (match->inode == oldinode)
52832 + && (match->device == olddevice)
52833 + && (match->mode & GR_DELETED)) {
52834 + if (match->prev == NULL) {
52835 + role->subj_hash[index] = match->next;
52836 + if (match->next != NULL)
52837 + match->next->prev = NULL;
52838 + } else {
52839 + match->prev->next = match->next;
52840 + if (match->next != NULL)
52841 + match->next->prev = match->prev;
52842 + }
52843 + match->prev = NULL;
52844 + match->next = NULL;
52845 + match->inode = newinode;
52846 + match->device = newdevice;
52847 + match->mode &= ~GR_DELETED;
52848 +
52849 + insert_acl_subj_label(match, role);
52850 + }
52851 +
52852 + return;
52853 +}
52854 +
52855 +static void
52856 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52857 + const ino_t newinode, const dev_t newdevice)
52858 +{
52859 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52860 + struct inodev_entry *match;
52861 +
52862 + match = inodev_set.i_hash[index];
52863 +
52864 + while (match && (match->nentry->inode != oldinode ||
52865 + match->nentry->device != olddevice || !match->nentry->deleted))
52866 + match = match->next;
52867 +
52868 + if (match && (match->nentry->inode == oldinode)
52869 + && (match->nentry->device == olddevice) &&
52870 + match->nentry->deleted) {
52871 + if (match->prev == NULL) {
52872 + inodev_set.i_hash[index] = match->next;
52873 + if (match->next != NULL)
52874 + match->next->prev = NULL;
52875 + } else {
52876 + match->prev->next = match->next;
52877 + if (match->next != NULL)
52878 + match->next->prev = match->prev;
52879 + }
52880 + match->prev = NULL;
52881 + match->next = NULL;
52882 + match->nentry->inode = newinode;
52883 + match->nentry->device = newdevice;
52884 + match->nentry->deleted = 0;
52885 +
52886 + insert_inodev_entry(match);
52887 + }
52888 +
52889 + return;
52890 +}
52891 +
52892 +static void
52893 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52894 +{
52895 + struct acl_subject_label *subj;
52896 + struct acl_role_label *role;
52897 + unsigned int x;
52898 +
52899 + FOR_EACH_ROLE_START(role)
52900 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52901 +
52902 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52903 + if ((subj->inode == ino) && (subj->device == dev)) {
52904 + subj->inode = ino;
52905 + subj->device = dev;
52906 + }
52907 + FOR_EACH_NESTED_SUBJECT_END(subj)
52908 + FOR_EACH_SUBJECT_START(role, subj, x)
52909 + update_acl_obj_label(matchn->inode, matchn->device,
52910 + ino, dev, subj);
52911 + FOR_EACH_SUBJECT_END(subj,x)
52912 + FOR_EACH_ROLE_END(role)
52913 +
52914 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52915 +
52916 + return;
52917 +}
52918 +
52919 +static void
52920 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52921 + const struct vfsmount *mnt)
52922 +{
52923 + ino_t ino = dentry->d_inode->i_ino;
52924 + dev_t dev = __get_dev(dentry);
52925 +
52926 + __do_handle_create(matchn, ino, dev);
52927 +
52928 + return;
52929 +}
52930 +
52931 +void
52932 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52933 +{
52934 + struct name_entry *matchn;
52935 +
52936 + if (unlikely(!(gr_status & GR_READY)))
52937 + return;
52938 +
52939 + preempt_disable();
52940 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52941 +
52942 + if (unlikely((unsigned long)matchn)) {
52943 + write_lock(&gr_inode_lock);
52944 + do_handle_create(matchn, dentry, mnt);
52945 + write_unlock(&gr_inode_lock);
52946 + }
52947 + preempt_enable();
52948 +
52949 + return;
52950 +}
52951 +
52952 +void
52953 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52954 +{
52955 + struct name_entry *matchn;
52956 +
52957 + if (unlikely(!(gr_status & GR_READY)))
52958 + return;
52959 +
52960 + preempt_disable();
52961 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52962 +
52963 + if (unlikely((unsigned long)matchn)) {
52964 + write_lock(&gr_inode_lock);
52965 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52966 + write_unlock(&gr_inode_lock);
52967 + }
52968 + preempt_enable();
52969 +
52970 + return;
52971 +}
52972 +
52973 +void
52974 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52975 + struct dentry *old_dentry,
52976 + struct dentry *new_dentry,
52977 + struct vfsmount *mnt, const __u8 replace)
52978 +{
52979 + struct name_entry *matchn;
52980 + struct inodev_entry *inodev;
52981 + struct inode *inode = new_dentry->d_inode;
52982 + ino_t old_ino = old_dentry->d_inode->i_ino;
52983 + dev_t old_dev = __get_dev(old_dentry);
52984 +
52985 + /* vfs_rename swaps the name and parent link for old_dentry and
52986 + new_dentry
52987 + at this point, old_dentry has the new name, parent link, and inode
52988 + for the renamed file
52989 + if a file is being replaced by a rename, new_dentry has the inode
52990 + and name for the replaced file
52991 + */
52992 +
52993 + if (unlikely(!(gr_status & GR_READY)))
52994 + return;
52995 +
52996 + preempt_disable();
52997 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
52998 +
52999 + /* we wouldn't have to check d_inode if it weren't for
53000 + NFS silly-renaming
53001 + */
53002 +
53003 + write_lock(&gr_inode_lock);
53004 + if (unlikely(replace && inode)) {
53005 + ino_t new_ino = inode->i_ino;
53006 + dev_t new_dev = __get_dev(new_dentry);
53007 +
53008 + inodev = lookup_inodev_entry(new_ino, new_dev);
53009 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53010 + do_handle_delete(inodev, new_ino, new_dev);
53011 + }
53012 +
53013 + inodev = lookup_inodev_entry(old_ino, old_dev);
53014 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53015 + do_handle_delete(inodev, old_ino, old_dev);
53016 +
53017 + if (unlikely((unsigned long)matchn))
53018 + do_handle_create(matchn, old_dentry, mnt);
53019 +
53020 + write_unlock(&gr_inode_lock);
53021 + preempt_enable();
53022 +
53023 + return;
53024 +}
53025 +
53026 +static int
53027 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53028 + unsigned char **sum)
53029 +{
53030 + struct acl_role_label *r;
53031 + struct role_allowed_ip *ipp;
53032 + struct role_transition *trans;
53033 + unsigned int i;
53034 + int found = 0;
53035 + u32 curr_ip = current->signal->curr_ip;
53036 +
53037 + current->signal->saved_ip = curr_ip;
53038 +
53039 + /* check transition table */
53040 +
53041 + for (trans = current->role->transitions; trans; trans = trans->next) {
53042 + if (!strcmp(rolename, trans->rolename)) {
53043 + found = 1;
53044 + break;
53045 + }
53046 + }
53047 +
53048 + if (!found)
53049 + return 0;
53050 +
53051 + /* handle special roles that do not require authentication
53052 + and check ip */
53053 +
53054 + FOR_EACH_ROLE_START(r)
53055 + if (!strcmp(rolename, r->rolename) &&
53056 + (r->roletype & GR_ROLE_SPECIAL)) {
53057 + found = 0;
53058 + if (r->allowed_ips != NULL) {
53059 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53060 + if ((ntohl(curr_ip) & ipp->netmask) ==
53061 + (ntohl(ipp->addr) & ipp->netmask))
53062 + found = 1;
53063 + }
53064 + } else
53065 + found = 2;
53066 + if (!found)
53067 + return 0;
53068 +
53069 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53070 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53071 + *salt = NULL;
53072 + *sum = NULL;
53073 + return 1;
53074 + }
53075 + }
53076 + FOR_EACH_ROLE_END(r)
53077 +
53078 + for (i = 0; i < num_sprole_pws; i++) {
53079 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53080 + *salt = acl_special_roles[i]->salt;
53081 + *sum = acl_special_roles[i]->sum;
53082 + return 1;
53083 + }
53084 + }
53085 +
53086 + return 0;
53087 +}
53088 +
53089 +static void
53090 +assign_special_role(char *rolename)
53091 +{
53092 + struct acl_object_label *obj;
53093 + struct acl_role_label *r;
53094 + struct acl_role_label *assigned = NULL;
53095 + struct task_struct *tsk;
53096 + struct file *filp;
53097 +
53098 + FOR_EACH_ROLE_START(r)
53099 + if (!strcmp(rolename, r->rolename) &&
53100 + (r->roletype & GR_ROLE_SPECIAL)) {
53101 + assigned = r;
53102 + break;
53103 + }
53104 + FOR_EACH_ROLE_END(r)
53105 +
53106 + if (!assigned)
53107 + return;
53108 +
53109 + read_lock(&tasklist_lock);
53110 + read_lock(&grsec_exec_file_lock);
53111 +
53112 + tsk = current->real_parent;
53113 + if (tsk == NULL)
53114 + goto out_unlock;
53115 +
53116 + filp = tsk->exec_file;
53117 + if (filp == NULL)
53118 + goto out_unlock;
53119 +
53120 + tsk->is_writable = 0;
53121 +
53122 + tsk->acl_sp_role = 1;
53123 + tsk->acl_role_id = ++acl_sp_role_value;
53124 + tsk->role = assigned;
53125 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53126 +
53127 + /* ignore additional mmap checks for processes that are writable
53128 + by the default ACL */
53129 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53130 + if (unlikely(obj->mode & GR_WRITE))
53131 + tsk->is_writable = 1;
53132 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53133 + if (unlikely(obj->mode & GR_WRITE))
53134 + tsk->is_writable = 1;
53135 +
53136 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53137 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53138 +#endif
53139 +
53140 +out_unlock:
53141 + read_unlock(&grsec_exec_file_lock);
53142 + read_unlock(&tasklist_lock);
53143 + return;
53144 +}
53145 +
53146 +int gr_check_secure_terminal(struct task_struct *task)
53147 +{
53148 + struct task_struct *p, *p2, *p3;
53149 + struct files_struct *files;
53150 + struct fdtable *fdt;
53151 + struct file *our_file = NULL, *file;
53152 + int i;
53153 +
53154 + if (task->signal->tty == NULL)
53155 + return 1;
53156 +
53157 + files = get_files_struct(task);
53158 + if (files != NULL) {
53159 + rcu_read_lock();
53160 + fdt = files_fdtable(files);
53161 + for (i=0; i < fdt->max_fds; i++) {
53162 + file = fcheck_files(files, i);
53163 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53164 + get_file(file);
53165 + our_file = file;
53166 + }
53167 + }
53168 + rcu_read_unlock();
53169 + put_files_struct(files);
53170 + }
53171 +
53172 + if (our_file == NULL)
53173 + return 1;
53174 +
53175 + read_lock(&tasklist_lock);
53176 + do_each_thread(p2, p) {
53177 + files = get_files_struct(p);
53178 + if (files == NULL ||
53179 + (p->signal && p->signal->tty == task->signal->tty)) {
53180 + if (files != NULL)
53181 + put_files_struct(files);
53182 + continue;
53183 + }
53184 + rcu_read_lock();
53185 + fdt = files_fdtable(files);
53186 + for (i=0; i < fdt->max_fds; i++) {
53187 + file = fcheck_files(files, i);
53188 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53189 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53190 + p3 = task;
53191 + while (p3->pid > 0) {
53192 + if (p3 == p)
53193 + break;
53194 + p3 = p3->real_parent;
53195 + }
53196 + if (p3 == p)
53197 + break;
53198 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53199 + gr_handle_alertkill(p);
53200 + rcu_read_unlock();
53201 + put_files_struct(files);
53202 + read_unlock(&tasklist_lock);
53203 + fput(our_file);
53204 + return 0;
53205 + }
53206 + }
53207 + rcu_read_unlock();
53208 + put_files_struct(files);
53209 + } while_each_thread(p2, p);
53210 + read_unlock(&tasklist_lock);
53211 +
53212 + fput(our_file);
53213 + return 1;
53214 +}
53215 +
53216 +static int gr_rbac_disable(void *unused)
53217 +{
53218 + pax_open_kernel();
53219 + gr_status &= ~GR_READY;
53220 + pax_close_kernel();
53221 +
53222 + return 0;
53223 +}
53224 +
53225 +ssize_t
53226 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53227 +{
53228 + struct gr_arg_wrapper uwrap;
53229 + unsigned char *sprole_salt = NULL;
53230 + unsigned char *sprole_sum = NULL;
53231 + int error = sizeof (struct gr_arg_wrapper);
53232 + int error2 = 0;
53233 +
53234 + mutex_lock(&gr_dev_mutex);
53235 +
53236 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53237 + error = -EPERM;
53238 + goto out;
53239 + }
53240 +
53241 + if (count != sizeof (struct gr_arg_wrapper)) {
53242 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53243 + error = -EINVAL;
53244 + goto out;
53245 + }
53246 +
53247 +
53248 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53249 + gr_auth_expires = 0;
53250 + gr_auth_attempts = 0;
53251 + }
53252 +
53253 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53254 + error = -EFAULT;
53255 + goto out;
53256 + }
53257 +
53258 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53259 + error = -EINVAL;
53260 + goto out;
53261 + }
53262 +
53263 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53264 + error = -EFAULT;
53265 + goto out;
53266 + }
53267 +
53268 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53269 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53270 + time_after(gr_auth_expires, get_seconds())) {
53271 + error = -EBUSY;
53272 + goto out;
53273 + }
53274 +
53275 + /* if non-root trying to do anything other than use a special role,
53276 + do not attempt authentication, do not count towards authentication
53277 + locking
53278 + */
53279 +
53280 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53281 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53282 + current_uid()) {
53283 + error = -EPERM;
53284 + goto out;
53285 + }
53286 +
53287 + /* ensure pw and special role name are null terminated */
53288 +
53289 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53290 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53291 +
53292 + /* Okay.
53293 + * We have our enough of the argument structure..(we have yet
53294 + * to copy_from_user the tables themselves) . Copy the tables
53295 + * only if we need them, i.e. for loading operations. */
53296 +
53297 + switch (gr_usermode->mode) {
53298 + case GR_STATUS:
53299 + if (gr_status & GR_READY) {
53300 + error = 1;
53301 + if (!gr_check_secure_terminal(current))
53302 + error = 3;
53303 + } else
53304 + error = 2;
53305 + goto out;
53306 + case GR_SHUTDOWN:
53307 + if ((gr_status & GR_READY)
53308 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53309 + stop_machine(gr_rbac_disable, NULL, NULL);
53310 + free_variables();
53311 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53312 + memset(gr_system_salt, 0, GR_SALT_LEN);
53313 + memset(gr_system_sum, 0, GR_SHA_LEN);
53314 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53315 + } else if (gr_status & GR_READY) {
53316 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53317 + error = -EPERM;
53318 + } else {
53319 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53320 + error = -EAGAIN;
53321 + }
53322 + break;
53323 + case GR_ENABLE:
53324 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53325 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53326 + else {
53327 + if (gr_status & GR_READY)
53328 + error = -EAGAIN;
53329 + else
53330 + error = error2;
53331 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53332 + }
53333 + break;
53334 + case GR_RELOAD:
53335 + if (!(gr_status & GR_READY)) {
53336 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53337 + error = -EAGAIN;
53338 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53339 + stop_machine(gr_rbac_disable, NULL, NULL);
53340 + free_variables();
53341 + error2 = gracl_init(gr_usermode);
53342 + if (!error2)
53343 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53344 + else {
53345 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53346 + error = error2;
53347 + }
53348 + } else {
53349 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53350 + error = -EPERM;
53351 + }
53352 + break;
53353 + case GR_SEGVMOD:
53354 + if (unlikely(!(gr_status & GR_READY))) {
53355 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53356 + error = -EAGAIN;
53357 + break;
53358 + }
53359 +
53360 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53361 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53362 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53363 + struct acl_subject_label *segvacl;
53364 + segvacl =
53365 + lookup_acl_subj_label(gr_usermode->segv_inode,
53366 + gr_usermode->segv_device,
53367 + current->role);
53368 + if (segvacl) {
53369 + segvacl->crashes = 0;
53370 + segvacl->expires = 0;
53371 + }
53372 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53373 + gr_remove_uid(gr_usermode->segv_uid);
53374 + }
53375 + } else {
53376 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53377 + error = -EPERM;
53378 + }
53379 + break;
53380 + case GR_SPROLE:
53381 + case GR_SPROLEPAM:
53382 + if (unlikely(!(gr_status & GR_READY))) {
53383 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53384 + error = -EAGAIN;
53385 + break;
53386 + }
53387 +
53388 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53389 + current->role->expires = 0;
53390 + current->role->auth_attempts = 0;
53391 + }
53392 +
53393 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53394 + time_after(current->role->expires, get_seconds())) {
53395 + error = -EBUSY;
53396 + goto out;
53397 + }
53398 +
53399 + if (lookup_special_role_auth
53400 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53401 + && ((!sprole_salt && !sprole_sum)
53402 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53403 + char *p = "";
53404 + assign_special_role(gr_usermode->sp_role);
53405 + read_lock(&tasklist_lock);
53406 + if (current->real_parent)
53407 + p = current->real_parent->role->rolename;
53408 + read_unlock(&tasklist_lock);
53409 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53410 + p, acl_sp_role_value);
53411 + } else {
53412 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53413 + error = -EPERM;
53414 + if(!(current->role->auth_attempts++))
53415 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53416 +
53417 + goto out;
53418 + }
53419 + break;
53420 + case GR_UNSPROLE:
53421 + if (unlikely(!(gr_status & GR_READY))) {
53422 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53423 + error = -EAGAIN;
53424 + break;
53425 + }
53426 +
53427 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53428 + char *p = "";
53429 + int i = 0;
53430 +
53431 + read_lock(&tasklist_lock);
53432 + if (current->real_parent) {
53433 + p = current->real_parent->role->rolename;
53434 + i = current->real_parent->acl_role_id;
53435 + }
53436 + read_unlock(&tasklist_lock);
53437 +
53438 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53439 + gr_set_acls(1);
53440 + } else {
53441 + error = -EPERM;
53442 + goto out;
53443 + }
53444 + break;
53445 + default:
53446 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53447 + error = -EINVAL;
53448 + break;
53449 + }
53450 +
53451 + if (error != -EPERM)
53452 + goto out;
53453 +
53454 + if(!(gr_auth_attempts++))
53455 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53456 +
53457 + out:
53458 + mutex_unlock(&gr_dev_mutex);
53459 + return error;
53460 +}
53461 +
53462 +/* must be called with
53463 + rcu_read_lock();
53464 + read_lock(&tasklist_lock);
53465 + read_lock(&grsec_exec_file_lock);
53466 +*/
53467 +int gr_apply_subject_to_task(struct task_struct *task)
53468 +{
53469 + struct acl_object_label *obj;
53470 + char *tmpname;
53471 + struct acl_subject_label *tmpsubj;
53472 + struct file *filp;
53473 + struct name_entry *nmatch;
53474 +
53475 + filp = task->exec_file;
53476 + if (filp == NULL)
53477 + return 0;
53478 +
53479 + /* the following is to apply the correct subject
53480 + on binaries running when the RBAC system
53481 + is enabled, when the binaries have been
53482 + replaced or deleted since their execution
53483 + -----
53484 + when the RBAC system starts, the inode/dev
53485 + from exec_file will be one the RBAC system
53486 + is unaware of. It only knows the inode/dev
53487 + of the present file on disk, or the absence
53488 + of it.
53489 + */
53490 + preempt_disable();
53491 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53492 +
53493 + nmatch = lookup_name_entry(tmpname);
53494 + preempt_enable();
53495 + tmpsubj = NULL;
53496 + if (nmatch) {
53497 + if (nmatch->deleted)
53498 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53499 + else
53500 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53501 + if (tmpsubj != NULL)
53502 + task->acl = tmpsubj;
53503 + }
53504 + if (tmpsubj == NULL)
53505 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53506 + task->role);
53507 + if (task->acl) {
53508 + task->is_writable = 0;
53509 + /* ignore additional mmap checks for processes that are writable
53510 + by the default ACL */
53511 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53512 + if (unlikely(obj->mode & GR_WRITE))
53513 + task->is_writable = 1;
53514 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53515 + if (unlikely(obj->mode & GR_WRITE))
53516 + task->is_writable = 1;
53517 +
53518 + gr_set_proc_res(task);
53519 +
53520 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53521 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53522 +#endif
53523 + } else {
53524 + return 1;
53525 + }
53526 +
53527 + return 0;
53528 +}
53529 +
53530 +int
53531 +gr_set_acls(const int type)
53532 +{
53533 + struct task_struct *task, *task2;
53534 + struct acl_role_label *role = current->role;
53535 + __u16 acl_role_id = current->acl_role_id;
53536 + const struct cred *cred;
53537 + int ret;
53538 +
53539 + rcu_read_lock();
53540 + read_lock(&tasklist_lock);
53541 + read_lock(&grsec_exec_file_lock);
53542 + do_each_thread(task2, task) {
53543 + /* check to see if we're called from the exit handler,
53544 + if so, only replace ACLs that have inherited the admin
53545 + ACL */
53546 +
53547 + if (type && (task->role != role ||
53548 + task->acl_role_id != acl_role_id))
53549 + continue;
53550 +
53551 + task->acl_role_id = 0;
53552 + task->acl_sp_role = 0;
53553 +
53554 + if (task->exec_file) {
53555 + cred = __task_cred(task);
53556 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53557 + ret = gr_apply_subject_to_task(task);
53558 + if (ret) {
53559 + read_unlock(&grsec_exec_file_lock);
53560 + read_unlock(&tasklist_lock);
53561 + rcu_read_unlock();
53562 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53563 + return ret;
53564 + }
53565 + } else {
53566 + // it's a kernel process
53567 + task->role = kernel_role;
53568 + task->acl = kernel_role->root_label;
53569 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53570 + task->acl->mode &= ~GR_PROCFIND;
53571 +#endif
53572 + }
53573 + } while_each_thread(task2, task);
53574 + read_unlock(&grsec_exec_file_lock);
53575 + read_unlock(&tasklist_lock);
53576 + rcu_read_unlock();
53577 +
53578 + return 0;
53579 +}
53580 +
53581 +void
53582 +gr_learn_resource(const struct task_struct *task,
53583 + const int res, const unsigned long wanted, const int gt)
53584 +{
53585 + struct acl_subject_label *acl;
53586 + const struct cred *cred;
53587 +
53588 + if (unlikely((gr_status & GR_READY) &&
53589 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53590 + goto skip_reslog;
53591 +
53592 +#ifdef CONFIG_GRKERNSEC_RESLOG
53593 + gr_log_resource(task, res, wanted, gt);
53594 +#endif
53595 + skip_reslog:
53596 +
53597 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53598 + return;
53599 +
53600 + acl = task->acl;
53601 +
53602 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53603 + !(acl->resmask & (1 << (unsigned short) res))))
53604 + return;
53605 +
53606 + if (wanted >= acl->res[res].rlim_cur) {
53607 + unsigned long res_add;
53608 +
53609 + res_add = wanted;
53610 + switch (res) {
53611 + case RLIMIT_CPU:
53612 + res_add += GR_RLIM_CPU_BUMP;
53613 + break;
53614 + case RLIMIT_FSIZE:
53615 + res_add += GR_RLIM_FSIZE_BUMP;
53616 + break;
53617 + case RLIMIT_DATA:
53618 + res_add += GR_RLIM_DATA_BUMP;
53619 + break;
53620 + case RLIMIT_STACK:
53621 + res_add += GR_RLIM_STACK_BUMP;
53622 + break;
53623 + case RLIMIT_CORE:
53624 + res_add += GR_RLIM_CORE_BUMP;
53625 + break;
53626 + case RLIMIT_RSS:
53627 + res_add += GR_RLIM_RSS_BUMP;
53628 + break;
53629 + case RLIMIT_NPROC:
53630 + res_add += GR_RLIM_NPROC_BUMP;
53631 + break;
53632 + case RLIMIT_NOFILE:
53633 + res_add += GR_RLIM_NOFILE_BUMP;
53634 + break;
53635 + case RLIMIT_MEMLOCK:
53636 + res_add += GR_RLIM_MEMLOCK_BUMP;
53637 + break;
53638 + case RLIMIT_AS:
53639 + res_add += GR_RLIM_AS_BUMP;
53640 + break;
53641 + case RLIMIT_LOCKS:
53642 + res_add += GR_RLIM_LOCKS_BUMP;
53643 + break;
53644 + case RLIMIT_SIGPENDING:
53645 + res_add += GR_RLIM_SIGPENDING_BUMP;
53646 + break;
53647 + case RLIMIT_MSGQUEUE:
53648 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53649 + break;
53650 + case RLIMIT_NICE:
53651 + res_add += GR_RLIM_NICE_BUMP;
53652 + break;
53653 + case RLIMIT_RTPRIO:
53654 + res_add += GR_RLIM_RTPRIO_BUMP;
53655 + break;
53656 + case RLIMIT_RTTIME:
53657 + res_add += GR_RLIM_RTTIME_BUMP;
53658 + break;
53659 + }
53660 +
53661 + acl->res[res].rlim_cur = res_add;
53662 +
53663 + if (wanted > acl->res[res].rlim_max)
53664 + acl->res[res].rlim_max = res_add;
53665 +
53666 + /* only log the subject filename, since resource logging is supported for
53667 + single-subject learning only */
53668 + rcu_read_lock();
53669 + cred = __task_cred(task);
53670 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53671 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53672 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53673 + "", (unsigned long) res, &task->signal->saved_ip);
53674 + rcu_read_unlock();
53675 + }
53676 +
53677 + return;
53678 +}
53679 +
53680 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53681 +void
53682 +pax_set_initial_flags(struct linux_binprm *bprm)
53683 +{
53684 + struct task_struct *task = current;
53685 + struct acl_subject_label *proc;
53686 + unsigned long flags;
53687 +
53688 + if (unlikely(!(gr_status & GR_READY)))
53689 + return;
53690 +
53691 + flags = pax_get_flags(task);
53692 +
53693 + proc = task->acl;
53694 +
53695 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53696 + flags &= ~MF_PAX_PAGEEXEC;
53697 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53698 + flags &= ~MF_PAX_SEGMEXEC;
53699 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53700 + flags &= ~MF_PAX_RANDMMAP;
53701 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53702 + flags &= ~MF_PAX_EMUTRAMP;
53703 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53704 + flags &= ~MF_PAX_MPROTECT;
53705 +
53706 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53707 + flags |= MF_PAX_PAGEEXEC;
53708 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53709 + flags |= MF_PAX_SEGMEXEC;
53710 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53711 + flags |= MF_PAX_RANDMMAP;
53712 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53713 + flags |= MF_PAX_EMUTRAMP;
53714 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53715 + flags |= MF_PAX_MPROTECT;
53716 +
53717 + pax_set_flags(task, flags);
53718 +
53719 + return;
53720 +}
53721 +#endif
53722 +
53723 +int
53724 +gr_handle_proc_ptrace(struct task_struct *task)
53725 +{
53726 + struct file *filp;
53727 + struct task_struct *tmp = task;
53728 + struct task_struct *curtemp = current;
53729 + __u32 retmode;
53730 +
53731 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53732 + if (unlikely(!(gr_status & GR_READY)))
53733 + return 0;
53734 +#endif
53735 +
53736 + read_lock(&tasklist_lock);
53737 + read_lock(&grsec_exec_file_lock);
53738 + filp = task->exec_file;
53739 +
53740 + while (tmp->pid > 0) {
53741 + if (tmp == curtemp)
53742 + break;
53743 + tmp = tmp->real_parent;
53744 + }
53745 +
53746 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53747 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53748 + read_unlock(&grsec_exec_file_lock);
53749 + read_unlock(&tasklist_lock);
53750 + return 1;
53751 + }
53752 +
53753 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53754 + if (!(gr_status & GR_READY)) {
53755 + read_unlock(&grsec_exec_file_lock);
53756 + read_unlock(&tasklist_lock);
53757 + return 0;
53758 + }
53759 +#endif
53760 +
53761 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53762 + read_unlock(&grsec_exec_file_lock);
53763 + read_unlock(&tasklist_lock);
53764 +
53765 + if (retmode & GR_NOPTRACE)
53766 + return 1;
53767 +
53768 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53769 + && (current->acl != task->acl || (current->acl != current->role->root_label
53770 + && current->pid != task->pid)))
53771 + return 1;
53772 +
53773 + return 0;
53774 +}
53775 +
53776 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53777 +{
53778 + if (unlikely(!(gr_status & GR_READY)))
53779 + return;
53780 +
53781 + if (!(current->role->roletype & GR_ROLE_GOD))
53782 + return;
53783 +
53784 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53785 + p->role->rolename, gr_task_roletype_to_char(p),
53786 + p->acl->filename);
53787 +}
53788 +
53789 +int
53790 +gr_handle_ptrace(struct task_struct *task, const long request)
53791 +{
53792 + struct task_struct *tmp = task;
53793 + struct task_struct *curtemp = current;
53794 + __u32 retmode;
53795 +
53796 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53797 + if (unlikely(!(gr_status & GR_READY)))
53798 + return 0;
53799 +#endif
53800 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
53801 + read_lock(&tasklist_lock);
53802 + while (tmp->pid > 0) {
53803 + if (tmp == curtemp)
53804 + break;
53805 + tmp = tmp->real_parent;
53806 + }
53807 +
53808 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53809 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53810 + read_unlock(&tasklist_lock);
53811 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53812 + return 1;
53813 + }
53814 + read_unlock(&tasklist_lock);
53815 + }
53816 +
53817 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53818 + if (!(gr_status & GR_READY))
53819 + return 0;
53820 +#endif
53821 +
53822 + read_lock(&grsec_exec_file_lock);
53823 + if (unlikely(!task->exec_file)) {
53824 + read_unlock(&grsec_exec_file_lock);
53825 + return 0;
53826 + }
53827 +
53828 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53829 + read_unlock(&grsec_exec_file_lock);
53830 +
53831 + if (retmode & GR_NOPTRACE) {
53832 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53833 + return 1;
53834 + }
53835 +
53836 + if (retmode & GR_PTRACERD) {
53837 + switch (request) {
53838 + case PTRACE_SEIZE:
53839 + case PTRACE_POKETEXT:
53840 + case PTRACE_POKEDATA:
53841 + case PTRACE_POKEUSR:
53842 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53843 + case PTRACE_SETREGS:
53844 + case PTRACE_SETFPREGS:
53845 +#endif
53846 +#ifdef CONFIG_X86
53847 + case PTRACE_SETFPXREGS:
53848 +#endif
53849 +#ifdef CONFIG_ALTIVEC
53850 + case PTRACE_SETVRREGS:
53851 +#endif
53852 + return 1;
53853 + default:
53854 + return 0;
53855 + }
53856 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
53857 + !(current->role->roletype & GR_ROLE_GOD) &&
53858 + (current->acl != task->acl)) {
53859 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53860 + return 1;
53861 + }
53862 +
53863 + return 0;
53864 +}
53865 +
53866 +static int is_writable_mmap(const struct file *filp)
53867 +{
53868 + struct task_struct *task = current;
53869 + struct acl_object_label *obj, *obj2;
53870 +
53871 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53872 + !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))) {
53873 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53874 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53875 + task->role->root_label);
53876 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53877 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53878 + return 1;
53879 + }
53880 + }
53881 + return 0;
53882 +}
53883 +
53884 +int
53885 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53886 +{
53887 + __u32 mode;
53888 +
53889 + if (unlikely(!file || !(prot & PROT_EXEC)))
53890 + return 1;
53891 +
53892 + if (is_writable_mmap(file))
53893 + return 0;
53894 +
53895 + mode =
53896 + gr_search_file(file->f_path.dentry,
53897 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53898 + file->f_path.mnt);
53899 +
53900 + if (!gr_tpe_allow(file))
53901 + return 0;
53902 +
53903 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53904 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53905 + return 0;
53906 + } else if (unlikely(!(mode & GR_EXEC))) {
53907 + return 0;
53908 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53909 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53910 + return 1;
53911 + }
53912 +
53913 + return 1;
53914 +}
53915 +
53916 +int
53917 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53918 +{
53919 + __u32 mode;
53920 +
53921 + if (unlikely(!file || !(prot & PROT_EXEC)))
53922 + return 1;
53923 +
53924 + if (is_writable_mmap(file))
53925 + return 0;
53926 +
53927 + mode =
53928 + gr_search_file(file->f_path.dentry,
53929 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53930 + file->f_path.mnt);
53931 +
53932 + if (!gr_tpe_allow(file))
53933 + return 0;
53934 +
53935 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53936 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53937 + return 0;
53938 + } else if (unlikely(!(mode & GR_EXEC))) {
53939 + return 0;
53940 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53941 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53942 + return 1;
53943 + }
53944 +
53945 + return 1;
53946 +}
53947 +
53948 +void
53949 +gr_acl_handle_psacct(struct task_struct *task, const long code)
53950 +{
53951 + unsigned long runtime;
53952 + unsigned long cputime;
53953 + unsigned int wday, cday;
53954 + __u8 whr, chr;
53955 + __u8 wmin, cmin;
53956 + __u8 wsec, csec;
53957 + struct timespec timeval;
53958 +
53959 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53960 + !(task->acl->mode & GR_PROCACCT)))
53961 + return;
53962 +
53963 + do_posix_clock_monotonic_gettime(&timeval);
53964 + runtime = timeval.tv_sec - task->start_time.tv_sec;
53965 + wday = runtime / (3600 * 24);
53966 + runtime -= wday * (3600 * 24);
53967 + whr = runtime / 3600;
53968 + runtime -= whr * 3600;
53969 + wmin = runtime / 60;
53970 + runtime -= wmin * 60;
53971 + wsec = runtime;
53972 +
53973 + cputime = (task->utime + task->stime) / HZ;
53974 + cday = cputime / (3600 * 24);
53975 + cputime -= cday * (3600 * 24);
53976 + chr = cputime / 3600;
53977 + cputime -= chr * 3600;
53978 + cmin = cputime / 60;
53979 + cputime -= cmin * 60;
53980 + csec = cputime;
53981 +
53982 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53983 +
53984 + return;
53985 +}
53986 +
53987 +void gr_set_kernel_label(struct task_struct *task)
53988 +{
53989 + if (gr_status & GR_READY) {
53990 + task->role = kernel_role;
53991 + task->acl = kernel_role->root_label;
53992 + }
53993 + return;
53994 +}
53995 +
53996 +#ifdef CONFIG_TASKSTATS
53997 +int gr_is_taskstats_denied(int pid)
53998 +{
53999 + struct task_struct *task;
54000 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54001 + const struct cred *cred;
54002 +#endif
54003 + int ret = 0;
54004 +
54005 + /* restrict taskstats viewing to un-chrooted root users
54006 + who have the 'view' subject flag if the RBAC system is enabled
54007 + */
54008 +
54009 + rcu_read_lock();
54010 + read_lock(&tasklist_lock);
54011 + task = find_task_by_vpid(pid);
54012 + if (task) {
54013 +#ifdef CONFIG_GRKERNSEC_CHROOT
54014 + if (proc_is_chrooted(task))
54015 + ret = -EACCES;
54016 +#endif
54017 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54018 + cred = __task_cred(task);
54019 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54020 + if (cred->uid != 0)
54021 + ret = -EACCES;
54022 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54023 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54024 + ret = -EACCES;
54025 +#endif
54026 +#endif
54027 + if (gr_status & GR_READY) {
54028 + if (!(task->acl->mode & GR_VIEW))
54029 + ret = -EACCES;
54030 + }
54031 + } else
54032 + ret = -ENOENT;
54033 +
54034 + read_unlock(&tasklist_lock);
54035 + rcu_read_unlock();
54036 +
54037 + return ret;
54038 +}
54039 +#endif
54040 +
54041 +/* AUXV entries are filled via a descendant of search_binary_handler
54042 + after we've already applied the subject for the target
54043 +*/
54044 +int gr_acl_enable_at_secure(void)
54045 +{
54046 + if (unlikely(!(gr_status & GR_READY)))
54047 + return 0;
54048 +
54049 + if (current->acl->mode & GR_ATSECURE)
54050 + return 1;
54051 +
54052 + return 0;
54053 +}
54054 +
54055 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54056 +{
54057 + struct task_struct *task = current;
54058 + struct dentry *dentry = file->f_path.dentry;
54059 + struct vfsmount *mnt = file->f_path.mnt;
54060 + struct acl_object_label *obj, *tmp;
54061 + struct acl_subject_label *subj;
54062 + unsigned int bufsize;
54063 + int is_not_root;
54064 + char *path;
54065 + dev_t dev = __get_dev(dentry);
54066 +
54067 + if (unlikely(!(gr_status & GR_READY)))
54068 + return 1;
54069 +
54070 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54071 + return 1;
54072 +
54073 + /* ignore Eric Biederman */
54074 + if (IS_PRIVATE(dentry->d_inode))
54075 + return 1;
54076 +
54077 + subj = task->acl;
54078 + read_lock(&gr_inode_lock);
54079 + do {
54080 + obj = lookup_acl_obj_label(ino, dev, subj);
54081 + if (obj != NULL) {
54082 + read_unlock(&gr_inode_lock);
54083 + return (obj->mode & GR_FIND) ? 1 : 0;
54084 + }
54085 + } while ((subj = subj->parent_subject));
54086 + read_unlock(&gr_inode_lock);
54087 +
54088 + /* this is purely an optimization since we're looking for an object
54089 + for the directory we're doing a readdir on
54090 + if it's possible for any globbed object to match the entry we're
54091 + filling into the directory, then the object we find here will be
54092 + an anchor point with attached globbed objects
54093 + */
54094 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54095 + if (obj->globbed == NULL)
54096 + return (obj->mode & GR_FIND) ? 1 : 0;
54097 +
54098 + is_not_root = ((obj->filename[0] == '/') &&
54099 + (obj->filename[1] == '\0')) ? 0 : 1;
54100 + bufsize = PAGE_SIZE - namelen - is_not_root;
54101 +
54102 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54103 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54104 + return 1;
54105 +
54106 + preempt_disable();
54107 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54108 + bufsize);
54109 +
54110 + bufsize = strlen(path);
54111 +
54112 + /* if base is "/", don't append an additional slash */
54113 + if (is_not_root)
54114 + *(path + bufsize) = '/';
54115 + memcpy(path + bufsize + is_not_root, name, namelen);
54116 + *(path + bufsize + namelen + is_not_root) = '\0';
54117 +
54118 + tmp = obj->globbed;
54119 + while (tmp) {
54120 + if (!glob_match(tmp->filename, path)) {
54121 + preempt_enable();
54122 + return (tmp->mode & GR_FIND) ? 1 : 0;
54123 + }
54124 + tmp = tmp->next;
54125 + }
54126 + preempt_enable();
54127 + return (obj->mode & GR_FIND) ? 1 : 0;
54128 +}
54129 +
54130 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54131 +EXPORT_SYMBOL(gr_acl_is_enabled);
54132 +#endif
54133 +EXPORT_SYMBOL(gr_learn_resource);
54134 +EXPORT_SYMBOL(gr_set_kernel_label);
54135 +#ifdef CONFIG_SECURITY
54136 +EXPORT_SYMBOL(gr_check_user_change);
54137 +EXPORT_SYMBOL(gr_check_group_change);
54138 +#endif
54139 +
54140 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54141 new file mode 100644
54142 index 0000000..34fefda
54143 --- /dev/null
54144 +++ b/grsecurity/gracl_alloc.c
54145 @@ -0,0 +1,105 @@
54146 +#include <linux/kernel.h>
54147 +#include <linux/mm.h>
54148 +#include <linux/slab.h>
54149 +#include <linux/vmalloc.h>
54150 +#include <linux/gracl.h>
54151 +#include <linux/grsecurity.h>
54152 +
54153 +static unsigned long alloc_stack_next = 1;
54154 +static unsigned long alloc_stack_size = 1;
54155 +static void **alloc_stack;
54156 +
54157 +static __inline__ int
54158 +alloc_pop(void)
54159 +{
54160 + if (alloc_stack_next == 1)
54161 + return 0;
54162 +
54163 + kfree(alloc_stack[alloc_stack_next - 2]);
54164 +
54165 + alloc_stack_next--;
54166 +
54167 + return 1;
54168 +}
54169 +
54170 +static __inline__ int
54171 +alloc_push(void *buf)
54172 +{
54173 + if (alloc_stack_next >= alloc_stack_size)
54174 + return 1;
54175 +
54176 + alloc_stack[alloc_stack_next - 1] = buf;
54177 +
54178 + alloc_stack_next++;
54179 +
54180 + return 0;
54181 +}
54182 +
54183 +void *
54184 +acl_alloc(unsigned long len)
54185 +{
54186 + void *ret = NULL;
54187 +
54188 + if (!len || len > PAGE_SIZE)
54189 + goto out;
54190 +
54191 + ret = kmalloc(len, GFP_KERNEL);
54192 +
54193 + if (ret) {
54194 + if (alloc_push(ret)) {
54195 + kfree(ret);
54196 + ret = NULL;
54197 + }
54198 + }
54199 +
54200 +out:
54201 + return ret;
54202 +}
54203 +
54204 +void *
54205 +acl_alloc_num(unsigned long num, unsigned long len)
54206 +{
54207 + if (!len || (num > (PAGE_SIZE / len)))
54208 + return NULL;
54209 +
54210 + return acl_alloc(num * len);
54211 +}
54212 +
54213 +void
54214 +acl_free_all(void)
54215 +{
54216 + if (gr_acl_is_enabled() || !alloc_stack)
54217 + return;
54218 +
54219 + while (alloc_pop()) ;
54220 +
54221 + if (alloc_stack) {
54222 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54223 + kfree(alloc_stack);
54224 + else
54225 + vfree(alloc_stack);
54226 + }
54227 +
54228 + alloc_stack = NULL;
54229 + alloc_stack_size = 1;
54230 + alloc_stack_next = 1;
54231 +
54232 + return;
54233 +}
54234 +
54235 +int
54236 +acl_alloc_stack_init(unsigned long size)
54237 +{
54238 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54239 + alloc_stack =
54240 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54241 + else
54242 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54243 +
54244 + alloc_stack_size = size;
54245 +
54246 + if (!alloc_stack)
54247 + return 0;
54248 + else
54249 + return 1;
54250 +}
54251 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54252 new file mode 100644
54253 index 0000000..6d21049
54254 --- /dev/null
54255 +++ b/grsecurity/gracl_cap.c
54256 @@ -0,0 +1,110 @@
54257 +#include <linux/kernel.h>
54258 +#include <linux/module.h>
54259 +#include <linux/sched.h>
54260 +#include <linux/gracl.h>
54261 +#include <linux/grsecurity.h>
54262 +#include <linux/grinternal.h>
54263 +
54264 +extern const char *captab_log[];
54265 +extern int captab_log_entries;
54266 +
54267 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54268 +{
54269 + struct acl_subject_label *curracl;
54270 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54271 + kernel_cap_t cap_audit = __cap_empty_set;
54272 +
54273 + if (!gr_acl_is_enabled())
54274 + return 1;
54275 +
54276 + curracl = task->acl;
54277 +
54278 + cap_drop = curracl->cap_lower;
54279 + cap_mask = curracl->cap_mask;
54280 + cap_audit = curracl->cap_invert_audit;
54281 +
54282 + while ((curracl = curracl->parent_subject)) {
54283 + /* if the cap isn't specified in the current computed mask but is specified in the
54284 + current level subject, and is lowered in the current level subject, then add
54285 + it to the set of dropped capabilities
54286 + otherwise, add the current level subject's mask to the current computed mask
54287 + */
54288 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54289 + cap_raise(cap_mask, cap);
54290 + if (cap_raised(curracl->cap_lower, cap))
54291 + cap_raise(cap_drop, cap);
54292 + if (cap_raised(curracl->cap_invert_audit, cap))
54293 + cap_raise(cap_audit, cap);
54294 + }
54295 + }
54296 +
54297 + if (!cap_raised(cap_drop, cap)) {
54298 + if (cap_raised(cap_audit, cap))
54299 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54300 + return 1;
54301 + }
54302 +
54303 + curracl = task->acl;
54304 +
54305 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54306 + && cap_raised(cred->cap_effective, cap)) {
54307 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54308 + task->role->roletype, cred->uid,
54309 + cred->gid, task->exec_file ?
54310 + gr_to_filename(task->exec_file->f_path.dentry,
54311 + task->exec_file->f_path.mnt) : curracl->filename,
54312 + curracl->filename, 0UL,
54313 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54314 + return 1;
54315 + }
54316 +
54317 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54318 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54319 +
54320 + return 0;
54321 +}
54322 +
54323 +int
54324 +gr_acl_is_capable(const int cap)
54325 +{
54326 + return gr_task_acl_is_capable(current, current_cred(), cap);
54327 +}
54328 +
54329 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54330 +{
54331 + struct acl_subject_label *curracl;
54332 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54333 +
54334 + if (!gr_acl_is_enabled())
54335 + return 1;
54336 +
54337 + curracl = task->acl;
54338 +
54339 + cap_drop = curracl->cap_lower;
54340 + cap_mask = curracl->cap_mask;
54341 +
54342 + while ((curracl = curracl->parent_subject)) {
54343 + /* if the cap isn't specified in the current computed mask but is specified in the
54344 + current level subject, and is lowered in the current level subject, then add
54345 + it to the set of dropped capabilities
54346 + otherwise, add the current level subject's mask to the current computed mask
54347 + */
54348 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54349 + cap_raise(cap_mask, cap);
54350 + if (cap_raised(curracl->cap_lower, cap))
54351 + cap_raise(cap_drop, cap);
54352 + }
54353 + }
54354 +
54355 + if (!cap_raised(cap_drop, cap))
54356 + return 1;
54357 +
54358 + return 0;
54359 +}
54360 +
54361 +int
54362 +gr_acl_is_capable_nolog(const int cap)
54363 +{
54364 + return gr_task_acl_is_capable_nolog(current, cap);
54365 +}
54366 +
54367 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54368 new file mode 100644
54369 index 0000000..88d0e87
54370 --- /dev/null
54371 +++ b/grsecurity/gracl_fs.c
54372 @@ -0,0 +1,435 @@
54373 +#include <linux/kernel.h>
54374 +#include <linux/sched.h>
54375 +#include <linux/types.h>
54376 +#include <linux/fs.h>
54377 +#include <linux/file.h>
54378 +#include <linux/stat.h>
54379 +#include <linux/grsecurity.h>
54380 +#include <linux/grinternal.h>
54381 +#include <linux/gracl.h>
54382 +
54383 +umode_t
54384 +gr_acl_umask(void)
54385 +{
54386 + if (unlikely(!gr_acl_is_enabled()))
54387 + return 0;
54388 +
54389 + return current->role->umask;
54390 +}
54391 +
54392 +__u32
54393 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54394 + const struct vfsmount * mnt)
54395 +{
54396 + __u32 mode;
54397 +
54398 + if (unlikely(!dentry->d_inode))
54399 + return GR_FIND;
54400 +
54401 + mode =
54402 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54403 +
54404 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54405 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54406 + return mode;
54407 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54408 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54409 + return 0;
54410 + } else if (unlikely(!(mode & GR_FIND)))
54411 + return 0;
54412 +
54413 + return GR_FIND;
54414 +}
54415 +
54416 +__u32
54417 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54418 + int acc_mode)
54419 +{
54420 + __u32 reqmode = GR_FIND;
54421 + __u32 mode;
54422 +
54423 + if (unlikely(!dentry->d_inode))
54424 + return reqmode;
54425 +
54426 + if (acc_mode & MAY_APPEND)
54427 + reqmode |= GR_APPEND;
54428 + else if (acc_mode & MAY_WRITE)
54429 + reqmode |= GR_WRITE;
54430 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54431 + reqmode |= GR_READ;
54432 +
54433 + mode =
54434 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54435 + mnt);
54436 +
54437 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54438 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54439 + reqmode & GR_READ ? " reading" : "",
54440 + reqmode & GR_WRITE ? " writing" : reqmode &
54441 + GR_APPEND ? " appending" : "");
54442 + return reqmode;
54443 + } else
54444 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54445 + {
54446 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54447 + reqmode & GR_READ ? " reading" : "",
54448 + reqmode & GR_WRITE ? " writing" : reqmode &
54449 + GR_APPEND ? " appending" : "");
54450 + return 0;
54451 + } else if (unlikely((mode & reqmode) != reqmode))
54452 + return 0;
54453 +
54454 + return reqmode;
54455 +}
54456 +
54457 +__u32
54458 +gr_acl_handle_creat(const struct dentry * dentry,
54459 + const struct dentry * p_dentry,
54460 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54461 + const int imode)
54462 +{
54463 + __u32 reqmode = GR_WRITE | GR_CREATE;
54464 + __u32 mode;
54465 +
54466 + if (acc_mode & MAY_APPEND)
54467 + reqmode |= GR_APPEND;
54468 + // if a directory was required or the directory already exists, then
54469 + // don't count this open as a read
54470 + if ((acc_mode & MAY_READ) &&
54471 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54472 + reqmode |= GR_READ;
54473 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54474 + reqmode |= GR_SETID;
54475 +
54476 + mode =
54477 + gr_check_create(dentry, p_dentry, p_mnt,
54478 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54479 +
54480 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54481 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54482 + reqmode & GR_READ ? " reading" : "",
54483 + reqmode & GR_WRITE ? " writing" : reqmode &
54484 + GR_APPEND ? " appending" : "");
54485 + return reqmode;
54486 + } else
54487 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54488 + {
54489 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54490 + reqmode & GR_READ ? " reading" : "",
54491 + reqmode & GR_WRITE ? " writing" : reqmode &
54492 + GR_APPEND ? " appending" : "");
54493 + return 0;
54494 + } else if (unlikely((mode & reqmode) != reqmode))
54495 + return 0;
54496 +
54497 + return reqmode;
54498 +}
54499 +
54500 +__u32
54501 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54502 + const int fmode)
54503 +{
54504 + __u32 mode, reqmode = GR_FIND;
54505 +
54506 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54507 + reqmode |= GR_EXEC;
54508 + if (fmode & S_IWOTH)
54509 + reqmode |= GR_WRITE;
54510 + if (fmode & S_IROTH)
54511 + reqmode |= GR_READ;
54512 +
54513 + mode =
54514 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54515 + mnt);
54516 +
54517 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54518 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54519 + reqmode & GR_READ ? " reading" : "",
54520 + reqmode & GR_WRITE ? " writing" : "",
54521 + reqmode & GR_EXEC ? " executing" : "");
54522 + return reqmode;
54523 + } else
54524 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54525 + {
54526 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54527 + reqmode & GR_READ ? " reading" : "",
54528 + reqmode & GR_WRITE ? " writing" : "",
54529 + reqmode & GR_EXEC ? " executing" : "");
54530 + return 0;
54531 + } else if (unlikely((mode & reqmode) != reqmode))
54532 + return 0;
54533 +
54534 + return reqmode;
54535 +}
54536 +
54537 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54538 +{
54539 + __u32 mode;
54540 +
54541 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54542 +
54543 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54544 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54545 + return mode;
54546 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54547 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54548 + return 0;
54549 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54550 + return 0;
54551 +
54552 + return (reqmode);
54553 +}
54554 +
54555 +__u32
54556 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54557 +{
54558 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54559 +}
54560 +
54561 +__u32
54562 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54563 +{
54564 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54565 +}
54566 +
54567 +__u32
54568 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54569 +{
54570 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54571 +}
54572 +
54573 +__u32
54574 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54575 +{
54576 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54577 +}
54578 +
54579 +__u32
54580 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54581 + umode_t *modeptr)
54582 +{
54583 + umode_t mode;
54584 +
54585 + *modeptr &= ~gr_acl_umask();
54586 + mode = *modeptr;
54587 +
54588 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54589 + return 1;
54590 +
54591 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54592 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54593 + GR_CHMOD_ACL_MSG);
54594 + } else {
54595 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54596 + }
54597 +}
54598 +
54599 +__u32
54600 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54601 +{
54602 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54603 +}
54604 +
54605 +__u32
54606 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54607 +{
54608 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54609 +}
54610 +
54611 +__u32
54612 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54613 +{
54614 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54615 +}
54616 +
54617 +__u32
54618 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54619 +{
54620 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54621 + GR_UNIXCONNECT_ACL_MSG);
54622 +}
54623 +
54624 +/* hardlinks require at minimum create and link permission,
54625 + any additional privilege required is based on the
54626 + privilege of the file being linked to
54627 +*/
54628 +__u32
54629 +gr_acl_handle_link(const struct dentry * new_dentry,
54630 + const struct dentry * parent_dentry,
54631 + const struct vfsmount * parent_mnt,
54632 + const struct dentry * old_dentry,
54633 + const struct vfsmount * old_mnt, const char *to)
54634 +{
54635 + __u32 mode;
54636 + __u32 needmode = GR_CREATE | GR_LINK;
54637 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54638 +
54639 + mode =
54640 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54641 + old_mnt);
54642 +
54643 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54644 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54645 + return mode;
54646 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54647 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54648 + return 0;
54649 + } else if (unlikely((mode & needmode) != needmode))
54650 + return 0;
54651 +
54652 + return 1;
54653 +}
54654 +
54655 +__u32
54656 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54657 + const struct dentry * parent_dentry,
54658 + const struct vfsmount * parent_mnt, const char *from)
54659 +{
54660 + __u32 needmode = GR_WRITE | GR_CREATE;
54661 + __u32 mode;
54662 +
54663 + mode =
54664 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54665 + GR_CREATE | GR_AUDIT_CREATE |
54666 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54667 +
54668 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54669 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54670 + return mode;
54671 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54672 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54673 + return 0;
54674 + } else if (unlikely((mode & needmode) != needmode))
54675 + return 0;
54676 +
54677 + return (GR_WRITE | GR_CREATE);
54678 +}
54679 +
54680 +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)
54681 +{
54682 + __u32 mode;
54683 +
54684 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54685 +
54686 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54687 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54688 + return mode;
54689 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54690 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54691 + return 0;
54692 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54693 + return 0;
54694 +
54695 + return (reqmode);
54696 +}
54697 +
54698 +__u32
54699 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54700 + const struct dentry * parent_dentry,
54701 + const struct vfsmount * parent_mnt,
54702 + const int mode)
54703 +{
54704 + __u32 reqmode = GR_WRITE | GR_CREATE;
54705 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54706 + reqmode |= GR_SETID;
54707 +
54708 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54709 + reqmode, GR_MKNOD_ACL_MSG);
54710 +}
54711 +
54712 +__u32
54713 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54714 + const struct dentry *parent_dentry,
54715 + const struct vfsmount *parent_mnt)
54716 +{
54717 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54718 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54719 +}
54720 +
54721 +#define RENAME_CHECK_SUCCESS(old, new) \
54722 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54723 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54724 +
54725 +int
54726 +gr_acl_handle_rename(struct dentry *new_dentry,
54727 + struct dentry *parent_dentry,
54728 + const struct vfsmount *parent_mnt,
54729 + struct dentry *old_dentry,
54730 + struct inode *old_parent_inode,
54731 + struct vfsmount *old_mnt, const char *newname)
54732 +{
54733 + __u32 comp1, comp2;
54734 + int error = 0;
54735 +
54736 + if (unlikely(!gr_acl_is_enabled()))
54737 + return 0;
54738 +
54739 + if (!new_dentry->d_inode) {
54740 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54741 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54742 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54743 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54744 + GR_DELETE | GR_AUDIT_DELETE |
54745 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54746 + GR_SUPPRESS, old_mnt);
54747 + } else {
54748 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54749 + GR_CREATE | GR_DELETE |
54750 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54751 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54752 + GR_SUPPRESS, parent_mnt);
54753 + comp2 =
54754 + gr_search_file(old_dentry,
54755 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54756 + GR_DELETE | GR_AUDIT_DELETE |
54757 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54758 + }
54759 +
54760 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54761 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54762 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54763 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54764 + && !(comp2 & GR_SUPPRESS)) {
54765 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54766 + error = -EACCES;
54767 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54768 + error = -EACCES;
54769 +
54770 + return error;
54771 +}
54772 +
54773 +void
54774 +gr_acl_handle_exit(void)
54775 +{
54776 + u16 id;
54777 + char *rolename;
54778 + struct file *exec_file;
54779 +
54780 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54781 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54782 + id = current->acl_role_id;
54783 + rolename = current->role->rolename;
54784 + gr_set_acls(1);
54785 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54786 + }
54787 +
54788 + write_lock(&grsec_exec_file_lock);
54789 + exec_file = current->exec_file;
54790 + current->exec_file = NULL;
54791 + write_unlock(&grsec_exec_file_lock);
54792 +
54793 + if (exec_file)
54794 + fput(exec_file);
54795 +}
54796 +
54797 +int
54798 +gr_acl_handle_procpidmem(const struct task_struct *task)
54799 +{
54800 + if (unlikely(!gr_acl_is_enabled()))
54801 + return 0;
54802 +
54803 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54804 + return -EACCES;
54805 +
54806 + return 0;
54807 +}
54808 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54809 new file mode 100644
54810 index 0000000..58800a7
54811 --- /dev/null
54812 +++ b/grsecurity/gracl_ip.c
54813 @@ -0,0 +1,384 @@
54814 +#include <linux/kernel.h>
54815 +#include <asm/uaccess.h>
54816 +#include <asm/errno.h>
54817 +#include <net/sock.h>
54818 +#include <linux/file.h>
54819 +#include <linux/fs.h>
54820 +#include <linux/net.h>
54821 +#include <linux/in.h>
54822 +#include <linux/skbuff.h>
54823 +#include <linux/ip.h>
54824 +#include <linux/udp.h>
54825 +#include <linux/types.h>
54826 +#include <linux/sched.h>
54827 +#include <linux/netdevice.h>
54828 +#include <linux/inetdevice.h>
54829 +#include <linux/gracl.h>
54830 +#include <linux/grsecurity.h>
54831 +#include <linux/grinternal.h>
54832 +
54833 +#define GR_BIND 0x01
54834 +#define GR_CONNECT 0x02
54835 +#define GR_INVERT 0x04
54836 +#define GR_BINDOVERRIDE 0x08
54837 +#define GR_CONNECTOVERRIDE 0x10
54838 +#define GR_SOCK_FAMILY 0x20
54839 +
54840 +static const char * gr_protocols[IPPROTO_MAX] = {
54841 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54842 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54843 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54844 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54845 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54846 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54847 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54848 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54849 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54850 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54851 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54852 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54853 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54854 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54855 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54856 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54857 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54858 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54859 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54860 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54861 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54862 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54863 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54864 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54865 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54866 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54867 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54868 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54869 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54870 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54871 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54872 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54873 + };
54874 +
54875 +static const char * gr_socktypes[SOCK_MAX] = {
54876 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54877 + "unknown:7", "unknown:8", "unknown:9", "packet"
54878 + };
54879 +
54880 +static const char * gr_sockfamilies[AF_MAX+1] = {
54881 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54882 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54883 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54884 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54885 + };
54886 +
54887 +const char *
54888 +gr_proto_to_name(unsigned char proto)
54889 +{
54890 + return gr_protocols[proto];
54891 +}
54892 +
54893 +const char *
54894 +gr_socktype_to_name(unsigned char type)
54895 +{
54896 + return gr_socktypes[type];
54897 +}
54898 +
54899 +const char *
54900 +gr_sockfamily_to_name(unsigned char family)
54901 +{
54902 + return gr_sockfamilies[family];
54903 +}
54904 +
54905 +int
54906 +gr_search_socket(const int domain, const int type, const int protocol)
54907 +{
54908 + struct acl_subject_label *curr;
54909 + const struct cred *cred = current_cred();
54910 +
54911 + if (unlikely(!gr_acl_is_enabled()))
54912 + goto exit;
54913 +
54914 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
54915 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54916 + goto exit; // let the kernel handle it
54917 +
54918 + curr = current->acl;
54919 +
54920 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54921 + /* the family is allowed, if this is PF_INET allow it only if
54922 + the extra sock type/protocol checks pass */
54923 + if (domain == PF_INET)
54924 + goto inet_check;
54925 + goto exit;
54926 + } else {
54927 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54928 + __u32 fakeip = 0;
54929 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54930 + current->role->roletype, cred->uid,
54931 + cred->gid, current->exec_file ?
54932 + gr_to_filename(current->exec_file->f_path.dentry,
54933 + current->exec_file->f_path.mnt) :
54934 + curr->filename, curr->filename,
54935 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54936 + &current->signal->saved_ip);
54937 + goto exit;
54938 + }
54939 + goto exit_fail;
54940 + }
54941 +
54942 +inet_check:
54943 + /* the rest of this checking is for IPv4 only */
54944 + if (!curr->ips)
54945 + goto exit;
54946 +
54947 + if ((curr->ip_type & (1 << type)) &&
54948 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54949 + goto exit;
54950 +
54951 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54952 + /* we don't place acls on raw sockets , and sometimes
54953 + dgram/ip sockets are opened for ioctl and not
54954 + bind/connect, so we'll fake a bind learn log */
54955 + if (type == SOCK_RAW || type == SOCK_PACKET) {
54956 + __u32 fakeip = 0;
54957 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54958 + current->role->roletype, cred->uid,
54959 + cred->gid, current->exec_file ?
54960 + gr_to_filename(current->exec_file->f_path.dentry,
54961 + current->exec_file->f_path.mnt) :
54962 + curr->filename, curr->filename,
54963 + &fakeip, 0, type,
54964 + protocol, GR_CONNECT, &current->signal->saved_ip);
54965 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54966 + __u32 fakeip = 0;
54967 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54968 + current->role->roletype, cred->uid,
54969 + cred->gid, current->exec_file ?
54970 + gr_to_filename(current->exec_file->f_path.dentry,
54971 + current->exec_file->f_path.mnt) :
54972 + curr->filename, curr->filename,
54973 + &fakeip, 0, type,
54974 + protocol, GR_BIND, &current->signal->saved_ip);
54975 + }
54976 + /* we'll log when they use connect or bind */
54977 + goto exit;
54978 + }
54979 +
54980 +exit_fail:
54981 + if (domain == PF_INET)
54982 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54983 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
54984 + else
54985 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
54986 + gr_socktype_to_name(type), protocol);
54987 +
54988 + return 0;
54989 +exit:
54990 + return 1;
54991 +}
54992 +
54993 +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)
54994 +{
54995 + if ((ip->mode & mode) &&
54996 + (ip_port >= ip->low) &&
54997 + (ip_port <= ip->high) &&
54998 + ((ntohl(ip_addr) & our_netmask) ==
54999 + (ntohl(our_addr) & our_netmask))
55000 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55001 + && (ip->type & (1 << type))) {
55002 + if (ip->mode & GR_INVERT)
55003 + return 2; // specifically denied
55004 + else
55005 + return 1; // allowed
55006 + }
55007 +
55008 + return 0; // not specifically allowed, may continue parsing
55009 +}
55010 +
55011 +static int
55012 +gr_search_connectbind(const int full_mode, struct sock *sk,
55013 + struct sockaddr_in *addr, const int type)
55014 +{
55015 + char iface[IFNAMSIZ] = {0};
55016 + struct acl_subject_label *curr;
55017 + struct acl_ip_label *ip;
55018 + struct inet_sock *isk;
55019 + struct net_device *dev;
55020 + struct in_device *idev;
55021 + unsigned long i;
55022 + int ret;
55023 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55024 + __u32 ip_addr = 0;
55025 + __u32 our_addr;
55026 + __u32 our_netmask;
55027 + char *p;
55028 + __u16 ip_port = 0;
55029 + const struct cred *cred = current_cred();
55030 +
55031 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55032 + return 0;
55033 +
55034 + curr = current->acl;
55035 + isk = inet_sk(sk);
55036 +
55037 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55038 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55039 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55040 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55041 + struct sockaddr_in saddr;
55042 + int err;
55043 +
55044 + saddr.sin_family = AF_INET;
55045 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55046 + saddr.sin_port = isk->inet_sport;
55047 +
55048 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55049 + if (err)
55050 + return err;
55051 +
55052 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55053 + if (err)
55054 + return err;
55055 + }
55056 +
55057 + if (!curr->ips)
55058 + return 0;
55059 +
55060 + ip_addr = addr->sin_addr.s_addr;
55061 + ip_port = ntohs(addr->sin_port);
55062 +
55063 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55064 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55065 + current->role->roletype, cred->uid,
55066 + cred->gid, current->exec_file ?
55067 + gr_to_filename(current->exec_file->f_path.dentry,
55068 + current->exec_file->f_path.mnt) :
55069 + curr->filename, curr->filename,
55070 + &ip_addr, ip_port, type,
55071 + sk->sk_protocol, mode, &current->signal->saved_ip);
55072 + return 0;
55073 + }
55074 +
55075 + for (i = 0; i < curr->ip_num; i++) {
55076 + ip = *(curr->ips + i);
55077 + if (ip->iface != NULL) {
55078 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55079 + p = strchr(iface, ':');
55080 + if (p != NULL)
55081 + *p = '\0';
55082 + dev = dev_get_by_name(sock_net(sk), iface);
55083 + if (dev == NULL)
55084 + continue;
55085 + idev = in_dev_get(dev);
55086 + if (idev == NULL) {
55087 + dev_put(dev);
55088 + continue;
55089 + }
55090 + rcu_read_lock();
55091 + for_ifa(idev) {
55092 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55093 + our_addr = ifa->ifa_address;
55094 + our_netmask = 0xffffffff;
55095 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55096 + if (ret == 1) {
55097 + rcu_read_unlock();
55098 + in_dev_put(idev);
55099 + dev_put(dev);
55100 + return 0;
55101 + } else if (ret == 2) {
55102 + rcu_read_unlock();
55103 + in_dev_put(idev);
55104 + dev_put(dev);
55105 + goto denied;
55106 + }
55107 + }
55108 + } endfor_ifa(idev);
55109 + rcu_read_unlock();
55110 + in_dev_put(idev);
55111 + dev_put(dev);
55112 + } else {
55113 + our_addr = ip->addr;
55114 + our_netmask = ip->netmask;
55115 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55116 + if (ret == 1)
55117 + return 0;
55118 + else if (ret == 2)
55119 + goto denied;
55120 + }
55121 + }
55122 +
55123 +denied:
55124 + if (mode == GR_BIND)
55125 + 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));
55126 + else if (mode == GR_CONNECT)
55127 + 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));
55128 +
55129 + return -EACCES;
55130 +}
55131 +
55132 +int
55133 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55134 +{
55135 + /* always allow disconnection of dgram sockets with connect */
55136 + if (addr->sin_family == AF_UNSPEC)
55137 + return 0;
55138 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55139 +}
55140 +
55141 +int
55142 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55143 +{
55144 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55145 +}
55146 +
55147 +int gr_search_listen(struct socket *sock)
55148 +{
55149 + struct sock *sk = sock->sk;
55150 + struct sockaddr_in addr;
55151 +
55152 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55153 + addr.sin_port = inet_sk(sk)->inet_sport;
55154 +
55155 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55156 +}
55157 +
55158 +int gr_search_accept(struct socket *sock)
55159 +{
55160 + struct sock *sk = sock->sk;
55161 + struct sockaddr_in addr;
55162 +
55163 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55164 + addr.sin_port = inet_sk(sk)->inet_sport;
55165 +
55166 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55167 +}
55168 +
55169 +int
55170 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55171 +{
55172 + if (addr)
55173 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55174 + else {
55175 + struct sockaddr_in sin;
55176 + const struct inet_sock *inet = inet_sk(sk);
55177 +
55178 + sin.sin_addr.s_addr = inet->inet_daddr;
55179 + sin.sin_port = inet->inet_dport;
55180 +
55181 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55182 + }
55183 +}
55184 +
55185 +int
55186 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55187 +{
55188 + struct sockaddr_in sin;
55189 +
55190 + if (unlikely(skb->len < sizeof (struct udphdr)))
55191 + return 0; // skip this packet
55192 +
55193 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55194 + sin.sin_port = udp_hdr(skb)->source;
55195 +
55196 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55197 +}
55198 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55199 new file mode 100644
55200 index 0000000..25f54ef
55201 --- /dev/null
55202 +++ b/grsecurity/gracl_learn.c
55203 @@ -0,0 +1,207 @@
55204 +#include <linux/kernel.h>
55205 +#include <linux/mm.h>
55206 +#include <linux/sched.h>
55207 +#include <linux/poll.h>
55208 +#include <linux/string.h>
55209 +#include <linux/file.h>
55210 +#include <linux/types.h>
55211 +#include <linux/vmalloc.h>
55212 +#include <linux/grinternal.h>
55213 +
55214 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55215 + size_t count, loff_t *ppos);
55216 +extern int gr_acl_is_enabled(void);
55217 +
55218 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55219 +static int gr_learn_attached;
55220 +
55221 +/* use a 512k buffer */
55222 +#define LEARN_BUFFER_SIZE (512 * 1024)
55223 +
55224 +static DEFINE_SPINLOCK(gr_learn_lock);
55225 +static DEFINE_MUTEX(gr_learn_user_mutex);
55226 +
55227 +/* we need to maintain two buffers, so that the kernel context of grlearn
55228 + uses a semaphore around the userspace copying, and the other kernel contexts
55229 + use a spinlock when copying into the buffer, since they cannot sleep
55230 +*/
55231 +static char *learn_buffer;
55232 +static char *learn_buffer_user;
55233 +static int learn_buffer_len;
55234 +static int learn_buffer_user_len;
55235 +
55236 +static ssize_t
55237 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55238 +{
55239 + DECLARE_WAITQUEUE(wait, current);
55240 + ssize_t retval = 0;
55241 +
55242 + add_wait_queue(&learn_wait, &wait);
55243 + set_current_state(TASK_INTERRUPTIBLE);
55244 + do {
55245 + mutex_lock(&gr_learn_user_mutex);
55246 + spin_lock(&gr_learn_lock);
55247 + if (learn_buffer_len)
55248 + break;
55249 + spin_unlock(&gr_learn_lock);
55250 + mutex_unlock(&gr_learn_user_mutex);
55251 + if (file->f_flags & O_NONBLOCK) {
55252 + retval = -EAGAIN;
55253 + goto out;
55254 + }
55255 + if (signal_pending(current)) {
55256 + retval = -ERESTARTSYS;
55257 + goto out;
55258 + }
55259 +
55260 + schedule();
55261 + } while (1);
55262 +
55263 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55264 + learn_buffer_user_len = learn_buffer_len;
55265 + retval = learn_buffer_len;
55266 + learn_buffer_len = 0;
55267 +
55268 + spin_unlock(&gr_learn_lock);
55269 +
55270 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55271 + retval = -EFAULT;
55272 +
55273 + mutex_unlock(&gr_learn_user_mutex);
55274 +out:
55275 + set_current_state(TASK_RUNNING);
55276 + remove_wait_queue(&learn_wait, &wait);
55277 + return retval;
55278 +}
55279 +
55280 +static unsigned int
55281 +poll_learn(struct file * file, poll_table * wait)
55282 +{
55283 + poll_wait(file, &learn_wait, wait);
55284 +
55285 + if (learn_buffer_len)
55286 + return (POLLIN | POLLRDNORM);
55287 +
55288 + return 0;
55289 +}
55290 +
55291 +void
55292 +gr_clear_learn_entries(void)
55293 +{
55294 + char *tmp;
55295 +
55296 + mutex_lock(&gr_learn_user_mutex);
55297 + spin_lock(&gr_learn_lock);
55298 + tmp = learn_buffer;
55299 + learn_buffer = NULL;
55300 + spin_unlock(&gr_learn_lock);
55301 + if (tmp)
55302 + vfree(tmp);
55303 + if (learn_buffer_user != NULL) {
55304 + vfree(learn_buffer_user);
55305 + learn_buffer_user = NULL;
55306 + }
55307 + learn_buffer_len = 0;
55308 + mutex_unlock(&gr_learn_user_mutex);
55309 +
55310 + return;
55311 +}
55312 +
55313 +void
55314 +gr_add_learn_entry(const char *fmt, ...)
55315 +{
55316 + va_list args;
55317 + unsigned int len;
55318 +
55319 + if (!gr_learn_attached)
55320 + return;
55321 +
55322 + spin_lock(&gr_learn_lock);
55323 +
55324 + /* leave a gap at the end so we know when it's "full" but don't have to
55325 + compute the exact length of the string we're trying to append
55326 + */
55327 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55328 + spin_unlock(&gr_learn_lock);
55329 + wake_up_interruptible(&learn_wait);
55330 + return;
55331 + }
55332 + if (learn_buffer == NULL) {
55333 + spin_unlock(&gr_learn_lock);
55334 + return;
55335 + }
55336 +
55337 + va_start(args, fmt);
55338 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55339 + va_end(args);
55340 +
55341 + learn_buffer_len += len + 1;
55342 +
55343 + spin_unlock(&gr_learn_lock);
55344 + wake_up_interruptible(&learn_wait);
55345 +
55346 + return;
55347 +}
55348 +
55349 +static int
55350 +open_learn(struct inode *inode, struct file *file)
55351 +{
55352 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55353 + return -EBUSY;
55354 + if (file->f_mode & FMODE_READ) {
55355 + int retval = 0;
55356 + mutex_lock(&gr_learn_user_mutex);
55357 + if (learn_buffer == NULL)
55358 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55359 + if (learn_buffer_user == NULL)
55360 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55361 + if (learn_buffer == NULL) {
55362 + retval = -ENOMEM;
55363 + goto out_error;
55364 + }
55365 + if (learn_buffer_user == NULL) {
55366 + retval = -ENOMEM;
55367 + goto out_error;
55368 + }
55369 + learn_buffer_len = 0;
55370 + learn_buffer_user_len = 0;
55371 + gr_learn_attached = 1;
55372 +out_error:
55373 + mutex_unlock(&gr_learn_user_mutex);
55374 + return retval;
55375 + }
55376 + return 0;
55377 +}
55378 +
55379 +static int
55380 +close_learn(struct inode *inode, struct file *file)
55381 +{
55382 + if (file->f_mode & FMODE_READ) {
55383 + char *tmp = NULL;
55384 + mutex_lock(&gr_learn_user_mutex);
55385 + spin_lock(&gr_learn_lock);
55386 + tmp = learn_buffer;
55387 + learn_buffer = NULL;
55388 + spin_unlock(&gr_learn_lock);
55389 + if (tmp)
55390 + vfree(tmp);
55391 + if (learn_buffer_user != NULL) {
55392 + vfree(learn_buffer_user);
55393 + learn_buffer_user = NULL;
55394 + }
55395 + learn_buffer_len = 0;
55396 + learn_buffer_user_len = 0;
55397 + gr_learn_attached = 0;
55398 + mutex_unlock(&gr_learn_user_mutex);
55399 + }
55400 +
55401 + return 0;
55402 +}
55403 +
55404 +const struct file_operations grsec_fops = {
55405 + .read = read_learn,
55406 + .write = write_grsec_handler,
55407 + .open = open_learn,
55408 + .release = close_learn,
55409 + .poll = poll_learn,
55410 +};
55411 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55412 new file mode 100644
55413 index 0000000..39645c9
55414 --- /dev/null
55415 +++ b/grsecurity/gracl_res.c
55416 @@ -0,0 +1,68 @@
55417 +#include <linux/kernel.h>
55418 +#include <linux/sched.h>
55419 +#include <linux/gracl.h>
55420 +#include <linux/grinternal.h>
55421 +
55422 +static const char *restab_log[] = {
55423 + [RLIMIT_CPU] = "RLIMIT_CPU",
55424 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55425 + [RLIMIT_DATA] = "RLIMIT_DATA",
55426 + [RLIMIT_STACK] = "RLIMIT_STACK",
55427 + [RLIMIT_CORE] = "RLIMIT_CORE",
55428 + [RLIMIT_RSS] = "RLIMIT_RSS",
55429 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55430 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55431 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55432 + [RLIMIT_AS] = "RLIMIT_AS",
55433 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55434 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55435 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55436 + [RLIMIT_NICE] = "RLIMIT_NICE",
55437 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55438 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55439 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55440 +};
55441 +
55442 +void
55443 +gr_log_resource(const struct task_struct *task,
55444 + const int res, const unsigned long wanted, const int gt)
55445 +{
55446 + const struct cred *cred;
55447 + unsigned long rlim;
55448 +
55449 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55450 + return;
55451 +
55452 + // not yet supported resource
55453 + if (unlikely(!restab_log[res]))
55454 + return;
55455 +
55456 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55457 + rlim = task_rlimit_max(task, res);
55458 + else
55459 + rlim = task_rlimit(task, res);
55460 +
55461 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55462 + return;
55463 +
55464 + rcu_read_lock();
55465 + cred = __task_cred(task);
55466 +
55467 + if (res == RLIMIT_NPROC &&
55468 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55469 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55470 + goto out_rcu_unlock;
55471 + else if (res == RLIMIT_MEMLOCK &&
55472 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55473 + goto out_rcu_unlock;
55474 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55475 + goto out_rcu_unlock;
55476 + rcu_read_unlock();
55477 +
55478 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55479 +
55480 + return;
55481 +out_rcu_unlock:
55482 + rcu_read_unlock();
55483 + return;
55484 +}
55485 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55486 new file mode 100644
55487 index 0000000..5556be3
55488 --- /dev/null
55489 +++ b/grsecurity/gracl_segv.c
55490 @@ -0,0 +1,299 @@
55491 +#include <linux/kernel.h>
55492 +#include <linux/mm.h>
55493 +#include <asm/uaccess.h>
55494 +#include <asm/errno.h>
55495 +#include <asm/mman.h>
55496 +#include <net/sock.h>
55497 +#include <linux/file.h>
55498 +#include <linux/fs.h>
55499 +#include <linux/net.h>
55500 +#include <linux/in.h>
55501 +#include <linux/slab.h>
55502 +#include <linux/types.h>
55503 +#include <linux/sched.h>
55504 +#include <linux/timer.h>
55505 +#include <linux/gracl.h>
55506 +#include <linux/grsecurity.h>
55507 +#include <linux/grinternal.h>
55508 +
55509 +static struct crash_uid *uid_set;
55510 +static unsigned short uid_used;
55511 +static DEFINE_SPINLOCK(gr_uid_lock);
55512 +extern rwlock_t gr_inode_lock;
55513 +extern struct acl_subject_label *
55514 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55515 + struct acl_role_label *role);
55516 +
55517 +#ifdef CONFIG_BTRFS_FS
55518 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55519 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55520 +#endif
55521 +
55522 +static inline dev_t __get_dev(const struct dentry *dentry)
55523 +{
55524 +#ifdef CONFIG_BTRFS_FS
55525 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55526 + return get_btrfs_dev_from_inode(dentry->d_inode);
55527 + else
55528 +#endif
55529 + return dentry->d_inode->i_sb->s_dev;
55530 +}
55531 +
55532 +int
55533 +gr_init_uidset(void)
55534 +{
55535 + uid_set =
55536 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55537 + uid_used = 0;
55538 +
55539 + return uid_set ? 1 : 0;
55540 +}
55541 +
55542 +void
55543 +gr_free_uidset(void)
55544 +{
55545 + if (uid_set)
55546 + kfree(uid_set);
55547 +
55548 + return;
55549 +}
55550 +
55551 +int
55552 +gr_find_uid(const uid_t uid)
55553 +{
55554 + struct crash_uid *tmp = uid_set;
55555 + uid_t buid;
55556 + int low = 0, high = uid_used - 1, mid;
55557 +
55558 + while (high >= low) {
55559 + mid = (low + high) >> 1;
55560 + buid = tmp[mid].uid;
55561 + if (buid == uid)
55562 + return mid;
55563 + if (buid > uid)
55564 + high = mid - 1;
55565 + if (buid < uid)
55566 + low = mid + 1;
55567 + }
55568 +
55569 + return -1;
55570 +}
55571 +
55572 +static __inline__ void
55573 +gr_insertsort(void)
55574 +{
55575 + unsigned short i, j;
55576 + struct crash_uid index;
55577 +
55578 + for (i = 1; i < uid_used; i++) {
55579 + index = uid_set[i];
55580 + j = i;
55581 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55582 + uid_set[j] = uid_set[j - 1];
55583 + j--;
55584 + }
55585 + uid_set[j] = index;
55586 + }
55587 +
55588 + return;
55589 +}
55590 +
55591 +static __inline__ void
55592 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55593 +{
55594 + int loc;
55595 +
55596 + if (uid_used == GR_UIDTABLE_MAX)
55597 + return;
55598 +
55599 + loc = gr_find_uid(uid);
55600 +
55601 + if (loc >= 0) {
55602 + uid_set[loc].expires = expires;
55603 + return;
55604 + }
55605 +
55606 + uid_set[uid_used].uid = uid;
55607 + uid_set[uid_used].expires = expires;
55608 + uid_used++;
55609 +
55610 + gr_insertsort();
55611 +
55612 + return;
55613 +}
55614 +
55615 +void
55616 +gr_remove_uid(const unsigned short loc)
55617 +{
55618 + unsigned short i;
55619 +
55620 + for (i = loc + 1; i < uid_used; i++)
55621 + uid_set[i - 1] = uid_set[i];
55622 +
55623 + uid_used--;
55624 +
55625 + return;
55626 +}
55627 +
55628 +int
55629 +gr_check_crash_uid(const uid_t uid)
55630 +{
55631 + int loc;
55632 + int ret = 0;
55633 +
55634 + if (unlikely(!gr_acl_is_enabled()))
55635 + return 0;
55636 +
55637 + spin_lock(&gr_uid_lock);
55638 + loc = gr_find_uid(uid);
55639 +
55640 + if (loc < 0)
55641 + goto out_unlock;
55642 +
55643 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55644 + gr_remove_uid(loc);
55645 + else
55646 + ret = 1;
55647 +
55648 +out_unlock:
55649 + spin_unlock(&gr_uid_lock);
55650 + return ret;
55651 +}
55652 +
55653 +static __inline__ int
55654 +proc_is_setxid(const struct cred *cred)
55655 +{
55656 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55657 + cred->uid != cred->fsuid)
55658 + return 1;
55659 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55660 + cred->gid != cred->fsgid)
55661 + return 1;
55662 +
55663 + return 0;
55664 +}
55665 +
55666 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55667 +
55668 +void
55669 +gr_handle_crash(struct task_struct *task, const int sig)
55670 +{
55671 + struct acl_subject_label *curr;
55672 + struct task_struct *tsk, *tsk2;
55673 + const struct cred *cred;
55674 + const struct cred *cred2;
55675 +
55676 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55677 + return;
55678 +
55679 + if (unlikely(!gr_acl_is_enabled()))
55680 + return;
55681 +
55682 + curr = task->acl;
55683 +
55684 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55685 + return;
55686 +
55687 + if (time_before_eq(curr->expires, get_seconds())) {
55688 + curr->expires = 0;
55689 + curr->crashes = 0;
55690 + }
55691 +
55692 + curr->crashes++;
55693 +
55694 + if (!curr->expires)
55695 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55696 +
55697 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55698 + time_after(curr->expires, get_seconds())) {
55699 + rcu_read_lock();
55700 + cred = __task_cred(task);
55701 + if (cred->uid && proc_is_setxid(cred)) {
55702 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55703 + spin_lock(&gr_uid_lock);
55704 + gr_insert_uid(cred->uid, curr->expires);
55705 + spin_unlock(&gr_uid_lock);
55706 + curr->expires = 0;
55707 + curr->crashes = 0;
55708 + read_lock(&tasklist_lock);
55709 + do_each_thread(tsk2, tsk) {
55710 + cred2 = __task_cred(tsk);
55711 + if (tsk != task && cred2->uid == cred->uid)
55712 + gr_fake_force_sig(SIGKILL, tsk);
55713 + } while_each_thread(tsk2, tsk);
55714 + read_unlock(&tasklist_lock);
55715 + } else {
55716 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55717 + read_lock(&tasklist_lock);
55718 + read_lock(&grsec_exec_file_lock);
55719 + do_each_thread(tsk2, tsk) {
55720 + if (likely(tsk != task)) {
55721 + // if this thread has the same subject as the one that triggered
55722 + // RES_CRASH and it's the same binary, kill it
55723 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55724 + gr_fake_force_sig(SIGKILL, tsk);
55725 + }
55726 + } while_each_thread(tsk2, tsk);
55727 + read_unlock(&grsec_exec_file_lock);
55728 + read_unlock(&tasklist_lock);
55729 + }
55730 + rcu_read_unlock();
55731 + }
55732 +
55733 + return;
55734 +}
55735 +
55736 +int
55737 +gr_check_crash_exec(const struct file *filp)
55738 +{
55739 + struct acl_subject_label *curr;
55740 +
55741 + if (unlikely(!gr_acl_is_enabled()))
55742 + return 0;
55743 +
55744 + read_lock(&gr_inode_lock);
55745 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55746 + __get_dev(filp->f_path.dentry),
55747 + current->role);
55748 + read_unlock(&gr_inode_lock);
55749 +
55750 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55751 + (!curr->crashes && !curr->expires))
55752 + return 0;
55753 +
55754 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55755 + time_after(curr->expires, get_seconds()))
55756 + return 1;
55757 + else if (time_before_eq(curr->expires, get_seconds())) {
55758 + curr->crashes = 0;
55759 + curr->expires = 0;
55760 + }
55761 +
55762 + return 0;
55763 +}
55764 +
55765 +void
55766 +gr_handle_alertkill(struct task_struct *task)
55767 +{
55768 + struct acl_subject_label *curracl;
55769 + __u32 curr_ip;
55770 + struct task_struct *p, *p2;
55771 +
55772 + if (unlikely(!gr_acl_is_enabled()))
55773 + return;
55774 +
55775 + curracl = task->acl;
55776 + curr_ip = task->signal->curr_ip;
55777 +
55778 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55779 + read_lock(&tasklist_lock);
55780 + do_each_thread(p2, p) {
55781 + if (p->signal->curr_ip == curr_ip)
55782 + gr_fake_force_sig(SIGKILL, p);
55783 + } while_each_thread(p2, p);
55784 + read_unlock(&tasklist_lock);
55785 + } else if (curracl->mode & GR_KILLPROC)
55786 + gr_fake_force_sig(SIGKILL, task);
55787 +
55788 + return;
55789 +}
55790 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55791 new file mode 100644
55792 index 0000000..9d83a69
55793 --- /dev/null
55794 +++ b/grsecurity/gracl_shm.c
55795 @@ -0,0 +1,40 @@
55796 +#include <linux/kernel.h>
55797 +#include <linux/mm.h>
55798 +#include <linux/sched.h>
55799 +#include <linux/file.h>
55800 +#include <linux/ipc.h>
55801 +#include <linux/gracl.h>
55802 +#include <linux/grsecurity.h>
55803 +#include <linux/grinternal.h>
55804 +
55805 +int
55806 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55807 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55808 +{
55809 + struct task_struct *task;
55810 +
55811 + if (!gr_acl_is_enabled())
55812 + return 1;
55813 +
55814 + rcu_read_lock();
55815 + read_lock(&tasklist_lock);
55816 +
55817 + task = find_task_by_vpid(shm_cprid);
55818 +
55819 + if (unlikely(!task))
55820 + task = find_task_by_vpid(shm_lapid);
55821 +
55822 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55823 + (task->pid == shm_lapid)) &&
55824 + (task->acl->mode & GR_PROTSHM) &&
55825 + (task->acl != current->acl))) {
55826 + read_unlock(&tasklist_lock);
55827 + rcu_read_unlock();
55828 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55829 + return 0;
55830 + }
55831 + read_unlock(&tasklist_lock);
55832 + rcu_read_unlock();
55833 +
55834 + return 1;
55835 +}
55836 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55837 new file mode 100644
55838 index 0000000..bc0be01
55839 --- /dev/null
55840 +++ b/grsecurity/grsec_chdir.c
55841 @@ -0,0 +1,19 @@
55842 +#include <linux/kernel.h>
55843 +#include <linux/sched.h>
55844 +#include <linux/fs.h>
55845 +#include <linux/file.h>
55846 +#include <linux/grsecurity.h>
55847 +#include <linux/grinternal.h>
55848 +
55849 +void
55850 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55851 +{
55852 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55853 + if ((grsec_enable_chdir && grsec_enable_group &&
55854 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55855 + !grsec_enable_group)) {
55856 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55857 + }
55858 +#endif
55859 + return;
55860 +}
55861 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55862 new file mode 100644
55863 index 0000000..9807ee2
55864 --- /dev/null
55865 +++ b/grsecurity/grsec_chroot.c
55866 @@ -0,0 +1,368 @@
55867 +#include <linux/kernel.h>
55868 +#include <linux/module.h>
55869 +#include <linux/sched.h>
55870 +#include <linux/file.h>
55871 +#include <linux/fs.h>
55872 +#include <linux/mount.h>
55873 +#include <linux/types.h>
55874 +#include "../fs/mount.h"
55875 +#include <linux/grsecurity.h>
55876 +#include <linux/grinternal.h>
55877 +
55878 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55879 +{
55880 +#ifdef CONFIG_GRKERNSEC
55881 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55882 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55883 + task->gr_is_chrooted = 1;
55884 + else
55885 + task->gr_is_chrooted = 0;
55886 +
55887 + task->gr_chroot_dentry = path->dentry;
55888 +#endif
55889 + return;
55890 +}
55891 +
55892 +void gr_clear_chroot_entries(struct task_struct *task)
55893 +{
55894 +#ifdef CONFIG_GRKERNSEC
55895 + task->gr_is_chrooted = 0;
55896 + task->gr_chroot_dentry = NULL;
55897 +#endif
55898 + return;
55899 +}
55900 +
55901 +int
55902 +gr_handle_chroot_unix(const pid_t pid)
55903 +{
55904 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55905 + struct task_struct *p;
55906 +
55907 + if (unlikely(!grsec_enable_chroot_unix))
55908 + return 1;
55909 +
55910 + if (likely(!proc_is_chrooted(current)))
55911 + return 1;
55912 +
55913 + rcu_read_lock();
55914 + read_lock(&tasklist_lock);
55915 + p = find_task_by_vpid_unrestricted(pid);
55916 + if (unlikely(p && !have_same_root(current, p))) {
55917 + read_unlock(&tasklist_lock);
55918 + rcu_read_unlock();
55919 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55920 + return 0;
55921 + }
55922 + read_unlock(&tasklist_lock);
55923 + rcu_read_unlock();
55924 +#endif
55925 + return 1;
55926 +}
55927 +
55928 +int
55929 +gr_handle_chroot_nice(void)
55930 +{
55931 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55932 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55933 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55934 + return -EPERM;
55935 + }
55936 +#endif
55937 + return 0;
55938 +}
55939 +
55940 +int
55941 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55942 +{
55943 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55944 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55945 + && proc_is_chrooted(current)) {
55946 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55947 + return -EACCES;
55948 + }
55949 +#endif
55950 + return 0;
55951 +}
55952 +
55953 +int
55954 +gr_handle_chroot_rawio(const struct inode *inode)
55955 +{
55956 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55957 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55958 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55959 + return 1;
55960 +#endif
55961 + return 0;
55962 +}
55963 +
55964 +int
55965 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55966 +{
55967 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55968 + struct task_struct *p;
55969 + int ret = 0;
55970 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55971 + return ret;
55972 +
55973 + read_lock(&tasklist_lock);
55974 + do_each_pid_task(pid, type, p) {
55975 + if (!have_same_root(current, p)) {
55976 + ret = 1;
55977 + goto out;
55978 + }
55979 + } while_each_pid_task(pid, type, p);
55980 +out:
55981 + read_unlock(&tasklist_lock);
55982 + return ret;
55983 +#endif
55984 + return 0;
55985 +}
55986 +
55987 +int
55988 +gr_pid_is_chrooted(struct task_struct *p)
55989 +{
55990 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55991 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
55992 + return 0;
55993 +
55994 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
55995 + !have_same_root(current, p)) {
55996 + return 1;
55997 + }
55998 +#endif
55999 + return 0;
56000 +}
56001 +
56002 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56003 +
56004 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56005 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56006 +{
56007 + struct path path, currentroot;
56008 + int ret = 0;
56009 +
56010 + path.dentry = (struct dentry *)u_dentry;
56011 + path.mnt = (struct vfsmount *)u_mnt;
56012 + get_fs_root(current->fs, &currentroot);
56013 + if (path_is_under(&path, &currentroot))
56014 + ret = 1;
56015 + path_put(&currentroot);
56016 +
56017 + return ret;
56018 +}
56019 +#endif
56020 +
56021 +int
56022 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56023 +{
56024 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56025 + if (!grsec_enable_chroot_fchdir)
56026 + return 1;
56027 +
56028 + if (!proc_is_chrooted(current))
56029 + return 1;
56030 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56031 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56032 + return 0;
56033 + }
56034 +#endif
56035 + return 1;
56036 +}
56037 +
56038 +int
56039 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56040 + const time_t shm_createtime)
56041 +{
56042 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56043 + struct task_struct *p;
56044 + time_t starttime;
56045 +
56046 + if (unlikely(!grsec_enable_chroot_shmat))
56047 + return 1;
56048 +
56049 + if (likely(!proc_is_chrooted(current)))
56050 + return 1;
56051 +
56052 + rcu_read_lock();
56053 + read_lock(&tasklist_lock);
56054 +
56055 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56056 + starttime = p->start_time.tv_sec;
56057 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56058 + if (have_same_root(current, p)) {
56059 + goto allow;
56060 + } else {
56061 + read_unlock(&tasklist_lock);
56062 + rcu_read_unlock();
56063 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56064 + return 0;
56065 + }
56066 + }
56067 + /* creator exited, pid reuse, fall through to next check */
56068 + }
56069 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56070 + if (unlikely(!have_same_root(current, p))) {
56071 + read_unlock(&tasklist_lock);
56072 + rcu_read_unlock();
56073 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56074 + return 0;
56075 + }
56076 + }
56077 +
56078 +allow:
56079 + read_unlock(&tasklist_lock);
56080 + rcu_read_unlock();
56081 +#endif
56082 + return 1;
56083 +}
56084 +
56085 +void
56086 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56087 +{
56088 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56089 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56090 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56091 +#endif
56092 + return;
56093 +}
56094 +
56095 +int
56096 +gr_handle_chroot_mknod(const struct dentry *dentry,
56097 + const struct vfsmount *mnt, const int mode)
56098 +{
56099 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56100 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56101 + proc_is_chrooted(current)) {
56102 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56103 + return -EPERM;
56104 + }
56105 +#endif
56106 + return 0;
56107 +}
56108 +
56109 +int
56110 +gr_handle_chroot_mount(const struct dentry *dentry,
56111 + const struct vfsmount *mnt, const char *dev_name)
56112 +{
56113 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56114 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56115 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56116 + return -EPERM;
56117 + }
56118 +#endif
56119 + return 0;
56120 +}
56121 +
56122 +int
56123 +gr_handle_chroot_pivot(void)
56124 +{
56125 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56126 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56127 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56128 + return -EPERM;
56129 + }
56130 +#endif
56131 + return 0;
56132 +}
56133 +
56134 +int
56135 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56136 +{
56137 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56138 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56139 + !gr_is_outside_chroot(dentry, mnt)) {
56140 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56141 + return -EPERM;
56142 + }
56143 +#endif
56144 + return 0;
56145 +}
56146 +
56147 +extern const char *captab_log[];
56148 +extern int captab_log_entries;
56149 +
56150 +int
56151 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56152 +{
56153 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56154 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56155 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56156 + if (cap_raised(chroot_caps, cap)) {
56157 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56158 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56159 + }
56160 + return 0;
56161 + }
56162 + }
56163 +#endif
56164 + return 1;
56165 +}
56166 +
56167 +int
56168 +gr_chroot_is_capable(const int cap)
56169 +{
56170 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56171 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56172 +#endif
56173 + return 1;
56174 +}
56175 +
56176 +int
56177 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56178 +{
56179 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56180 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56181 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56182 + if (cap_raised(chroot_caps, cap)) {
56183 + return 0;
56184 + }
56185 + }
56186 +#endif
56187 + return 1;
56188 +}
56189 +
56190 +int
56191 +gr_chroot_is_capable_nolog(const int cap)
56192 +{
56193 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56194 + return gr_task_chroot_is_capable_nolog(current, cap);
56195 +#endif
56196 + return 1;
56197 +}
56198 +
56199 +int
56200 +gr_handle_chroot_sysctl(const int op)
56201 +{
56202 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56203 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56204 + proc_is_chrooted(current))
56205 + return -EACCES;
56206 +#endif
56207 + return 0;
56208 +}
56209 +
56210 +void
56211 +gr_handle_chroot_chdir(struct path *path)
56212 +{
56213 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56214 + if (grsec_enable_chroot_chdir)
56215 + set_fs_pwd(current->fs, path);
56216 +#endif
56217 + return;
56218 +}
56219 +
56220 +int
56221 +gr_handle_chroot_chmod(const struct dentry *dentry,
56222 + const struct vfsmount *mnt, const int mode)
56223 +{
56224 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56225 + /* allow chmod +s on directories, but not files */
56226 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56227 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56228 + proc_is_chrooted(current)) {
56229 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56230 + return -EPERM;
56231 + }
56232 +#endif
56233 + return 0;
56234 +}
56235 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56236 new file mode 100644
56237 index 0000000..213ad8b
56238 --- /dev/null
56239 +++ b/grsecurity/grsec_disabled.c
56240 @@ -0,0 +1,437 @@
56241 +#include <linux/kernel.h>
56242 +#include <linux/module.h>
56243 +#include <linux/sched.h>
56244 +#include <linux/file.h>
56245 +#include <linux/fs.h>
56246 +#include <linux/kdev_t.h>
56247 +#include <linux/net.h>
56248 +#include <linux/in.h>
56249 +#include <linux/ip.h>
56250 +#include <linux/skbuff.h>
56251 +#include <linux/sysctl.h>
56252 +
56253 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56254 +void
56255 +pax_set_initial_flags(struct linux_binprm *bprm)
56256 +{
56257 + return;
56258 +}
56259 +#endif
56260 +
56261 +#ifdef CONFIG_SYSCTL
56262 +__u32
56263 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56264 +{
56265 + return 0;
56266 +}
56267 +#endif
56268 +
56269 +#ifdef CONFIG_TASKSTATS
56270 +int gr_is_taskstats_denied(int pid)
56271 +{
56272 + return 0;
56273 +}
56274 +#endif
56275 +
56276 +int
56277 +gr_acl_is_enabled(void)
56278 +{
56279 + return 0;
56280 +}
56281 +
56282 +void
56283 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56284 +{
56285 + return;
56286 +}
56287 +
56288 +int
56289 +gr_handle_rawio(const struct inode *inode)
56290 +{
56291 + return 0;
56292 +}
56293 +
56294 +void
56295 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56296 +{
56297 + return;
56298 +}
56299 +
56300 +int
56301 +gr_handle_ptrace(struct task_struct *task, const long request)
56302 +{
56303 + return 0;
56304 +}
56305 +
56306 +int
56307 +gr_handle_proc_ptrace(struct task_struct *task)
56308 +{
56309 + return 0;
56310 +}
56311 +
56312 +void
56313 +gr_learn_resource(const struct task_struct *task,
56314 + const int res, const unsigned long wanted, const int gt)
56315 +{
56316 + return;
56317 +}
56318 +
56319 +int
56320 +gr_set_acls(const int type)
56321 +{
56322 + return 0;
56323 +}
56324 +
56325 +int
56326 +gr_check_hidden_task(const struct task_struct *tsk)
56327 +{
56328 + return 0;
56329 +}
56330 +
56331 +int
56332 +gr_check_protected_task(const struct task_struct *task)
56333 +{
56334 + return 0;
56335 +}
56336 +
56337 +int
56338 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56339 +{
56340 + return 0;
56341 +}
56342 +
56343 +void
56344 +gr_copy_label(struct task_struct *tsk)
56345 +{
56346 + return;
56347 +}
56348 +
56349 +void
56350 +gr_set_pax_flags(struct task_struct *task)
56351 +{
56352 + return;
56353 +}
56354 +
56355 +int
56356 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56357 + const int unsafe_share)
56358 +{
56359 + return 0;
56360 +}
56361 +
56362 +void
56363 +gr_handle_delete(const ino_t ino, const dev_t dev)
56364 +{
56365 + return;
56366 +}
56367 +
56368 +void
56369 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56370 +{
56371 + return;
56372 +}
56373 +
56374 +void
56375 +gr_handle_crash(struct task_struct *task, const int sig)
56376 +{
56377 + return;
56378 +}
56379 +
56380 +int
56381 +gr_check_crash_exec(const struct file *filp)
56382 +{
56383 + return 0;
56384 +}
56385 +
56386 +int
56387 +gr_check_crash_uid(const uid_t uid)
56388 +{
56389 + return 0;
56390 +}
56391 +
56392 +void
56393 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56394 + struct dentry *old_dentry,
56395 + struct dentry *new_dentry,
56396 + struct vfsmount *mnt, const __u8 replace)
56397 +{
56398 + return;
56399 +}
56400 +
56401 +int
56402 +gr_search_socket(const int family, const int type, const int protocol)
56403 +{
56404 + return 1;
56405 +}
56406 +
56407 +int
56408 +gr_search_connectbind(const int mode, const struct socket *sock,
56409 + const struct sockaddr_in *addr)
56410 +{
56411 + return 0;
56412 +}
56413 +
56414 +void
56415 +gr_handle_alertkill(struct task_struct *task)
56416 +{
56417 + return;
56418 +}
56419 +
56420 +__u32
56421 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56422 +{
56423 + return 1;
56424 +}
56425 +
56426 +__u32
56427 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56428 + const struct vfsmount * mnt)
56429 +{
56430 + return 1;
56431 +}
56432 +
56433 +__u32
56434 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56435 + int acc_mode)
56436 +{
56437 + return 1;
56438 +}
56439 +
56440 +__u32
56441 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56442 +{
56443 + return 1;
56444 +}
56445 +
56446 +__u32
56447 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56448 +{
56449 + return 1;
56450 +}
56451 +
56452 +int
56453 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56454 + unsigned int *vm_flags)
56455 +{
56456 + return 1;
56457 +}
56458 +
56459 +__u32
56460 +gr_acl_handle_truncate(const struct dentry * dentry,
56461 + const struct vfsmount * mnt)
56462 +{
56463 + return 1;
56464 +}
56465 +
56466 +__u32
56467 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56468 +{
56469 + return 1;
56470 +}
56471 +
56472 +__u32
56473 +gr_acl_handle_access(const struct dentry * dentry,
56474 + const struct vfsmount * mnt, const int fmode)
56475 +{
56476 + return 1;
56477 +}
56478 +
56479 +__u32
56480 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56481 + umode_t *mode)
56482 +{
56483 + return 1;
56484 +}
56485 +
56486 +__u32
56487 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56488 +{
56489 + return 1;
56490 +}
56491 +
56492 +__u32
56493 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56494 +{
56495 + return 1;
56496 +}
56497 +
56498 +void
56499 +grsecurity_init(void)
56500 +{
56501 + return;
56502 +}
56503 +
56504 +umode_t gr_acl_umask(void)
56505 +{
56506 + return 0;
56507 +}
56508 +
56509 +__u32
56510 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56511 + const struct dentry * parent_dentry,
56512 + const struct vfsmount * parent_mnt,
56513 + const int mode)
56514 +{
56515 + return 1;
56516 +}
56517 +
56518 +__u32
56519 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56520 + const struct dentry * parent_dentry,
56521 + const struct vfsmount * parent_mnt)
56522 +{
56523 + return 1;
56524 +}
56525 +
56526 +__u32
56527 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56528 + const struct dentry * parent_dentry,
56529 + const struct vfsmount * parent_mnt, const char *from)
56530 +{
56531 + return 1;
56532 +}
56533 +
56534 +__u32
56535 +gr_acl_handle_link(const struct dentry * new_dentry,
56536 + const struct dentry * parent_dentry,
56537 + const struct vfsmount * parent_mnt,
56538 + const struct dentry * old_dentry,
56539 + const struct vfsmount * old_mnt, const char *to)
56540 +{
56541 + return 1;
56542 +}
56543 +
56544 +int
56545 +gr_acl_handle_rename(const struct dentry *new_dentry,
56546 + const struct dentry *parent_dentry,
56547 + const struct vfsmount *parent_mnt,
56548 + const struct dentry *old_dentry,
56549 + const struct inode *old_parent_inode,
56550 + const struct vfsmount *old_mnt, const char *newname)
56551 +{
56552 + return 0;
56553 +}
56554 +
56555 +int
56556 +gr_acl_handle_filldir(const struct file *file, const char *name,
56557 + const int namelen, const ino_t ino)
56558 +{
56559 + return 1;
56560 +}
56561 +
56562 +int
56563 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56564 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56565 +{
56566 + return 1;
56567 +}
56568 +
56569 +int
56570 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56571 +{
56572 + return 0;
56573 +}
56574 +
56575 +int
56576 +gr_search_accept(const struct socket *sock)
56577 +{
56578 + return 0;
56579 +}
56580 +
56581 +int
56582 +gr_search_listen(const struct socket *sock)
56583 +{
56584 + return 0;
56585 +}
56586 +
56587 +int
56588 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56589 +{
56590 + return 0;
56591 +}
56592 +
56593 +__u32
56594 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56595 +{
56596 + return 1;
56597 +}
56598 +
56599 +__u32
56600 +gr_acl_handle_creat(const struct dentry * dentry,
56601 + const struct dentry * p_dentry,
56602 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56603 + const int imode)
56604 +{
56605 + return 1;
56606 +}
56607 +
56608 +void
56609 +gr_acl_handle_exit(void)
56610 +{
56611 + return;
56612 +}
56613 +
56614 +int
56615 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56616 +{
56617 + return 1;
56618 +}
56619 +
56620 +void
56621 +gr_set_role_label(const uid_t uid, const gid_t gid)
56622 +{
56623 + return;
56624 +}
56625 +
56626 +int
56627 +gr_acl_handle_procpidmem(const struct task_struct *task)
56628 +{
56629 + return 0;
56630 +}
56631 +
56632 +int
56633 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56634 +{
56635 + return 0;
56636 +}
56637 +
56638 +int
56639 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56640 +{
56641 + return 0;
56642 +}
56643 +
56644 +void
56645 +gr_set_kernel_label(struct task_struct *task)
56646 +{
56647 + return;
56648 +}
56649 +
56650 +int
56651 +gr_check_user_change(int real, int effective, int fs)
56652 +{
56653 + return 0;
56654 +}
56655 +
56656 +int
56657 +gr_check_group_change(int real, int effective, int fs)
56658 +{
56659 + return 0;
56660 +}
56661 +
56662 +int gr_acl_enable_at_secure(void)
56663 +{
56664 + return 0;
56665 +}
56666 +
56667 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56668 +{
56669 + return dentry->d_inode->i_sb->s_dev;
56670 +}
56671 +
56672 +EXPORT_SYMBOL(gr_learn_resource);
56673 +EXPORT_SYMBOL(gr_set_kernel_label);
56674 +#ifdef CONFIG_SECURITY
56675 +EXPORT_SYMBOL(gr_check_user_change);
56676 +EXPORT_SYMBOL(gr_check_group_change);
56677 +#endif
56678 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56679 new file mode 100644
56680 index 0000000..abfa971
56681 --- /dev/null
56682 +++ b/grsecurity/grsec_exec.c
56683 @@ -0,0 +1,174 @@
56684 +#include <linux/kernel.h>
56685 +#include <linux/sched.h>
56686 +#include <linux/file.h>
56687 +#include <linux/binfmts.h>
56688 +#include <linux/fs.h>
56689 +#include <linux/types.h>
56690 +#include <linux/grdefs.h>
56691 +#include <linux/grsecurity.h>
56692 +#include <linux/grinternal.h>
56693 +#include <linux/capability.h>
56694 +#include <linux/module.h>
56695 +
56696 +#include <asm/uaccess.h>
56697 +
56698 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56699 +static char gr_exec_arg_buf[132];
56700 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56701 +#endif
56702 +
56703 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56704 +
56705 +void
56706 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56707 +{
56708 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56709 + char *grarg = gr_exec_arg_buf;
56710 + unsigned int i, x, execlen = 0;
56711 + char c;
56712 +
56713 + if (!((grsec_enable_execlog && grsec_enable_group &&
56714 + in_group_p(grsec_audit_gid))
56715 + || (grsec_enable_execlog && !grsec_enable_group)))
56716 + return;
56717 +
56718 + mutex_lock(&gr_exec_arg_mutex);
56719 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56720 +
56721 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56722 + const char __user *p;
56723 + unsigned int len;
56724 +
56725 + p = get_user_arg_ptr(argv, i);
56726 + if (IS_ERR(p))
56727 + goto log;
56728 +
56729 + len = strnlen_user(p, 128 - execlen);
56730 + if (len > 128 - execlen)
56731 + len = 128 - execlen;
56732 + else if (len > 0)
56733 + len--;
56734 + if (copy_from_user(grarg + execlen, p, len))
56735 + goto log;
56736 +
56737 + /* rewrite unprintable characters */
56738 + for (x = 0; x < len; x++) {
56739 + c = *(grarg + execlen + x);
56740 + if (c < 32 || c > 126)
56741 + *(grarg + execlen + x) = ' ';
56742 + }
56743 +
56744 + execlen += len;
56745 + *(grarg + execlen) = ' ';
56746 + *(grarg + execlen + 1) = '\0';
56747 + execlen++;
56748 + }
56749 +
56750 + log:
56751 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56752 + bprm->file->f_path.mnt, grarg);
56753 + mutex_unlock(&gr_exec_arg_mutex);
56754 +#endif
56755 + return;
56756 +}
56757 +
56758 +#ifdef CONFIG_GRKERNSEC
56759 +extern int gr_acl_is_capable(const int cap);
56760 +extern int gr_acl_is_capable_nolog(const int cap);
56761 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56762 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56763 +extern int gr_chroot_is_capable(const int cap);
56764 +extern int gr_chroot_is_capable_nolog(const int cap);
56765 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56766 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56767 +#endif
56768 +
56769 +const char *captab_log[] = {
56770 + "CAP_CHOWN",
56771 + "CAP_DAC_OVERRIDE",
56772 + "CAP_DAC_READ_SEARCH",
56773 + "CAP_FOWNER",
56774 + "CAP_FSETID",
56775 + "CAP_KILL",
56776 + "CAP_SETGID",
56777 + "CAP_SETUID",
56778 + "CAP_SETPCAP",
56779 + "CAP_LINUX_IMMUTABLE",
56780 + "CAP_NET_BIND_SERVICE",
56781 + "CAP_NET_BROADCAST",
56782 + "CAP_NET_ADMIN",
56783 + "CAP_NET_RAW",
56784 + "CAP_IPC_LOCK",
56785 + "CAP_IPC_OWNER",
56786 + "CAP_SYS_MODULE",
56787 + "CAP_SYS_RAWIO",
56788 + "CAP_SYS_CHROOT",
56789 + "CAP_SYS_PTRACE",
56790 + "CAP_SYS_PACCT",
56791 + "CAP_SYS_ADMIN",
56792 + "CAP_SYS_BOOT",
56793 + "CAP_SYS_NICE",
56794 + "CAP_SYS_RESOURCE",
56795 + "CAP_SYS_TIME",
56796 + "CAP_SYS_TTY_CONFIG",
56797 + "CAP_MKNOD",
56798 + "CAP_LEASE",
56799 + "CAP_AUDIT_WRITE",
56800 + "CAP_AUDIT_CONTROL",
56801 + "CAP_SETFCAP",
56802 + "CAP_MAC_OVERRIDE",
56803 + "CAP_MAC_ADMIN",
56804 + "CAP_SYSLOG",
56805 + "CAP_WAKE_ALARM"
56806 +};
56807 +
56808 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56809 +
56810 +int gr_is_capable(const int cap)
56811 +{
56812 +#ifdef CONFIG_GRKERNSEC
56813 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56814 + return 1;
56815 + return 0;
56816 +#else
56817 + return 1;
56818 +#endif
56819 +}
56820 +
56821 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56822 +{
56823 +#ifdef CONFIG_GRKERNSEC
56824 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56825 + return 1;
56826 + return 0;
56827 +#else
56828 + return 1;
56829 +#endif
56830 +}
56831 +
56832 +int gr_is_capable_nolog(const int cap)
56833 +{
56834 +#ifdef CONFIG_GRKERNSEC
56835 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56836 + return 1;
56837 + return 0;
56838 +#else
56839 + return 1;
56840 +#endif
56841 +}
56842 +
56843 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56844 +{
56845 +#ifdef CONFIG_GRKERNSEC
56846 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56847 + return 1;
56848 + return 0;
56849 +#else
56850 + return 1;
56851 +#endif
56852 +}
56853 +
56854 +EXPORT_SYMBOL(gr_is_capable);
56855 +EXPORT_SYMBOL(gr_is_capable_nolog);
56856 +EXPORT_SYMBOL(gr_task_is_capable);
56857 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
56858 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56859 new file mode 100644
56860 index 0000000..d3ee748
56861 --- /dev/null
56862 +++ b/grsecurity/grsec_fifo.c
56863 @@ -0,0 +1,24 @@
56864 +#include <linux/kernel.h>
56865 +#include <linux/sched.h>
56866 +#include <linux/fs.h>
56867 +#include <linux/file.h>
56868 +#include <linux/grinternal.h>
56869 +
56870 +int
56871 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56872 + const struct dentry *dir, const int flag, const int acc_mode)
56873 +{
56874 +#ifdef CONFIG_GRKERNSEC_FIFO
56875 + const struct cred *cred = current_cred();
56876 +
56877 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56878 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56879 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56880 + (cred->fsuid != dentry->d_inode->i_uid)) {
56881 + if (!inode_permission(dentry->d_inode, acc_mode))
56882 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56883 + return -EACCES;
56884 + }
56885 +#endif
56886 + return 0;
56887 +}
56888 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56889 new file mode 100644
56890 index 0000000..8ca18bf
56891 --- /dev/null
56892 +++ b/grsecurity/grsec_fork.c
56893 @@ -0,0 +1,23 @@
56894 +#include <linux/kernel.h>
56895 +#include <linux/sched.h>
56896 +#include <linux/grsecurity.h>
56897 +#include <linux/grinternal.h>
56898 +#include <linux/errno.h>
56899 +
56900 +void
56901 +gr_log_forkfail(const int retval)
56902 +{
56903 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56904 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56905 + switch (retval) {
56906 + case -EAGAIN:
56907 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56908 + break;
56909 + case -ENOMEM:
56910 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56911 + break;
56912 + }
56913 + }
56914 +#endif
56915 + return;
56916 +}
56917 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56918 new file mode 100644
56919 index 0000000..05a6015
56920 --- /dev/null
56921 +++ b/grsecurity/grsec_init.c
56922 @@ -0,0 +1,283 @@
56923 +#include <linux/kernel.h>
56924 +#include <linux/sched.h>
56925 +#include <linux/mm.h>
56926 +#include <linux/gracl.h>
56927 +#include <linux/slab.h>
56928 +#include <linux/vmalloc.h>
56929 +#include <linux/percpu.h>
56930 +#include <linux/module.h>
56931 +
56932 +int grsec_enable_ptrace_readexec;
56933 +int grsec_enable_setxid;
56934 +int grsec_enable_symlinkown;
56935 +int grsec_symlinkown_gid;
56936 +int grsec_enable_brute;
56937 +int grsec_enable_link;
56938 +int grsec_enable_dmesg;
56939 +int grsec_enable_harden_ptrace;
56940 +int grsec_enable_fifo;
56941 +int grsec_enable_execlog;
56942 +int grsec_enable_signal;
56943 +int grsec_enable_forkfail;
56944 +int grsec_enable_audit_ptrace;
56945 +int grsec_enable_time;
56946 +int grsec_enable_audit_textrel;
56947 +int grsec_enable_group;
56948 +int grsec_audit_gid;
56949 +int grsec_enable_chdir;
56950 +int grsec_enable_mount;
56951 +int grsec_enable_rofs;
56952 +int grsec_enable_chroot_findtask;
56953 +int grsec_enable_chroot_mount;
56954 +int grsec_enable_chroot_shmat;
56955 +int grsec_enable_chroot_fchdir;
56956 +int grsec_enable_chroot_double;
56957 +int grsec_enable_chroot_pivot;
56958 +int grsec_enable_chroot_chdir;
56959 +int grsec_enable_chroot_chmod;
56960 +int grsec_enable_chroot_mknod;
56961 +int grsec_enable_chroot_nice;
56962 +int grsec_enable_chroot_execlog;
56963 +int grsec_enable_chroot_caps;
56964 +int grsec_enable_chroot_sysctl;
56965 +int grsec_enable_chroot_unix;
56966 +int grsec_enable_tpe;
56967 +int grsec_tpe_gid;
56968 +int grsec_enable_blackhole;
56969 +#ifdef CONFIG_IPV6_MODULE
56970 +EXPORT_SYMBOL(grsec_enable_blackhole);
56971 +#endif
56972 +int grsec_lastack_retries;
56973 +int grsec_enable_tpe_all;
56974 +int grsec_enable_tpe_invert;
56975 +int grsec_enable_socket_all;
56976 +int grsec_socket_all_gid;
56977 +int grsec_enable_socket_client;
56978 +int grsec_socket_client_gid;
56979 +int grsec_enable_socket_server;
56980 +int grsec_socket_server_gid;
56981 +int grsec_resource_logging;
56982 +int grsec_disable_privio;
56983 +int grsec_enable_log_rwxmaps;
56984 +int grsec_lock;
56985 +
56986 +DEFINE_SPINLOCK(grsec_alert_lock);
56987 +unsigned long grsec_alert_wtime = 0;
56988 +unsigned long grsec_alert_fyet = 0;
56989 +
56990 +DEFINE_SPINLOCK(grsec_audit_lock);
56991 +
56992 +DEFINE_RWLOCK(grsec_exec_file_lock);
56993 +
56994 +char *gr_shared_page[4];
56995 +
56996 +char *gr_alert_log_fmt;
56997 +char *gr_audit_log_fmt;
56998 +char *gr_alert_log_buf;
56999 +char *gr_audit_log_buf;
57000 +
57001 +extern struct gr_arg *gr_usermode;
57002 +extern unsigned char *gr_system_salt;
57003 +extern unsigned char *gr_system_sum;
57004 +
57005 +void __init
57006 +grsecurity_init(void)
57007 +{
57008 + int j;
57009 + /* create the per-cpu shared pages */
57010 +
57011 +#ifdef CONFIG_X86
57012 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57013 +#endif
57014 +
57015 + for (j = 0; j < 4; j++) {
57016 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57017 + if (gr_shared_page[j] == NULL) {
57018 + panic("Unable to allocate grsecurity shared page");
57019 + return;
57020 + }
57021 + }
57022 +
57023 + /* allocate log buffers */
57024 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57025 + if (!gr_alert_log_fmt) {
57026 + panic("Unable to allocate grsecurity alert log format buffer");
57027 + return;
57028 + }
57029 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57030 + if (!gr_audit_log_fmt) {
57031 + panic("Unable to allocate grsecurity audit log format buffer");
57032 + return;
57033 + }
57034 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57035 + if (!gr_alert_log_buf) {
57036 + panic("Unable to allocate grsecurity alert log buffer");
57037 + return;
57038 + }
57039 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57040 + if (!gr_audit_log_buf) {
57041 + panic("Unable to allocate grsecurity audit log buffer");
57042 + return;
57043 + }
57044 +
57045 + /* allocate memory for authentication structure */
57046 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57047 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57048 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57049 +
57050 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57051 + panic("Unable to allocate grsecurity authentication structure");
57052 + return;
57053 + }
57054 +
57055 +
57056 +#ifdef CONFIG_GRKERNSEC_IO
57057 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57058 + grsec_disable_privio = 1;
57059 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57060 + grsec_disable_privio = 1;
57061 +#else
57062 + grsec_disable_privio = 0;
57063 +#endif
57064 +#endif
57065 +
57066 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57067 + /* for backward compatibility, tpe_invert always defaults to on if
57068 + enabled in the kernel
57069 + */
57070 + grsec_enable_tpe_invert = 1;
57071 +#endif
57072 +
57073 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57074 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57075 + grsec_lock = 1;
57076 +#endif
57077 +
57078 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57079 + grsec_enable_audit_textrel = 1;
57080 +#endif
57081 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57082 + grsec_enable_log_rwxmaps = 1;
57083 +#endif
57084 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57085 + grsec_enable_group = 1;
57086 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57087 +#endif
57088 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57089 + grsec_enable_ptrace_readexec = 1;
57090 +#endif
57091 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57092 + grsec_enable_chdir = 1;
57093 +#endif
57094 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57095 + grsec_enable_harden_ptrace = 1;
57096 +#endif
57097 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57098 + grsec_enable_mount = 1;
57099 +#endif
57100 +#ifdef CONFIG_GRKERNSEC_LINK
57101 + grsec_enable_link = 1;
57102 +#endif
57103 +#ifdef CONFIG_GRKERNSEC_BRUTE
57104 + grsec_enable_brute = 1;
57105 +#endif
57106 +#ifdef CONFIG_GRKERNSEC_DMESG
57107 + grsec_enable_dmesg = 1;
57108 +#endif
57109 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57110 + grsec_enable_blackhole = 1;
57111 + grsec_lastack_retries = 4;
57112 +#endif
57113 +#ifdef CONFIG_GRKERNSEC_FIFO
57114 + grsec_enable_fifo = 1;
57115 +#endif
57116 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57117 + grsec_enable_execlog = 1;
57118 +#endif
57119 +#ifdef CONFIG_GRKERNSEC_SETXID
57120 + grsec_enable_setxid = 1;
57121 +#endif
57122 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57123 + grsec_enable_signal = 1;
57124 +#endif
57125 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57126 + grsec_enable_forkfail = 1;
57127 +#endif
57128 +#ifdef CONFIG_GRKERNSEC_TIME
57129 + grsec_enable_time = 1;
57130 +#endif
57131 +#ifdef CONFIG_GRKERNSEC_RESLOG
57132 + grsec_resource_logging = 1;
57133 +#endif
57134 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57135 + grsec_enable_chroot_findtask = 1;
57136 +#endif
57137 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57138 + grsec_enable_chroot_unix = 1;
57139 +#endif
57140 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57141 + grsec_enable_chroot_mount = 1;
57142 +#endif
57143 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57144 + grsec_enable_chroot_fchdir = 1;
57145 +#endif
57146 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57147 + grsec_enable_chroot_shmat = 1;
57148 +#endif
57149 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57150 + grsec_enable_audit_ptrace = 1;
57151 +#endif
57152 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57153 + grsec_enable_chroot_double = 1;
57154 +#endif
57155 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57156 + grsec_enable_chroot_pivot = 1;
57157 +#endif
57158 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57159 + grsec_enable_chroot_chdir = 1;
57160 +#endif
57161 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57162 + grsec_enable_chroot_chmod = 1;
57163 +#endif
57164 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57165 + grsec_enable_chroot_mknod = 1;
57166 +#endif
57167 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57168 + grsec_enable_chroot_nice = 1;
57169 +#endif
57170 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57171 + grsec_enable_chroot_execlog = 1;
57172 +#endif
57173 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57174 + grsec_enable_chroot_caps = 1;
57175 +#endif
57176 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57177 + grsec_enable_chroot_sysctl = 1;
57178 +#endif
57179 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57180 + grsec_enable_symlinkown = 1;
57181 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
57182 +#endif
57183 +#ifdef CONFIG_GRKERNSEC_TPE
57184 + grsec_enable_tpe = 1;
57185 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57186 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57187 + grsec_enable_tpe_all = 1;
57188 +#endif
57189 +#endif
57190 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57191 + grsec_enable_socket_all = 1;
57192 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57193 +#endif
57194 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57195 + grsec_enable_socket_client = 1;
57196 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57197 +#endif
57198 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57199 + grsec_enable_socket_server = 1;
57200 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57201 +#endif
57202 +#endif
57203 +
57204 + return;
57205 +}
57206 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57207 new file mode 100644
57208 index 0000000..35a96d1
57209 --- /dev/null
57210 +++ b/grsecurity/grsec_link.c
57211 @@ -0,0 +1,59 @@
57212 +#include <linux/kernel.h>
57213 +#include <linux/sched.h>
57214 +#include <linux/fs.h>
57215 +#include <linux/file.h>
57216 +#include <linux/grinternal.h>
57217 +
57218 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
57219 +{
57220 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57221 + const struct inode *link_inode = link->dentry->d_inode;
57222 +
57223 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
57224 + /* ignore root-owned links, e.g. /proc/self */
57225 + link_inode->i_uid &&
57226 + link_inode->i_uid != target->i_uid) {
57227 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
57228 + return 1;
57229 + }
57230 +#endif
57231 + return 0;
57232 +}
57233 +
57234 +int
57235 +gr_handle_follow_link(const struct inode *parent,
57236 + const struct inode *inode,
57237 + const struct dentry *dentry, const struct vfsmount *mnt)
57238 +{
57239 +#ifdef CONFIG_GRKERNSEC_LINK
57240 + const struct cred *cred = current_cred();
57241 +
57242 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57243 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57244 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57245 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57246 + return -EACCES;
57247 + }
57248 +#endif
57249 + return 0;
57250 +}
57251 +
57252 +int
57253 +gr_handle_hardlink(const struct dentry *dentry,
57254 + const struct vfsmount *mnt,
57255 + struct inode *inode, const int mode, const char *to)
57256 +{
57257 +#ifdef CONFIG_GRKERNSEC_LINK
57258 + const struct cred *cred = current_cred();
57259 +
57260 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57261 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57262 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57263 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57264 + !capable(CAP_FOWNER) && cred->uid) {
57265 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57266 + return -EPERM;
57267 + }
57268 +#endif
57269 + return 0;
57270 +}
57271 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57272 new file mode 100644
57273 index 0000000..a45d2e9
57274 --- /dev/null
57275 +++ b/grsecurity/grsec_log.c
57276 @@ -0,0 +1,322 @@
57277 +#include <linux/kernel.h>
57278 +#include <linux/sched.h>
57279 +#include <linux/file.h>
57280 +#include <linux/tty.h>
57281 +#include <linux/fs.h>
57282 +#include <linux/grinternal.h>
57283 +
57284 +#ifdef CONFIG_TREE_PREEMPT_RCU
57285 +#define DISABLE_PREEMPT() preempt_disable()
57286 +#define ENABLE_PREEMPT() preempt_enable()
57287 +#else
57288 +#define DISABLE_PREEMPT()
57289 +#define ENABLE_PREEMPT()
57290 +#endif
57291 +
57292 +#define BEGIN_LOCKS(x) \
57293 + DISABLE_PREEMPT(); \
57294 + rcu_read_lock(); \
57295 + read_lock(&tasklist_lock); \
57296 + read_lock(&grsec_exec_file_lock); \
57297 + if (x != GR_DO_AUDIT) \
57298 + spin_lock(&grsec_alert_lock); \
57299 + else \
57300 + spin_lock(&grsec_audit_lock)
57301 +
57302 +#define END_LOCKS(x) \
57303 + if (x != GR_DO_AUDIT) \
57304 + spin_unlock(&grsec_alert_lock); \
57305 + else \
57306 + spin_unlock(&grsec_audit_lock); \
57307 + read_unlock(&grsec_exec_file_lock); \
57308 + read_unlock(&tasklist_lock); \
57309 + rcu_read_unlock(); \
57310 + ENABLE_PREEMPT(); \
57311 + if (x == GR_DONT_AUDIT) \
57312 + gr_handle_alertkill(current)
57313 +
57314 +enum {
57315 + FLOODING,
57316 + NO_FLOODING
57317 +};
57318 +
57319 +extern char *gr_alert_log_fmt;
57320 +extern char *gr_audit_log_fmt;
57321 +extern char *gr_alert_log_buf;
57322 +extern char *gr_audit_log_buf;
57323 +
57324 +static int gr_log_start(int audit)
57325 +{
57326 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57327 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57328 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57329 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57330 + unsigned long curr_secs = get_seconds();
57331 +
57332 + if (audit == GR_DO_AUDIT)
57333 + goto set_fmt;
57334 +
57335 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57336 + grsec_alert_wtime = curr_secs;
57337 + grsec_alert_fyet = 0;
57338 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57339 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57340 + grsec_alert_fyet++;
57341 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57342 + grsec_alert_wtime = curr_secs;
57343 + grsec_alert_fyet++;
57344 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57345 + return FLOODING;
57346 + }
57347 + else return FLOODING;
57348 +
57349 +set_fmt:
57350 +#endif
57351 + memset(buf, 0, PAGE_SIZE);
57352 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57353 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57354 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57355 + } else if (current->signal->curr_ip) {
57356 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57357 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57358 + } else if (gr_acl_is_enabled()) {
57359 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57360 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57361 + } else {
57362 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57363 + strcpy(buf, fmt);
57364 + }
57365 +
57366 + return NO_FLOODING;
57367 +}
57368 +
57369 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57370 + __attribute__ ((format (printf, 2, 0)));
57371 +
57372 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57373 +{
57374 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57375 + unsigned int len = strlen(buf);
57376 +
57377 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57378 +
57379 + return;
57380 +}
57381 +
57382 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57383 + __attribute__ ((format (printf, 2, 3)));
57384 +
57385 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57386 +{
57387 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57388 + unsigned int len = strlen(buf);
57389 + va_list ap;
57390 +
57391 + va_start(ap, msg);
57392 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57393 + va_end(ap);
57394 +
57395 + return;
57396 +}
57397 +
57398 +static void gr_log_end(int audit, int append_default)
57399 +{
57400 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57401 +
57402 + if (append_default) {
57403 + unsigned int len = strlen(buf);
57404 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57405 + }
57406 +
57407 + printk("%s\n", buf);
57408 +
57409 + return;
57410 +}
57411 +
57412 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57413 +{
57414 + int logtype;
57415 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57416 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57417 + void *voidptr = NULL;
57418 + int num1 = 0, num2 = 0;
57419 + unsigned long ulong1 = 0, ulong2 = 0;
57420 + struct dentry *dentry = NULL;
57421 + struct vfsmount *mnt = NULL;
57422 + struct file *file = NULL;
57423 + struct task_struct *task = NULL;
57424 + const struct cred *cred, *pcred;
57425 + va_list ap;
57426 +
57427 + BEGIN_LOCKS(audit);
57428 + logtype = gr_log_start(audit);
57429 + if (logtype == FLOODING) {
57430 + END_LOCKS(audit);
57431 + return;
57432 + }
57433 + va_start(ap, argtypes);
57434 + switch (argtypes) {
57435 + case GR_TTYSNIFF:
57436 + task = va_arg(ap, struct task_struct *);
57437 + 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);
57438 + break;
57439 + case GR_SYSCTL_HIDDEN:
57440 + str1 = va_arg(ap, char *);
57441 + gr_log_middle_varargs(audit, msg, result, str1);
57442 + break;
57443 + case GR_RBAC:
57444 + dentry = va_arg(ap, struct dentry *);
57445 + mnt = va_arg(ap, struct vfsmount *);
57446 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57447 + break;
57448 + case GR_RBAC_STR:
57449 + dentry = va_arg(ap, struct dentry *);
57450 + mnt = va_arg(ap, struct vfsmount *);
57451 + str1 = va_arg(ap, char *);
57452 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57453 + break;
57454 + case GR_STR_RBAC:
57455 + str1 = va_arg(ap, char *);
57456 + dentry = va_arg(ap, struct dentry *);
57457 + mnt = va_arg(ap, struct vfsmount *);
57458 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57459 + break;
57460 + case GR_RBAC_MODE2:
57461 + dentry = va_arg(ap, struct dentry *);
57462 + mnt = va_arg(ap, struct vfsmount *);
57463 + str1 = va_arg(ap, char *);
57464 + str2 = va_arg(ap, char *);
57465 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57466 + break;
57467 + case GR_RBAC_MODE3:
57468 + dentry = va_arg(ap, struct dentry *);
57469 + mnt = va_arg(ap, struct vfsmount *);
57470 + str1 = va_arg(ap, char *);
57471 + str2 = va_arg(ap, char *);
57472 + str3 = va_arg(ap, char *);
57473 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57474 + break;
57475 + case GR_FILENAME:
57476 + dentry = va_arg(ap, struct dentry *);
57477 + mnt = va_arg(ap, struct vfsmount *);
57478 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57479 + break;
57480 + case GR_STR_FILENAME:
57481 + str1 = va_arg(ap, char *);
57482 + dentry = va_arg(ap, struct dentry *);
57483 + mnt = va_arg(ap, struct vfsmount *);
57484 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57485 + break;
57486 + case GR_FILENAME_STR:
57487 + dentry = va_arg(ap, struct dentry *);
57488 + mnt = va_arg(ap, struct vfsmount *);
57489 + str1 = va_arg(ap, char *);
57490 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57491 + break;
57492 + case GR_FILENAME_TWO_INT:
57493 + dentry = va_arg(ap, struct dentry *);
57494 + mnt = va_arg(ap, struct vfsmount *);
57495 + num1 = va_arg(ap, int);
57496 + num2 = va_arg(ap, int);
57497 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57498 + break;
57499 + case GR_FILENAME_TWO_INT_STR:
57500 + dentry = va_arg(ap, struct dentry *);
57501 + mnt = va_arg(ap, struct vfsmount *);
57502 + num1 = va_arg(ap, int);
57503 + num2 = va_arg(ap, int);
57504 + str1 = va_arg(ap, char *);
57505 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57506 + break;
57507 + case GR_TEXTREL:
57508 + file = va_arg(ap, struct file *);
57509 + ulong1 = va_arg(ap, unsigned long);
57510 + ulong2 = va_arg(ap, unsigned long);
57511 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57512 + break;
57513 + case GR_PTRACE:
57514 + task = va_arg(ap, struct task_struct *);
57515 + 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);
57516 + break;
57517 + case GR_RESOURCE:
57518 + task = va_arg(ap, struct task_struct *);
57519 + cred = __task_cred(task);
57520 + pcred = __task_cred(task->real_parent);
57521 + ulong1 = va_arg(ap, unsigned long);
57522 + str1 = va_arg(ap, char *);
57523 + ulong2 = va_arg(ap, unsigned long);
57524 + 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);
57525 + break;
57526 + case GR_CAP:
57527 + task = va_arg(ap, struct task_struct *);
57528 + cred = __task_cred(task);
57529 + pcred = __task_cred(task->real_parent);
57530 + str1 = va_arg(ap, char *);
57531 + 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);
57532 + break;
57533 + case GR_SIG:
57534 + str1 = va_arg(ap, char *);
57535 + voidptr = va_arg(ap, void *);
57536 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57537 + break;
57538 + case GR_SIG2:
57539 + task = va_arg(ap, struct task_struct *);
57540 + cred = __task_cred(task);
57541 + pcred = __task_cred(task->real_parent);
57542 + num1 = va_arg(ap, int);
57543 + 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);
57544 + break;
57545 + case GR_CRASH1:
57546 + task = va_arg(ap, struct task_struct *);
57547 + cred = __task_cred(task);
57548 + pcred = __task_cred(task->real_parent);
57549 + ulong1 = va_arg(ap, unsigned long);
57550 + 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);
57551 + break;
57552 + case GR_CRASH2:
57553 + task = va_arg(ap, struct task_struct *);
57554 + cred = __task_cred(task);
57555 + pcred = __task_cred(task->real_parent);
57556 + ulong1 = va_arg(ap, unsigned long);
57557 + 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);
57558 + break;
57559 + case GR_RWXMAP:
57560 + file = va_arg(ap, struct file *);
57561 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57562 + break;
57563 + case GR_PSACCT:
57564 + {
57565 + unsigned int wday, cday;
57566 + __u8 whr, chr;
57567 + __u8 wmin, cmin;
57568 + __u8 wsec, csec;
57569 + char cur_tty[64] = { 0 };
57570 + char parent_tty[64] = { 0 };
57571 +
57572 + task = va_arg(ap, struct task_struct *);
57573 + wday = va_arg(ap, unsigned int);
57574 + cday = va_arg(ap, unsigned int);
57575 + whr = va_arg(ap, int);
57576 + chr = va_arg(ap, int);
57577 + wmin = va_arg(ap, int);
57578 + cmin = va_arg(ap, int);
57579 + wsec = va_arg(ap, int);
57580 + csec = va_arg(ap, int);
57581 + ulong1 = va_arg(ap, unsigned long);
57582 + cred = __task_cred(task);
57583 + pcred = __task_cred(task->real_parent);
57584 +
57585 + 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);
57586 + }
57587 + break;
57588 + default:
57589 + gr_log_middle(audit, msg, ap);
57590 + }
57591 + va_end(ap);
57592 + // these don't need DEFAULTSECARGS printed on the end
57593 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57594 + gr_log_end(audit, 0);
57595 + else
57596 + gr_log_end(audit, 1);
57597 + END_LOCKS(audit);
57598 +}
57599 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57600 new file mode 100644
57601 index 0000000..f536303
57602 --- /dev/null
57603 +++ b/grsecurity/grsec_mem.c
57604 @@ -0,0 +1,40 @@
57605 +#include <linux/kernel.h>
57606 +#include <linux/sched.h>
57607 +#include <linux/mm.h>
57608 +#include <linux/mman.h>
57609 +#include <linux/grinternal.h>
57610 +
57611 +void
57612 +gr_handle_ioperm(void)
57613 +{
57614 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57615 + return;
57616 +}
57617 +
57618 +void
57619 +gr_handle_iopl(void)
57620 +{
57621 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57622 + return;
57623 +}
57624 +
57625 +void
57626 +gr_handle_mem_readwrite(u64 from, u64 to)
57627 +{
57628 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57629 + return;
57630 +}
57631 +
57632 +void
57633 +gr_handle_vm86(void)
57634 +{
57635 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57636 + return;
57637 +}
57638 +
57639 +void
57640 +gr_log_badprocpid(const char *entry)
57641 +{
57642 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57643 + return;
57644 +}
57645 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57646 new file mode 100644
57647 index 0000000..2131422
57648 --- /dev/null
57649 +++ b/grsecurity/grsec_mount.c
57650 @@ -0,0 +1,62 @@
57651 +#include <linux/kernel.h>
57652 +#include <linux/sched.h>
57653 +#include <linux/mount.h>
57654 +#include <linux/grsecurity.h>
57655 +#include <linux/grinternal.h>
57656 +
57657 +void
57658 +gr_log_remount(const char *devname, const int retval)
57659 +{
57660 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57661 + if (grsec_enable_mount && (retval >= 0))
57662 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57663 +#endif
57664 + return;
57665 +}
57666 +
57667 +void
57668 +gr_log_unmount(const char *devname, const int retval)
57669 +{
57670 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57671 + if (grsec_enable_mount && (retval >= 0))
57672 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57673 +#endif
57674 + return;
57675 +}
57676 +
57677 +void
57678 +gr_log_mount(const char *from, const char *to, const int retval)
57679 +{
57680 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57681 + if (grsec_enable_mount && (retval >= 0))
57682 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57683 +#endif
57684 + return;
57685 +}
57686 +
57687 +int
57688 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57689 +{
57690 +#ifdef CONFIG_GRKERNSEC_ROFS
57691 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57692 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57693 + return -EPERM;
57694 + } else
57695 + return 0;
57696 +#endif
57697 + return 0;
57698 +}
57699 +
57700 +int
57701 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57702 +{
57703 +#ifdef CONFIG_GRKERNSEC_ROFS
57704 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57705 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57706 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57707 + return -EPERM;
57708 + } else
57709 + return 0;
57710 +#endif
57711 + return 0;
57712 +}
57713 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57714 new file mode 100644
57715 index 0000000..a3b12a0
57716 --- /dev/null
57717 +++ b/grsecurity/grsec_pax.c
57718 @@ -0,0 +1,36 @@
57719 +#include <linux/kernel.h>
57720 +#include <linux/sched.h>
57721 +#include <linux/mm.h>
57722 +#include <linux/file.h>
57723 +#include <linux/grinternal.h>
57724 +#include <linux/grsecurity.h>
57725 +
57726 +void
57727 +gr_log_textrel(struct vm_area_struct * vma)
57728 +{
57729 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57730 + if (grsec_enable_audit_textrel)
57731 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57732 +#endif
57733 + return;
57734 +}
57735 +
57736 +void
57737 +gr_log_rwxmmap(struct file *file)
57738 +{
57739 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57740 + if (grsec_enable_log_rwxmaps)
57741 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57742 +#endif
57743 + return;
57744 +}
57745 +
57746 +void
57747 +gr_log_rwxmprotect(struct file *file)
57748 +{
57749 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57750 + if (grsec_enable_log_rwxmaps)
57751 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57752 +#endif
57753 + return;
57754 +}
57755 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57756 new file mode 100644
57757 index 0000000..f7f29aa
57758 --- /dev/null
57759 +++ b/grsecurity/grsec_ptrace.c
57760 @@ -0,0 +1,30 @@
57761 +#include <linux/kernel.h>
57762 +#include <linux/sched.h>
57763 +#include <linux/grinternal.h>
57764 +#include <linux/security.h>
57765 +
57766 +void
57767 +gr_audit_ptrace(struct task_struct *task)
57768 +{
57769 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57770 + if (grsec_enable_audit_ptrace)
57771 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57772 +#endif
57773 + return;
57774 +}
57775 +
57776 +int
57777 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57778 +{
57779 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57780 + const struct dentry *dentry = file->f_path.dentry;
57781 + const struct vfsmount *mnt = file->f_path.mnt;
57782 +
57783 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57784 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57785 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57786 + return -EACCES;
57787 + }
57788 +#endif
57789 + return 0;
57790 +}
57791 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57792 new file mode 100644
57793 index 0000000..7a5b2de
57794 --- /dev/null
57795 +++ b/grsecurity/grsec_sig.c
57796 @@ -0,0 +1,207 @@
57797 +#include <linux/kernel.h>
57798 +#include <linux/sched.h>
57799 +#include <linux/delay.h>
57800 +#include <linux/grsecurity.h>
57801 +#include <linux/grinternal.h>
57802 +#include <linux/hardirq.h>
57803 +
57804 +char *signames[] = {
57805 + [SIGSEGV] = "Segmentation fault",
57806 + [SIGILL] = "Illegal instruction",
57807 + [SIGABRT] = "Abort",
57808 + [SIGBUS] = "Invalid alignment/Bus error"
57809 +};
57810 +
57811 +void
57812 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57813 +{
57814 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57815 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57816 + (sig == SIGABRT) || (sig == SIGBUS))) {
57817 + if (t->pid == current->pid) {
57818 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57819 + } else {
57820 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57821 + }
57822 + }
57823 +#endif
57824 + return;
57825 +}
57826 +
57827 +int
57828 +gr_handle_signal(const struct task_struct *p, const int sig)
57829 +{
57830 +#ifdef CONFIG_GRKERNSEC
57831 + /* ignore the 0 signal for protected task checks */
57832 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57833 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57834 + return -EPERM;
57835 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57836 + return -EPERM;
57837 + }
57838 +#endif
57839 + return 0;
57840 +}
57841 +
57842 +#ifdef CONFIG_GRKERNSEC
57843 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57844 +
57845 +int gr_fake_force_sig(int sig, struct task_struct *t)
57846 +{
57847 + unsigned long int flags;
57848 + int ret, blocked, ignored;
57849 + struct k_sigaction *action;
57850 +
57851 + spin_lock_irqsave(&t->sighand->siglock, flags);
57852 + action = &t->sighand->action[sig-1];
57853 + ignored = action->sa.sa_handler == SIG_IGN;
57854 + blocked = sigismember(&t->blocked, sig);
57855 + if (blocked || ignored) {
57856 + action->sa.sa_handler = SIG_DFL;
57857 + if (blocked) {
57858 + sigdelset(&t->blocked, sig);
57859 + recalc_sigpending_and_wake(t);
57860 + }
57861 + }
57862 + if (action->sa.sa_handler == SIG_DFL)
57863 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
57864 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57865 +
57866 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
57867 +
57868 + return ret;
57869 +}
57870 +#endif
57871 +
57872 +#ifdef CONFIG_GRKERNSEC_BRUTE
57873 +#define GR_USER_BAN_TIME (15 * 60)
57874 +
57875 +static int __get_dumpable(unsigned long mm_flags)
57876 +{
57877 + int ret;
57878 +
57879 + ret = mm_flags & MMF_DUMPABLE_MASK;
57880 + return (ret >= 2) ? 2 : ret;
57881 +}
57882 +#endif
57883 +
57884 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57885 +{
57886 +#ifdef CONFIG_GRKERNSEC_BRUTE
57887 + uid_t uid = 0;
57888 +
57889 + if (!grsec_enable_brute)
57890 + return;
57891 +
57892 + rcu_read_lock();
57893 + read_lock(&tasklist_lock);
57894 + read_lock(&grsec_exec_file_lock);
57895 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57896 + p->real_parent->brute = 1;
57897 + else {
57898 + const struct cred *cred = __task_cred(p), *cred2;
57899 + struct task_struct *tsk, *tsk2;
57900 +
57901 + if (!__get_dumpable(mm_flags) && cred->uid) {
57902 + struct user_struct *user;
57903 +
57904 + uid = cred->uid;
57905 +
57906 + /* this is put upon execution past expiration */
57907 + user = find_user(uid);
57908 + if (user == NULL)
57909 + goto unlock;
57910 + user->banned = 1;
57911 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57912 + if (user->ban_expires == ~0UL)
57913 + user->ban_expires--;
57914 +
57915 + do_each_thread(tsk2, tsk) {
57916 + cred2 = __task_cred(tsk);
57917 + if (tsk != p && cred2->uid == uid)
57918 + gr_fake_force_sig(SIGKILL, tsk);
57919 + } while_each_thread(tsk2, tsk);
57920 + }
57921 + }
57922 +unlock:
57923 + read_unlock(&grsec_exec_file_lock);
57924 + read_unlock(&tasklist_lock);
57925 + rcu_read_unlock();
57926 +
57927 + if (uid)
57928 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57929 +
57930 +#endif
57931 + return;
57932 +}
57933 +
57934 +void gr_handle_brute_check(void)
57935 +{
57936 +#ifdef CONFIG_GRKERNSEC_BRUTE
57937 + if (current->brute)
57938 + msleep(30 * 1000);
57939 +#endif
57940 + return;
57941 +}
57942 +
57943 +void gr_handle_kernel_exploit(void)
57944 +{
57945 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57946 + const struct cred *cred;
57947 + struct task_struct *tsk, *tsk2;
57948 + struct user_struct *user;
57949 + uid_t uid;
57950 +
57951 + if (in_irq() || in_serving_softirq() || in_nmi())
57952 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57953 +
57954 + uid = current_uid();
57955 +
57956 + if (uid == 0)
57957 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
57958 + else {
57959 + /* kill all the processes of this user, hold a reference
57960 + to their creds struct, and prevent them from creating
57961 + another process until system reset
57962 + */
57963 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57964 + /* we intentionally leak this ref */
57965 + user = get_uid(current->cred->user);
57966 + if (user) {
57967 + user->banned = 1;
57968 + user->ban_expires = ~0UL;
57969 + }
57970 +
57971 + read_lock(&tasklist_lock);
57972 + do_each_thread(tsk2, tsk) {
57973 + cred = __task_cred(tsk);
57974 + if (cred->uid == uid)
57975 + gr_fake_force_sig(SIGKILL, tsk);
57976 + } while_each_thread(tsk2, tsk);
57977 + read_unlock(&tasklist_lock);
57978 + }
57979 +#endif
57980 +}
57981 +
57982 +int __gr_process_user_ban(struct user_struct *user)
57983 +{
57984 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57985 + if (unlikely(user->banned)) {
57986 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
57987 + user->banned = 0;
57988 + user->ban_expires = 0;
57989 + free_uid(user);
57990 + } else
57991 + return -EPERM;
57992 + }
57993 +#endif
57994 + return 0;
57995 +}
57996 +
57997 +int gr_process_user_ban(void)
57998 +{
57999 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58000 + return __gr_process_user_ban(current->cred->user);
58001 +#endif
58002 + return 0;
58003 +}
58004 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58005 new file mode 100644
58006 index 0000000..4030d57
58007 --- /dev/null
58008 +++ b/grsecurity/grsec_sock.c
58009 @@ -0,0 +1,244 @@
58010 +#include <linux/kernel.h>
58011 +#include <linux/module.h>
58012 +#include <linux/sched.h>
58013 +#include <linux/file.h>
58014 +#include <linux/net.h>
58015 +#include <linux/in.h>
58016 +#include <linux/ip.h>
58017 +#include <net/sock.h>
58018 +#include <net/inet_sock.h>
58019 +#include <linux/grsecurity.h>
58020 +#include <linux/grinternal.h>
58021 +#include <linux/gracl.h>
58022 +
58023 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58024 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58025 +
58026 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58027 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58028 +
58029 +#ifdef CONFIG_UNIX_MODULE
58030 +EXPORT_SYMBOL(gr_acl_handle_unix);
58031 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58032 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58033 +EXPORT_SYMBOL(gr_handle_create);
58034 +#endif
58035 +
58036 +#ifdef CONFIG_GRKERNSEC
58037 +#define gr_conn_table_size 32749
58038 +struct conn_table_entry {
58039 + struct conn_table_entry *next;
58040 + struct signal_struct *sig;
58041 +};
58042 +
58043 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58044 +DEFINE_SPINLOCK(gr_conn_table_lock);
58045 +
58046 +extern const char * gr_socktype_to_name(unsigned char type);
58047 +extern const char * gr_proto_to_name(unsigned char proto);
58048 +extern const char * gr_sockfamily_to_name(unsigned char family);
58049 +
58050 +static __inline__ int
58051 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58052 +{
58053 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58054 +}
58055 +
58056 +static __inline__ int
58057 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58058 + __u16 sport, __u16 dport)
58059 +{
58060 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58061 + sig->gr_sport == sport && sig->gr_dport == dport))
58062 + return 1;
58063 + else
58064 + return 0;
58065 +}
58066 +
58067 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58068 +{
58069 + struct conn_table_entry **match;
58070 + unsigned int index;
58071 +
58072 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58073 + sig->gr_sport, sig->gr_dport,
58074 + gr_conn_table_size);
58075 +
58076 + newent->sig = sig;
58077 +
58078 + match = &gr_conn_table[index];
58079 + newent->next = *match;
58080 + *match = newent;
58081 +
58082 + return;
58083 +}
58084 +
58085 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58086 +{
58087 + struct conn_table_entry *match, *last = NULL;
58088 + unsigned int index;
58089 +
58090 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58091 + sig->gr_sport, sig->gr_dport,
58092 + gr_conn_table_size);
58093 +
58094 + match = gr_conn_table[index];
58095 + while (match && !conn_match(match->sig,
58096 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58097 + sig->gr_dport)) {
58098 + last = match;
58099 + match = match->next;
58100 + }
58101 +
58102 + if (match) {
58103 + if (last)
58104 + last->next = match->next;
58105 + else
58106 + gr_conn_table[index] = NULL;
58107 + kfree(match);
58108 + }
58109 +
58110 + return;
58111 +}
58112 +
58113 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58114 + __u16 sport, __u16 dport)
58115 +{
58116 + struct conn_table_entry *match;
58117 + unsigned int index;
58118 +
58119 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58120 +
58121 + match = gr_conn_table[index];
58122 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58123 + match = match->next;
58124 +
58125 + if (match)
58126 + return match->sig;
58127 + else
58128 + return NULL;
58129 +}
58130 +
58131 +#endif
58132 +
58133 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58134 +{
58135 +#ifdef CONFIG_GRKERNSEC
58136 + struct signal_struct *sig = task->signal;
58137 + struct conn_table_entry *newent;
58138 +
58139 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58140 + if (newent == NULL)
58141 + return;
58142 + /* no bh lock needed since we are called with bh disabled */
58143 + spin_lock(&gr_conn_table_lock);
58144 + gr_del_task_from_ip_table_nolock(sig);
58145 + sig->gr_saddr = inet->inet_rcv_saddr;
58146 + sig->gr_daddr = inet->inet_daddr;
58147 + sig->gr_sport = inet->inet_sport;
58148 + sig->gr_dport = inet->inet_dport;
58149 + gr_add_to_task_ip_table_nolock(sig, newent);
58150 + spin_unlock(&gr_conn_table_lock);
58151 +#endif
58152 + return;
58153 +}
58154 +
58155 +void gr_del_task_from_ip_table(struct task_struct *task)
58156 +{
58157 +#ifdef CONFIG_GRKERNSEC
58158 + spin_lock_bh(&gr_conn_table_lock);
58159 + gr_del_task_from_ip_table_nolock(task->signal);
58160 + spin_unlock_bh(&gr_conn_table_lock);
58161 +#endif
58162 + return;
58163 +}
58164 +
58165 +void
58166 +gr_attach_curr_ip(const struct sock *sk)
58167 +{
58168 +#ifdef CONFIG_GRKERNSEC
58169 + struct signal_struct *p, *set;
58170 + const struct inet_sock *inet = inet_sk(sk);
58171 +
58172 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58173 + return;
58174 +
58175 + set = current->signal;
58176 +
58177 + spin_lock_bh(&gr_conn_table_lock);
58178 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58179 + inet->inet_dport, inet->inet_sport);
58180 + if (unlikely(p != NULL)) {
58181 + set->curr_ip = p->curr_ip;
58182 + set->used_accept = 1;
58183 + gr_del_task_from_ip_table_nolock(p);
58184 + spin_unlock_bh(&gr_conn_table_lock);
58185 + return;
58186 + }
58187 + spin_unlock_bh(&gr_conn_table_lock);
58188 +
58189 + set->curr_ip = inet->inet_daddr;
58190 + set->used_accept = 1;
58191 +#endif
58192 + return;
58193 +}
58194 +
58195 +int
58196 +gr_handle_sock_all(const int family, const int type, const int protocol)
58197 +{
58198 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58199 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58200 + (family != AF_UNIX)) {
58201 + if (family == AF_INET)
58202 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58203 + else
58204 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58205 + return -EACCES;
58206 + }
58207 +#endif
58208 + return 0;
58209 +}
58210 +
58211 +int
58212 +gr_handle_sock_server(const struct sockaddr *sck)
58213 +{
58214 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58215 + if (grsec_enable_socket_server &&
58216 + in_group_p(grsec_socket_server_gid) &&
58217 + sck && (sck->sa_family != AF_UNIX) &&
58218 + (sck->sa_family != AF_LOCAL)) {
58219 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58220 + return -EACCES;
58221 + }
58222 +#endif
58223 + return 0;
58224 +}
58225 +
58226 +int
58227 +gr_handle_sock_server_other(const struct sock *sck)
58228 +{
58229 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58230 + if (grsec_enable_socket_server &&
58231 + in_group_p(grsec_socket_server_gid) &&
58232 + sck && (sck->sk_family != AF_UNIX) &&
58233 + (sck->sk_family != AF_LOCAL)) {
58234 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58235 + return -EACCES;
58236 + }
58237 +#endif
58238 + return 0;
58239 +}
58240 +
58241 +int
58242 +gr_handle_sock_client(const struct sockaddr *sck)
58243 +{
58244 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58245 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58246 + sck && (sck->sa_family != AF_UNIX) &&
58247 + (sck->sa_family != AF_LOCAL)) {
58248 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58249 + return -EACCES;
58250 + }
58251 +#endif
58252 + return 0;
58253 +}
58254 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58255 new file mode 100644
58256 index 0000000..f55ef0f
58257 --- /dev/null
58258 +++ b/grsecurity/grsec_sysctl.c
58259 @@ -0,0 +1,469 @@
58260 +#include <linux/kernel.h>
58261 +#include <linux/sched.h>
58262 +#include <linux/sysctl.h>
58263 +#include <linux/grsecurity.h>
58264 +#include <linux/grinternal.h>
58265 +
58266 +int
58267 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58268 +{
58269 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58270 + if (dirname == NULL || name == NULL)
58271 + return 0;
58272 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58273 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58274 + return -EACCES;
58275 + }
58276 +#endif
58277 + return 0;
58278 +}
58279 +
58280 +#ifdef CONFIG_GRKERNSEC_ROFS
58281 +static int __maybe_unused one = 1;
58282 +#endif
58283 +
58284 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58285 +struct ctl_table grsecurity_table[] = {
58286 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58287 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58288 +#ifdef CONFIG_GRKERNSEC_IO
58289 + {
58290 + .procname = "disable_priv_io",
58291 + .data = &grsec_disable_privio,
58292 + .maxlen = sizeof(int),
58293 + .mode = 0600,
58294 + .proc_handler = &proc_dointvec,
58295 + },
58296 +#endif
58297 +#endif
58298 +#ifdef CONFIG_GRKERNSEC_LINK
58299 + {
58300 + .procname = "linking_restrictions",
58301 + .data = &grsec_enable_link,
58302 + .maxlen = sizeof(int),
58303 + .mode = 0600,
58304 + .proc_handler = &proc_dointvec,
58305 + },
58306 +#endif
58307 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58308 + {
58309 + .procname = "enforce_symlinksifowner",
58310 + .data = &grsec_enable_symlinkown,
58311 + .maxlen = sizeof(int),
58312 + .mode = 0600,
58313 + .proc_handler = &proc_dointvec,
58314 + },
58315 + {
58316 + .procname = "symlinkown_gid",
58317 + .data = &grsec_symlinkown_gid,
58318 + .maxlen = sizeof(int),
58319 + .mode = 0600,
58320 + .proc_handler = &proc_dointvec,
58321 + },
58322 +#endif
58323 +#ifdef CONFIG_GRKERNSEC_BRUTE
58324 + {
58325 + .procname = "deter_bruteforce",
58326 + .data = &grsec_enable_brute,
58327 + .maxlen = sizeof(int),
58328 + .mode = 0600,
58329 + .proc_handler = &proc_dointvec,
58330 + },
58331 +#endif
58332 +#ifdef CONFIG_GRKERNSEC_FIFO
58333 + {
58334 + .procname = "fifo_restrictions",
58335 + .data = &grsec_enable_fifo,
58336 + .maxlen = sizeof(int),
58337 + .mode = 0600,
58338 + .proc_handler = &proc_dointvec,
58339 + },
58340 +#endif
58341 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58342 + {
58343 + .procname = "ptrace_readexec",
58344 + .data = &grsec_enable_ptrace_readexec,
58345 + .maxlen = sizeof(int),
58346 + .mode = 0600,
58347 + .proc_handler = &proc_dointvec,
58348 + },
58349 +#endif
58350 +#ifdef CONFIG_GRKERNSEC_SETXID
58351 + {
58352 + .procname = "consistent_setxid",
58353 + .data = &grsec_enable_setxid,
58354 + .maxlen = sizeof(int),
58355 + .mode = 0600,
58356 + .proc_handler = &proc_dointvec,
58357 + },
58358 +#endif
58359 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58360 + {
58361 + .procname = "ip_blackhole",
58362 + .data = &grsec_enable_blackhole,
58363 + .maxlen = sizeof(int),
58364 + .mode = 0600,
58365 + .proc_handler = &proc_dointvec,
58366 + },
58367 + {
58368 + .procname = "lastack_retries",
58369 + .data = &grsec_lastack_retries,
58370 + .maxlen = sizeof(int),
58371 + .mode = 0600,
58372 + .proc_handler = &proc_dointvec,
58373 + },
58374 +#endif
58375 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58376 + {
58377 + .procname = "exec_logging",
58378 + .data = &grsec_enable_execlog,
58379 + .maxlen = sizeof(int),
58380 + .mode = 0600,
58381 + .proc_handler = &proc_dointvec,
58382 + },
58383 +#endif
58384 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58385 + {
58386 + .procname = "rwxmap_logging",
58387 + .data = &grsec_enable_log_rwxmaps,
58388 + .maxlen = sizeof(int),
58389 + .mode = 0600,
58390 + .proc_handler = &proc_dointvec,
58391 + },
58392 +#endif
58393 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58394 + {
58395 + .procname = "signal_logging",
58396 + .data = &grsec_enable_signal,
58397 + .maxlen = sizeof(int),
58398 + .mode = 0600,
58399 + .proc_handler = &proc_dointvec,
58400 + },
58401 +#endif
58402 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58403 + {
58404 + .procname = "forkfail_logging",
58405 + .data = &grsec_enable_forkfail,
58406 + .maxlen = sizeof(int),
58407 + .mode = 0600,
58408 + .proc_handler = &proc_dointvec,
58409 + },
58410 +#endif
58411 +#ifdef CONFIG_GRKERNSEC_TIME
58412 + {
58413 + .procname = "timechange_logging",
58414 + .data = &grsec_enable_time,
58415 + .maxlen = sizeof(int),
58416 + .mode = 0600,
58417 + .proc_handler = &proc_dointvec,
58418 + },
58419 +#endif
58420 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58421 + {
58422 + .procname = "chroot_deny_shmat",
58423 + .data = &grsec_enable_chroot_shmat,
58424 + .maxlen = sizeof(int),
58425 + .mode = 0600,
58426 + .proc_handler = &proc_dointvec,
58427 + },
58428 +#endif
58429 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58430 + {
58431 + .procname = "chroot_deny_unix",
58432 + .data = &grsec_enable_chroot_unix,
58433 + .maxlen = sizeof(int),
58434 + .mode = 0600,
58435 + .proc_handler = &proc_dointvec,
58436 + },
58437 +#endif
58438 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58439 + {
58440 + .procname = "chroot_deny_mount",
58441 + .data = &grsec_enable_chroot_mount,
58442 + .maxlen = sizeof(int),
58443 + .mode = 0600,
58444 + .proc_handler = &proc_dointvec,
58445 + },
58446 +#endif
58447 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58448 + {
58449 + .procname = "chroot_deny_fchdir",
58450 + .data = &grsec_enable_chroot_fchdir,
58451 + .maxlen = sizeof(int),
58452 + .mode = 0600,
58453 + .proc_handler = &proc_dointvec,
58454 + },
58455 +#endif
58456 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58457 + {
58458 + .procname = "chroot_deny_chroot",
58459 + .data = &grsec_enable_chroot_double,
58460 + .maxlen = sizeof(int),
58461 + .mode = 0600,
58462 + .proc_handler = &proc_dointvec,
58463 + },
58464 +#endif
58465 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58466 + {
58467 + .procname = "chroot_deny_pivot",
58468 + .data = &grsec_enable_chroot_pivot,
58469 + .maxlen = sizeof(int),
58470 + .mode = 0600,
58471 + .proc_handler = &proc_dointvec,
58472 + },
58473 +#endif
58474 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58475 + {
58476 + .procname = "chroot_enforce_chdir",
58477 + .data = &grsec_enable_chroot_chdir,
58478 + .maxlen = sizeof(int),
58479 + .mode = 0600,
58480 + .proc_handler = &proc_dointvec,
58481 + },
58482 +#endif
58483 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58484 + {
58485 + .procname = "chroot_deny_chmod",
58486 + .data = &grsec_enable_chroot_chmod,
58487 + .maxlen = sizeof(int),
58488 + .mode = 0600,
58489 + .proc_handler = &proc_dointvec,
58490 + },
58491 +#endif
58492 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58493 + {
58494 + .procname = "chroot_deny_mknod",
58495 + .data = &grsec_enable_chroot_mknod,
58496 + .maxlen = sizeof(int),
58497 + .mode = 0600,
58498 + .proc_handler = &proc_dointvec,
58499 + },
58500 +#endif
58501 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58502 + {
58503 + .procname = "chroot_restrict_nice",
58504 + .data = &grsec_enable_chroot_nice,
58505 + .maxlen = sizeof(int),
58506 + .mode = 0600,
58507 + .proc_handler = &proc_dointvec,
58508 + },
58509 +#endif
58510 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58511 + {
58512 + .procname = "chroot_execlog",
58513 + .data = &grsec_enable_chroot_execlog,
58514 + .maxlen = sizeof(int),
58515 + .mode = 0600,
58516 + .proc_handler = &proc_dointvec,
58517 + },
58518 +#endif
58519 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58520 + {
58521 + .procname = "chroot_caps",
58522 + .data = &grsec_enable_chroot_caps,
58523 + .maxlen = sizeof(int),
58524 + .mode = 0600,
58525 + .proc_handler = &proc_dointvec,
58526 + },
58527 +#endif
58528 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58529 + {
58530 + .procname = "chroot_deny_sysctl",
58531 + .data = &grsec_enable_chroot_sysctl,
58532 + .maxlen = sizeof(int),
58533 + .mode = 0600,
58534 + .proc_handler = &proc_dointvec,
58535 + },
58536 +#endif
58537 +#ifdef CONFIG_GRKERNSEC_TPE
58538 + {
58539 + .procname = "tpe",
58540 + .data = &grsec_enable_tpe,
58541 + .maxlen = sizeof(int),
58542 + .mode = 0600,
58543 + .proc_handler = &proc_dointvec,
58544 + },
58545 + {
58546 + .procname = "tpe_gid",
58547 + .data = &grsec_tpe_gid,
58548 + .maxlen = sizeof(int),
58549 + .mode = 0600,
58550 + .proc_handler = &proc_dointvec,
58551 + },
58552 +#endif
58553 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58554 + {
58555 + .procname = "tpe_invert",
58556 + .data = &grsec_enable_tpe_invert,
58557 + .maxlen = sizeof(int),
58558 + .mode = 0600,
58559 + .proc_handler = &proc_dointvec,
58560 + },
58561 +#endif
58562 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58563 + {
58564 + .procname = "tpe_restrict_all",
58565 + .data = &grsec_enable_tpe_all,
58566 + .maxlen = sizeof(int),
58567 + .mode = 0600,
58568 + .proc_handler = &proc_dointvec,
58569 + },
58570 +#endif
58571 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58572 + {
58573 + .procname = "socket_all",
58574 + .data = &grsec_enable_socket_all,
58575 + .maxlen = sizeof(int),
58576 + .mode = 0600,
58577 + .proc_handler = &proc_dointvec,
58578 + },
58579 + {
58580 + .procname = "socket_all_gid",
58581 + .data = &grsec_socket_all_gid,
58582 + .maxlen = sizeof(int),
58583 + .mode = 0600,
58584 + .proc_handler = &proc_dointvec,
58585 + },
58586 +#endif
58587 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58588 + {
58589 + .procname = "socket_client",
58590 + .data = &grsec_enable_socket_client,
58591 + .maxlen = sizeof(int),
58592 + .mode = 0600,
58593 + .proc_handler = &proc_dointvec,
58594 + },
58595 + {
58596 + .procname = "socket_client_gid",
58597 + .data = &grsec_socket_client_gid,
58598 + .maxlen = sizeof(int),
58599 + .mode = 0600,
58600 + .proc_handler = &proc_dointvec,
58601 + },
58602 +#endif
58603 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58604 + {
58605 + .procname = "socket_server",
58606 + .data = &grsec_enable_socket_server,
58607 + .maxlen = sizeof(int),
58608 + .mode = 0600,
58609 + .proc_handler = &proc_dointvec,
58610 + },
58611 + {
58612 + .procname = "socket_server_gid",
58613 + .data = &grsec_socket_server_gid,
58614 + .maxlen = sizeof(int),
58615 + .mode = 0600,
58616 + .proc_handler = &proc_dointvec,
58617 + },
58618 +#endif
58619 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58620 + {
58621 + .procname = "audit_group",
58622 + .data = &grsec_enable_group,
58623 + .maxlen = sizeof(int),
58624 + .mode = 0600,
58625 + .proc_handler = &proc_dointvec,
58626 + },
58627 + {
58628 + .procname = "audit_gid",
58629 + .data = &grsec_audit_gid,
58630 + .maxlen = sizeof(int),
58631 + .mode = 0600,
58632 + .proc_handler = &proc_dointvec,
58633 + },
58634 +#endif
58635 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58636 + {
58637 + .procname = "audit_chdir",
58638 + .data = &grsec_enable_chdir,
58639 + .maxlen = sizeof(int),
58640 + .mode = 0600,
58641 + .proc_handler = &proc_dointvec,
58642 + },
58643 +#endif
58644 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58645 + {
58646 + .procname = "audit_mount",
58647 + .data = &grsec_enable_mount,
58648 + .maxlen = sizeof(int),
58649 + .mode = 0600,
58650 + .proc_handler = &proc_dointvec,
58651 + },
58652 +#endif
58653 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58654 + {
58655 + .procname = "audit_textrel",
58656 + .data = &grsec_enable_audit_textrel,
58657 + .maxlen = sizeof(int),
58658 + .mode = 0600,
58659 + .proc_handler = &proc_dointvec,
58660 + },
58661 +#endif
58662 +#ifdef CONFIG_GRKERNSEC_DMESG
58663 + {
58664 + .procname = "dmesg",
58665 + .data = &grsec_enable_dmesg,
58666 + .maxlen = sizeof(int),
58667 + .mode = 0600,
58668 + .proc_handler = &proc_dointvec,
58669 + },
58670 +#endif
58671 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58672 + {
58673 + .procname = "chroot_findtask",
58674 + .data = &grsec_enable_chroot_findtask,
58675 + .maxlen = sizeof(int),
58676 + .mode = 0600,
58677 + .proc_handler = &proc_dointvec,
58678 + },
58679 +#endif
58680 +#ifdef CONFIG_GRKERNSEC_RESLOG
58681 + {
58682 + .procname = "resource_logging",
58683 + .data = &grsec_resource_logging,
58684 + .maxlen = sizeof(int),
58685 + .mode = 0600,
58686 + .proc_handler = &proc_dointvec,
58687 + },
58688 +#endif
58689 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58690 + {
58691 + .procname = "audit_ptrace",
58692 + .data = &grsec_enable_audit_ptrace,
58693 + .maxlen = sizeof(int),
58694 + .mode = 0600,
58695 + .proc_handler = &proc_dointvec,
58696 + },
58697 +#endif
58698 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58699 + {
58700 + .procname = "harden_ptrace",
58701 + .data = &grsec_enable_harden_ptrace,
58702 + .maxlen = sizeof(int),
58703 + .mode = 0600,
58704 + .proc_handler = &proc_dointvec,
58705 + },
58706 +#endif
58707 + {
58708 + .procname = "grsec_lock",
58709 + .data = &grsec_lock,
58710 + .maxlen = sizeof(int),
58711 + .mode = 0600,
58712 + .proc_handler = &proc_dointvec,
58713 + },
58714 +#endif
58715 +#ifdef CONFIG_GRKERNSEC_ROFS
58716 + {
58717 + .procname = "romount_protect",
58718 + .data = &grsec_enable_rofs,
58719 + .maxlen = sizeof(int),
58720 + .mode = 0600,
58721 + .proc_handler = &proc_dointvec_minmax,
58722 + .extra1 = &one,
58723 + .extra2 = &one,
58724 + },
58725 +#endif
58726 + { }
58727 +};
58728 +#endif
58729 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58730 new file mode 100644
58731 index 0000000..0dc13c3
58732 --- /dev/null
58733 +++ b/grsecurity/grsec_time.c
58734 @@ -0,0 +1,16 @@
58735 +#include <linux/kernel.h>
58736 +#include <linux/sched.h>
58737 +#include <linux/grinternal.h>
58738 +#include <linux/module.h>
58739 +
58740 +void
58741 +gr_log_timechange(void)
58742 +{
58743 +#ifdef CONFIG_GRKERNSEC_TIME
58744 + if (grsec_enable_time)
58745 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58746 +#endif
58747 + return;
58748 +}
58749 +
58750 +EXPORT_SYMBOL(gr_log_timechange);
58751 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58752 new file mode 100644
58753 index 0000000..07e0dc0
58754 --- /dev/null
58755 +++ b/grsecurity/grsec_tpe.c
58756 @@ -0,0 +1,73 @@
58757 +#include <linux/kernel.h>
58758 +#include <linux/sched.h>
58759 +#include <linux/file.h>
58760 +#include <linux/fs.h>
58761 +#include <linux/grinternal.h>
58762 +
58763 +extern int gr_acl_tpe_check(void);
58764 +
58765 +int
58766 +gr_tpe_allow(const struct file *file)
58767 +{
58768 +#ifdef CONFIG_GRKERNSEC
58769 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58770 + const struct cred *cred = current_cred();
58771 + char *msg = NULL;
58772 + char *msg2 = NULL;
58773 +
58774 + // never restrict root
58775 + if (!cred->uid)
58776 + return 1;
58777 +
58778 + if (grsec_enable_tpe) {
58779 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58780 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58781 + msg = "not being in trusted group";
58782 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58783 + msg = "being in untrusted group";
58784 +#else
58785 + if (in_group_p(grsec_tpe_gid))
58786 + msg = "being in untrusted group";
58787 +#endif
58788 + }
58789 + if (!msg && gr_acl_tpe_check())
58790 + msg = "being in untrusted role";
58791 +
58792 + // not in any affected group/role
58793 + if (!msg)
58794 + goto next_check;
58795 +
58796 + if (inode->i_uid)
58797 + msg2 = "file in non-root-owned directory";
58798 + else if (inode->i_mode & S_IWOTH)
58799 + msg2 = "file in world-writable directory";
58800 + else if (inode->i_mode & S_IWGRP)
58801 + msg2 = "file in group-writable directory";
58802 +
58803 + if (msg && msg2) {
58804 + char fullmsg[70] = {0};
58805 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58806 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58807 + return 0;
58808 + }
58809 + msg = NULL;
58810 +next_check:
58811 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58812 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58813 + return 1;
58814 +
58815 + if (inode->i_uid && (inode->i_uid != cred->uid))
58816 + msg = "directory not owned by user";
58817 + else if (inode->i_mode & S_IWOTH)
58818 + msg = "file in world-writable directory";
58819 + else if (inode->i_mode & S_IWGRP)
58820 + msg = "file in group-writable directory";
58821 +
58822 + if (msg) {
58823 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58824 + return 0;
58825 + }
58826 +#endif
58827 +#endif
58828 + return 1;
58829 +}
58830 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58831 new file mode 100644
58832 index 0000000..9f7b1ac
58833 --- /dev/null
58834 +++ b/grsecurity/grsum.c
58835 @@ -0,0 +1,61 @@
58836 +#include <linux/err.h>
58837 +#include <linux/kernel.h>
58838 +#include <linux/sched.h>
58839 +#include <linux/mm.h>
58840 +#include <linux/scatterlist.h>
58841 +#include <linux/crypto.h>
58842 +#include <linux/gracl.h>
58843 +
58844 +
58845 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58846 +#error "crypto and sha256 must be built into the kernel"
58847 +#endif
58848 +
58849 +int
58850 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58851 +{
58852 + char *p;
58853 + struct crypto_hash *tfm;
58854 + struct hash_desc desc;
58855 + struct scatterlist sg;
58856 + unsigned char temp_sum[GR_SHA_LEN];
58857 + volatile int retval = 0;
58858 + volatile int dummy = 0;
58859 + unsigned int i;
58860 +
58861 + sg_init_table(&sg, 1);
58862 +
58863 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58864 + if (IS_ERR(tfm)) {
58865 + /* should never happen, since sha256 should be built in */
58866 + return 1;
58867 + }
58868 +
58869 + desc.tfm = tfm;
58870 + desc.flags = 0;
58871 +
58872 + crypto_hash_init(&desc);
58873 +
58874 + p = salt;
58875 + sg_set_buf(&sg, p, GR_SALT_LEN);
58876 + crypto_hash_update(&desc, &sg, sg.length);
58877 +
58878 + p = entry->pw;
58879 + sg_set_buf(&sg, p, strlen(p));
58880 +
58881 + crypto_hash_update(&desc, &sg, sg.length);
58882 +
58883 + crypto_hash_final(&desc, temp_sum);
58884 +
58885 + memset(entry->pw, 0, GR_PW_LEN);
58886 +
58887 + for (i = 0; i < GR_SHA_LEN; i++)
58888 + if (sum[i] != temp_sum[i])
58889 + retval = 1;
58890 + else
58891 + dummy = 1; // waste a cycle
58892 +
58893 + crypto_free_hash(tfm);
58894 +
58895 + return retval;
58896 +}
58897 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58898 index f1c8ca6..b5c1cc7 100644
58899 --- a/include/acpi/acpi_bus.h
58900 +++ b/include/acpi/acpi_bus.h
58901 @@ -107,7 +107,7 @@ struct acpi_device_ops {
58902 acpi_op_bind bind;
58903 acpi_op_unbind unbind;
58904 acpi_op_notify notify;
58905 -};
58906 +} __no_const;
58907
58908 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58909
58910 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58911 index b7babf0..71e4e74 100644
58912 --- a/include/asm-generic/atomic-long.h
58913 +++ b/include/asm-generic/atomic-long.h
58914 @@ -22,6 +22,12 @@
58915
58916 typedef atomic64_t atomic_long_t;
58917
58918 +#ifdef CONFIG_PAX_REFCOUNT
58919 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
58920 +#else
58921 +typedef atomic64_t atomic_long_unchecked_t;
58922 +#endif
58923 +
58924 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58925
58926 static inline long atomic_long_read(atomic_long_t *l)
58927 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58928 return (long)atomic64_read(v);
58929 }
58930
58931 +#ifdef CONFIG_PAX_REFCOUNT
58932 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58933 +{
58934 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58935 +
58936 + return (long)atomic64_read_unchecked(v);
58937 +}
58938 +#endif
58939 +
58940 static inline void atomic_long_set(atomic_long_t *l, long i)
58941 {
58942 atomic64_t *v = (atomic64_t *)l;
58943 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58944 atomic64_set(v, i);
58945 }
58946
58947 +#ifdef CONFIG_PAX_REFCOUNT
58948 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58949 +{
58950 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58951 +
58952 + atomic64_set_unchecked(v, i);
58953 +}
58954 +#endif
58955 +
58956 static inline void atomic_long_inc(atomic_long_t *l)
58957 {
58958 atomic64_t *v = (atomic64_t *)l;
58959 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58960 atomic64_inc(v);
58961 }
58962
58963 +#ifdef CONFIG_PAX_REFCOUNT
58964 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58965 +{
58966 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58967 +
58968 + atomic64_inc_unchecked(v);
58969 +}
58970 +#endif
58971 +
58972 static inline void atomic_long_dec(atomic_long_t *l)
58973 {
58974 atomic64_t *v = (atomic64_t *)l;
58975 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58976 atomic64_dec(v);
58977 }
58978
58979 +#ifdef CONFIG_PAX_REFCOUNT
58980 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58981 +{
58982 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58983 +
58984 + atomic64_dec_unchecked(v);
58985 +}
58986 +#endif
58987 +
58988 static inline void atomic_long_add(long i, atomic_long_t *l)
58989 {
58990 atomic64_t *v = (atomic64_t *)l;
58991 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58992 atomic64_add(i, v);
58993 }
58994
58995 +#ifdef CONFIG_PAX_REFCOUNT
58996 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58997 +{
58998 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58999 +
59000 + atomic64_add_unchecked(i, v);
59001 +}
59002 +#endif
59003 +
59004 static inline void atomic_long_sub(long i, atomic_long_t *l)
59005 {
59006 atomic64_t *v = (atomic64_t *)l;
59007 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59008 atomic64_sub(i, v);
59009 }
59010
59011 +#ifdef CONFIG_PAX_REFCOUNT
59012 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59013 +{
59014 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59015 +
59016 + atomic64_sub_unchecked(i, v);
59017 +}
59018 +#endif
59019 +
59020 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59021 {
59022 atomic64_t *v = (atomic64_t *)l;
59023 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59024 return (long)atomic64_inc_return(v);
59025 }
59026
59027 +#ifdef CONFIG_PAX_REFCOUNT
59028 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59029 +{
59030 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59031 +
59032 + return (long)atomic64_inc_return_unchecked(v);
59033 +}
59034 +#endif
59035 +
59036 static inline long atomic_long_dec_return(atomic_long_t *l)
59037 {
59038 atomic64_t *v = (atomic64_t *)l;
59039 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59040
59041 typedef atomic_t atomic_long_t;
59042
59043 +#ifdef CONFIG_PAX_REFCOUNT
59044 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59045 +#else
59046 +typedef atomic_t atomic_long_unchecked_t;
59047 +#endif
59048 +
59049 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59050 static inline long atomic_long_read(atomic_long_t *l)
59051 {
59052 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59053 return (long)atomic_read(v);
59054 }
59055
59056 +#ifdef CONFIG_PAX_REFCOUNT
59057 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59058 +{
59059 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59060 +
59061 + return (long)atomic_read_unchecked(v);
59062 +}
59063 +#endif
59064 +
59065 static inline void atomic_long_set(atomic_long_t *l, long i)
59066 {
59067 atomic_t *v = (atomic_t *)l;
59068 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59069 atomic_set(v, i);
59070 }
59071
59072 +#ifdef CONFIG_PAX_REFCOUNT
59073 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59074 +{
59075 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59076 +
59077 + atomic_set_unchecked(v, i);
59078 +}
59079 +#endif
59080 +
59081 static inline void atomic_long_inc(atomic_long_t *l)
59082 {
59083 atomic_t *v = (atomic_t *)l;
59084 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59085 atomic_inc(v);
59086 }
59087
59088 +#ifdef CONFIG_PAX_REFCOUNT
59089 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59090 +{
59091 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59092 +
59093 + atomic_inc_unchecked(v);
59094 +}
59095 +#endif
59096 +
59097 static inline void atomic_long_dec(atomic_long_t *l)
59098 {
59099 atomic_t *v = (atomic_t *)l;
59100 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59101 atomic_dec(v);
59102 }
59103
59104 +#ifdef CONFIG_PAX_REFCOUNT
59105 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59106 +{
59107 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59108 +
59109 + atomic_dec_unchecked(v);
59110 +}
59111 +#endif
59112 +
59113 static inline void atomic_long_add(long i, atomic_long_t *l)
59114 {
59115 atomic_t *v = (atomic_t *)l;
59116 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59117 atomic_add(i, v);
59118 }
59119
59120 +#ifdef CONFIG_PAX_REFCOUNT
59121 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59122 +{
59123 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59124 +
59125 + atomic_add_unchecked(i, v);
59126 +}
59127 +#endif
59128 +
59129 static inline void atomic_long_sub(long i, atomic_long_t *l)
59130 {
59131 atomic_t *v = (atomic_t *)l;
59132 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59133 atomic_sub(i, v);
59134 }
59135
59136 +#ifdef CONFIG_PAX_REFCOUNT
59137 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59138 +{
59139 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59140 +
59141 + atomic_sub_unchecked(i, v);
59142 +}
59143 +#endif
59144 +
59145 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59146 {
59147 atomic_t *v = (atomic_t *)l;
59148 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59149 return (long)atomic_inc_return(v);
59150 }
59151
59152 +#ifdef CONFIG_PAX_REFCOUNT
59153 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59154 +{
59155 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59156 +
59157 + return (long)atomic_inc_return_unchecked(v);
59158 +}
59159 +#endif
59160 +
59161 static inline long atomic_long_dec_return(atomic_long_t *l)
59162 {
59163 atomic_t *v = (atomic_t *)l;
59164 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59165
59166 #endif /* BITS_PER_LONG == 64 */
59167
59168 +#ifdef CONFIG_PAX_REFCOUNT
59169 +static inline void pax_refcount_needs_these_functions(void)
59170 +{
59171 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59172 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59173 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59174 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59175 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59176 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59177 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59178 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59179 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59180 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59181 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59182 +
59183 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59184 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59185 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59186 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59187 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59188 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59189 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59190 +}
59191 +#else
59192 +#define atomic_read_unchecked(v) atomic_read(v)
59193 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59194 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59195 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59196 +#define atomic_inc_unchecked(v) atomic_inc(v)
59197 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59198 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59199 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59200 +#define atomic_dec_unchecked(v) atomic_dec(v)
59201 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59202 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59203 +
59204 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59205 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59206 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59207 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59208 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59209 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59210 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59211 +#endif
59212 +
59213 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59214 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59215 index b18ce4f..2ee2843 100644
59216 --- a/include/asm-generic/atomic64.h
59217 +++ b/include/asm-generic/atomic64.h
59218 @@ -16,6 +16,8 @@ typedef struct {
59219 long long counter;
59220 } atomic64_t;
59221
59222 +typedef atomic64_t atomic64_unchecked_t;
59223 +
59224 #define ATOMIC64_INIT(i) { (i) }
59225
59226 extern long long atomic64_read(const atomic64_t *v);
59227 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59228 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59229 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59230
59231 +#define atomic64_read_unchecked(v) atomic64_read(v)
59232 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59233 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59234 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59235 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59236 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59237 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59238 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59239 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59240 +
59241 #endif /* _ASM_GENERIC_ATOMIC64_H */
59242 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59243 index 1bfcfe5..e04c5c9 100644
59244 --- a/include/asm-generic/cache.h
59245 +++ b/include/asm-generic/cache.h
59246 @@ -6,7 +6,7 @@
59247 * cache lines need to provide their own cache.h.
59248 */
59249
59250 -#define L1_CACHE_SHIFT 5
59251 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59252 +#define L1_CACHE_SHIFT 5UL
59253 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59254
59255 #endif /* __ASM_GENERIC_CACHE_H */
59256 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59257 index 0d68a1e..b74a761 100644
59258 --- a/include/asm-generic/emergency-restart.h
59259 +++ b/include/asm-generic/emergency-restart.h
59260 @@ -1,7 +1,7 @@
59261 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59262 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59263
59264 -static inline void machine_emergency_restart(void)
59265 +static inline __noreturn void machine_emergency_restart(void)
59266 {
59267 machine_restart(NULL);
59268 }
59269 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59270 index 0232ccb..13d9165 100644
59271 --- a/include/asm-generic/kmap_types.h
59272 +++ b/include/asm-generic/kmap_types.h
59273 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59274 KMAP_D(17) KM_NMI,
59275 KMAP_D(18) KM_NMI_PTE,
59276 KMAP_D(19) KM_KDB,
59277 +KMAP_D(20) KM_CLEARPAGE,
59278 /*
59279 * Remember to update debug_kmap_atomic() when adding new kmap types!
59280 */
59281 -KMAP_D(20) KM_TYPE_NR
59282 +KMAP_D(21) KM_TYPE_NR
59283 };
59284
59285 #undef KMAP_D
59286 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59287 index 9ceb03b..2efbcbd 100644
59288 --- a/include/asm-generic/local.h
59289 +++ b/include/asm-generic/local.h
59290 @@ -39,6 +39,7 @@ typedef struct
59291 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59292 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59293 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59294 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59295
59296 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59297 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59298 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59299 index 725612b..9cc513a 100644
59300 --- a/include/asm-generic/pgtable-nopmd.h
59301 +++ b/include/asm-generic/pgtable-nopmd.h
59302 @@ -1,14 +1,19 @@
59303 #ifndef _PGTABLE_NOPMD_H
59304 #define _PGTABLE_NOPMD_H
59305
59306 -#ifndef __ASSEMBLY__
59307 -
59308 #include <asm-generic/pgtable-nopud.h>
59309
59310 -struct mm_struct;
59311 -
59312 #define __PAGETABLE_PMD_FOLDED
59313
59314 +#define PMD_SHIFT PUD_SHIFT
59315 +#define PTRS_PER_PMD 1
59316 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59317 +#define PMD_MASK (~(PMD_SIZE-1))
59318 +
59319 +#ifndef __ASSEMBLY__
59320 +
59321 +struct mm_struct;
59322 +
59323 /*
59324 * Having the pmd type consist of a pud gets the size right, and allows
59325 * us to conceptually access the pud entry that this pmd is folded into
59326 @@ -16,11 +21,6 @@ struct mm_struct;
59327 */
59328 typedef struct { pud_t pud; } pmd_t;
59329
59330 -#define PMD_SHIFT PUD_SHIFT
59331 -#define PTRS_PER_PMD 1
59332 -#define PMD_SIZE (1UL << PMD_SHIFT)
59333 -#define PMD_MASK (~(PMD_SIZE-1))
59334 -
59335 /*
59336 * The "pud_xxx()" functions here are trivial for a folded two-level
59337 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59338 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59339 index 810431d..0ec4804f 100644
59340 --- a/include/asm-generic/pgtable-nopud.h
59341 +++ b/include/asm-generic/pgtable-nopud.h
59342 @@ -1,10 +1,15 @@
59343 #ifndef _PGTABLE_NOPUD_H
59344 #define _PGTABLE_NOPUD_H
59345
59346 -#ifndef __ASSEMBLY__
59347 -
59348 #define __PAGETABLE_PUD_FOLDED
59349
59350 +#define PUD_SHIFT PGDIR_SHIFT
59351 +#define PTRS_PER_PUD 1
59352 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59353 +#define PUD_MASK (~(PUD_SIZE-1))
59354 +
59355 +#ifndef __ASSEMBLY__
59356 +
59357 /*
59358 * Having the pud type consist of a pgd gets the size right, and allows
59359 * us to conceptually access the pgd entry that this pud is folded into
59360 @@ -12,11 +17,6 @@
59361 */
59362 typedef struct { pgd_t pgd; } pud_t;
59363
59364 -#define PUD_SHIFT PGDIR_SHIFT
59365 -#define PTRS_PER_PUD 1
59366 -#define PUD_SIZE (1UL << PUD_SHIFT)
59367 -#define PUD_MASK (~(PUD_SIZE-1))
59368 -
59369 /*
59370 * The "pgd_xxx()" functions here are trivial for a folded two-level
59371 * setup: the pud is never bad, and a pud always exists (as it's folded
59372 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59373 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59374
59375 #define pgd_populate(mm, pgd, pud) do { } while (0)
59376 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59377 /*
59378 * (puds are folded into pgds so this doesn't get actually called,
59379 * but the define is needed for a generic inline function.)
59380 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59381 index c7ec2cd..909d125 100644
59382 --- a/include/asm-generic/pgtable.h
59383 +++ b/include/asm-generic/pgtable.h
59384 @@ -531,6 +531,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59385 #endif
59386 }
59387
59388 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59389 +static inline unsigned long pax_open_kernel(void) { return 0; }
59390 +#endif
59391 +
59392 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59393 +static inline unsigned long pax_close_kernel(void) { return 0; }
59394 +#endif
59395 +
59396 #endif /* CONFIG_MMU */
59397
59398 #endif /* !__ASSEMBLY__ */
59399 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59400 index 8aeadf6..f1dc019 100644
59401 --- a/include/asm-generic/vmlinux.lds.h
59402 +++ b/include/asm-generic/vmlinux.lds.h
59403 @@ -218,6 +218,7 @@
59404 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59405 VMLINUX_SYMBOL(__start_rodata) = .; \
59406 *(.rodata) *(.rodata.*) \
59407 + *(.data..read_only) \
59408 *(__vermagic) /* Kernel version magic */ \
59409 . = ALIGN(8); \
59410 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59411 @@ -716,17 +717,18 @@
59412 * section in the linker script will go there too. @phdr should have
59413 * a leading colon.
59414 *
59415 - * Note that this macros defines __per_cpu_load as an absolute symbol.
59416 + * Note that this macros defines per_cpu_load as an absolute symbol.
59417 * If there is no need to put the percpu section at a predetermined
59418 * address, use PERCPU_SECTION.
59419 */
59420 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59421 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
59422 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59423 + per_cpu_load = .; \
59424 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59425 - LOAD_OFFSET) { \
59426 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59427 PERCPU_INPUT(cacheline) \
59428 } phdr \
59429 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59430 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59431
59432 /**
59433 * PERCPU_SECTION - define output section for percpu area, simple version
59434 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59435 index dd73104..fde86bd 100644
59436 --- a/include/drm/drmP.h
59437 +++ b/include/drm/drmP.h
59438 @@ -72,6 +72,7 @@
59439 #include <linux/workqueue.h>
59440 #include <linux/poll.h>
59441 #include <asm/pgalloc.h>
59442 +#include <asm/local.h>
59443 #include "drm.h"
59444
59445 #include <linux/idr.h>
59446 @@ -1074,7 +1075,7 @@ struct drm_device {
59447
59448 /** \name Usage Counters */
59449 /*@{ */
59450 - int open_count; /**< Outstanding files open */
59451 + local_t open_count; /**< Outstanding files open */
59452 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59453 atomic_t vma_count; /**< Outstanding vma areas open */
59454 int buf_use; /**< Buffers in use -- cannot alloc */
59455 @@ -1085,7 +1086,7 @@ struct drm_device {
59456 /*@{ */
59457 unsigned long counters;
59458 enum drm_stat_type types[15];
59459 - atomic_t counts[15];
59460 + atomic_unchecked_t counts[15];
59461 /*@} */
59462
59463 struct list_head filelist;
59464 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59465 index 37515d1..34fa8b0 100644
59466 --- a/include/drm/drm_crtc_helper.h
59467 +++ b/include/drm/drm_crtc_helper.h
59468 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59469
59470 /* disable crtc when not in use - more explicit than dpms off */
59471 void (*disable)(struct drm_crtc *crtc);
59472 -};
59473 +} __no_const;
59474
59475 struct drm_encoder_helper_funcs {
59476 void (*dpms)(struct drm_encoder *encoder, int mode);
59477 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59478 struct drm_connector *connector);
59479 /* disable encoder when not in use - more explicit than dpms off */
59480 void (*disable)(struct drm_encoder *encoder);
59481 -};
59482 +} __no_const;
59483
59484 struct drm_connector_helper_funcs {
59485 int (*get_modes)(struct drm_connector *connector);
59486 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59487 index d6d1da4..fdd1ac5 100644
59488 --- a/include/drm/ttm/ttm_memory.h
59489 +++ b/include/drm/ttm/ttm_memory.h
59490 @@ -48,7 +48,7 @@
59491
59492 struct ttm_mem_shrink {
59493 int (*do_shrink) (struct ttm_mem_shrink *);
59494 -};
59495 +} __no_const;
59496
59497 /**
59498 * struct ttm_mem_global - Global memory accounting structure.
59499 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59500 index e86dfca..40cc55f 100644
59501 --- a/include/linux/a.out.h
59502 +++ b/include/linux/a.out.h
59503 @@ -39,6 +39,14 @@ enum machine_type {
59504 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59505 };
59506
59507 +/* Constants for the N_FLAGS field */
59508 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59509 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59510 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59511 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59512 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59513 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59514 +
59515 #if !defined (N_MAGIC)
59516 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59517 #endif
59518 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59519 index 06fd4bb..1caec0d 100644
59520 --- a/include/linux/atmdev.h
59521 +++ b/include/linux/atmdev.h
59522 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59523 #endif
59524
59525 struct k_atm_aal_stats {
59526 -#define __HANDLE_ITEM(i) atomic_t i
59527 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59528 __AAL_STAT_ITEMS
59529 #undef __HANDLE_ITEM
59530 };
59531 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59532 index 366422b..1fa7f84 100644
59533 --- a/include/linux/binfmts.h
59534 +++ b/include/linux/binfmts.h
59535 @@ -89,6 +89,7 @@ struct linux_binfmt {
59536 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59537 int (*load_shlib)(struct file *);
59538 int (*core_dump)(struct coredump_params *cprm);
59539 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59540 unsigned long min_coredump; /* minimal dump size */
59541 };
59542
59543 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59544 index 4d4ac24..2c3ccce 100644
59545 --- a/include/linux/blkdev.h
59546 +++ b/include/linux/blkdev.h
59547 @@ -1376,7 +1376,7 @@ struct block_device_operations {
59548 /* this callback is with swap_lock and sometimes page table lock held */
59549 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59550 struct module *owner;
59551 -};
59552 +} __do_const;
59553
59554 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59555 unsigned long);
59556 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59557 index 4d1a074..88f929a 100644
59558 --- a/include/linux/blktrace_api.h
59559 +++ b/include/linux/blktrace_api.h
59560 @@ -162,7 +162,7 @@ struct blk_trace {
59561 struct dentry *dir;
59562 struct dentry *dropped_file;
59563 struct dentry *msg_file;
59564 - atomic_t dropped;
59565 + atomic_unchecked_t dropped;
59566 };
59567
59568 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59569 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59570 index 83195fb..0b0f77d 100644
59571 --- a/include/linux/byteorder/little_endian.h
59572 +++ b/include/linux/byteorder/little_endian.h
59573 @@ -42,51 +42,51 @@
59574
59575 static inline __le64 __cpu_to_le64p(const __u64 *p)
59576 {
59577 - return (__force __le64)*p;
59578 + return (__force const __le64)*p;
59579 }
59580 static inline __u64 __le64_to_cpup(const __le64 *p)
59581 {
59582 - return (__force __u64)*p;
59583 + return (__force const __u64)*p;
59584 }
59585 static inline __le32 __cpu_to_le32p(const __u32 *p)
59586 {
59587 - return (__force __le32)*p;
59588 + return (__force const __le32)*p;
59589 }
59590 static inline __u32 __le32_to_cpup(const __le32 *p)
59591 {
59592 - return (__force __u32)*p;
59593 + return (__force const __u32)*p;
59594 }
59595 static inline __le16 __cpu_to_le16p(const __u16 *p)
59596 {
59597 - return (__force __le16)*p;
59598 + return (__force const __le16)*p;
59599 }
59600 static inline __u16 __le16_to_cpup(const __le16 *p)
59601 {
59602 - return (__force __u16)*p;
59603 + return (__force const __u16)*p;
59604 }
59605 static inline __be64 __cpu_to_be64p(const __u64 *p)
59606 {
59607 - return (__force __be64)__swab64p(p);
59608 + return (__force const __be64)__swab64p(p);
59609 }
59610 static inline __u64 __be64_to_cpup(const __be64 *p)
59611 {
59612 - return __swab64p((__u64 *)p);
59613 + return __swab64p((const __u64 *)p);
59614 }
59615 static inline __be32 __cpu_to_be32p(const __u32 *p)
59616 {
59617 - return (__force __be32)__swab32p(p);
59618 + return (__force const __be32)__swab32p(p);
59619 }
59620 static inline __u32 __be32_to_cpup(const __be32 *p)
59621 {
59622 - return __swab32p((__u32 *)p);
59623 + return __swab32p((const __u32 *)p);
59624 }
59625 static inline __be16 __cpu_to_be16p(const __u16 *p)
59626 {
59627 - return (__force __be16)__swab16p(p);
59628 + return (__force const __be16)__swab16p(p);
59629 }
59630 static inline __u16 __be16_to_cpup(const __be16 *p)
59631 {
59632 - return __swab16p((__u16 *)p);
59633 + return __swab16p((const __u16 *)p);
59634 }
59635 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59636 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59637 diff --git a/include/linux/cache.h b/include/linux/cache.h
59638 index 4c57065..4307975 100644
59639 --- a/include/linux/cache.h
59640 +++ b/include/linux/cache.h
59641 @@ -16,6 +16,10 @@
59642 #define __read_mostly
59643 #endif
59644
59645 +#ifndef __read_only
59646 +#define __read_only __read_mostly
59647 +#endif
59648 +
59649 #ifndef ____cacheline_aligned
59650 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59651 #endif
59652 diff --git a/include/linux/capability.h b/include/linux/capability.h
59653 index 12d52de..b5f7fa7 100644
59654 --- a/include/linux/capability.h
59655 +++ b/include/linux/capability.h
59656 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59657 extern bool capable(int cap);
59658 extern bool ns_capable(struct user_namespace *ns, int cap);
59659 extern bool nsown_capable(int cap);
59660 +extern bool capable_nolog(int cap);
59661 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59662
59663 /* audit system wants to get cap info from files as well */
59664 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59665 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59666 index 42e55de..1cd0e66 100644
59667 --- a/include/linux/cleancache.h
59668 +++ b/include/linux/cleancache.h
59669 @@ -31,7 +31,7 @@ struct cleancache_ops {
59670 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
59671 void (*invalidate_inode)(int, struct cleancache_filekey);
59672 void (*invalidate_fs)(int);
59673 -};
59674 +} __no_const;
59675
59676 extern struct cleancache_ops
59677 cleancache_register_ops(struct cleancache_ops *ops);
59678 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59679 index 2f40791..a62d196 100644
59680 --- a/include/linux/compiler-gcc4.h
59681 +++ b/include/linux/compiler-gcc4.h
59682 @@ -32,6 +32,16 @@
59683 #define __linktime_error(message) __attribute__((__error__(message)))
59684
59685 #if __GNUC_MINOR__ >= 5
59686 +
59687 +#ifdef CONSTIFY_PLUGIN
59688 +#define __no_const __attribute__((no_const))
59689 +#define __do_const __attribute__((do_const))
59690 +#endif
59691 +
59692 +#ifdef SIZE_OVERFLOW_PLUGIN
59693 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
59694 +#endif
59695 +
59696 /*
59697 * Mark a position in code as unreachable. This can be used to
59698 * suppress control flow warnings after asm blocks that transfer
59699 @@ -47,6 +57,11 @@
59700 #define __noclone __attribute__((__noclone__))
59701
59702 #endif
59703 +
59704 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59705 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59706 +#define __bos0(ptr) __bos((ptr), 0)
59707 +#define __bos1(ptr) __bos((ptr), 1)
59708 #endif
59709
59710 #if __GNUC_MINOR__ > 0
59711 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59712 index 923d093..726c17f 100644
59713 --- a/include/linux/compiler.h
59714 +++ b/include/linux/compiler.h
59715 @@ -5,31 +5,62 @@
59716
59717 #ifdef __CHECKER__
59718 # define __user __attribute__((noderef, address_space(1)))
59719 +# define __force_user __force __user
59720 # define __kernel __attribute__((address_space(0)))
59721 +# define __force_kernel __force __kernel
59722 # define __safe __attribute__((safe))
59723 # define __force __attribute__((force))
59724 # define __nocast __attribute__((nocast))
59725 # define __iomem __attribute__((noderef, address_space(2)))
59726 +# define __force_iomem __force __iomem
59727 # define __acquires(x) __attribute__((context(x,0,1)))
59728 # define __releases(x) __attribute__((context(x,1,0)))
59729 # define __acquire(x) __context__(x,1)
59730 # define __release(x) __context__(x,-1)
59731 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59732 # define __percpu __attribute__((noderef, address_space(3)))
59733 +# define __force_percpu __force __percpu
59734 #ifdef CONFIG_SPARSE_RCU_POINTER
59735 # define __rcu __attribute__((noderef, address_space(4)))
59736 +# define __force_rcu __force __rcu
59737 #else
59738 # define __rcu
59739 +# define __force_rcu
59740 #endif
59741 extern void __chk_user_ptr(const volatile void __user *);
59742 extern void __chk_io_ptr(const volatile void __iomem *);
59743 +#elif defined(CHECKER_PLUGIN)
59744 +//# define __user
59745 +//# define __force_user
59746 +//# define __kernel
59747 +//# define __force_kernel
59748 +# define __safe
59749 +# define __force
59750 +# define __nocast
59751 +# define __iomem
59752 +# define __force_iomem
59753 +# define __chk_user_ptr(x) (void)0
59754 +# define __chk_io_ptr(x) (void)0
59755 +# define __builtin_warning(x, y...) (1)
59756 +# define __acquires(x)
59757 +# define __releases(x)
59758 +# define __acquire(x) (void)0
59759 +# define __release(x) (void)0
59760 +# define __cond_lock(x,c) (c)
59761 +# define __percpu
59762 +# define __force_percpu
59763 +# define __rcu
59764 +# define __force_rcu
59765 #else
59766 # define __user
59767 +# define __force_user
59768 # define __kernel
59769 +# define __force_kernel
59770 # define __safe
59771 # define __force
59772 # define __nocast
59773 # define __iomem
59774 +# define __force_iomem
59775 # define __chk_user_ptr(x) (void)0
59776 # define __chk_io_ptr(x) (void)0
59777 # define __builtin_warning(x, y...) (1)
59778 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59779 # define __release(x) (void)0
59780 # define __cond_lock(x,c) (c)
59781 # define __percpu
59782 +# define __force_percpu
59783 # define __rcu
59784 +# define __force_rcu
59785 #endif
59786
59787 #ifdef __KERNEL__
59788 @@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59789 # define __attribute_const__ /* unimplemented */
59790 #endif
59791
59792 +#ifndef __no_const
59793 +# define __no_const
59794 +#endif
59795 +
59796 +#ifndef __do_const
59797 +# define __do_const
59798 +#endif
59799 +
59800 +#ifndef __size_overflow
59801 +# define __size_overflow(...)
59802 +#endif
59803 +
59804 /*
59805 * Tell gcc if a function is cold. The compiler will assume any path
59806 * directly leading to the call is unlikely.
59807 @@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59808 #define __cold
59809 #endif
59810
59811 +#ifndef __alloc_size
59812 +#define __alloc_size(...)
59813 +#endif
59814 +
59815 +#ifndef __bos
59816 +#define __bos(ptr, arg)
59817 +#endif
59818 +
59819 +#ifndef __bos0
59820 +#define __bos0(ptr)
59821 +#endif
59822 +
59823 +#ifndef __bos1
59824 +#define __bos1(ptr)
59825 +#endif
59826 +
59827 /* Simple shorthand for a section definition */
59828 #ifndef __section
59829 # define __section(S) __attribute__ ((__section__(#S)))
59830 @@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59831 * use is to mediate communication between process-level code and irq/NMI
59832 * handlers, all running on the same CPU.
59833 */
59834 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59835 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59836 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59837
59838 #endif /* __LINUX_COMPILER_H */
59839 diff --git a/include/linux/cred.h b/include/linux/cred.h
59840 index adadf71..6af5560 100644
59841 --- a/include/linux/cred.h
59842 +++ b/include/linux/cred.h
59843 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59844 static inline void validate_process_creds(void)
59845 {
59846 }
59847 +static inline void validate_task_creds(struct task_struct *task)
59848 +{
59849 +}
59850 #endif
59851
59852 /**
59853 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59854 index b92eadf..b4ecdc1 100644
59855 --- a/include/linux/crypto.h
59856 +++ b/include/linux/crypto.h
59857 @@ -373,7 +373,7 @@ struct cipher_tfm {
59858 const u8 *key, unsigned int keylen);
59859 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59860 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59861 -};
59862 +} __no_const;
59863
59864 struct hash_tfm {
59865 int (*init)(struct hash_desc *desc);
59866 @@ -394,13 +394,13 @@ struct compress_tfm {
59867 int (*cot_decompress)(struct crypto_tfm *tfm,
59868 const u8 *src, unsigned int slen,
59869 u8 *dst, unsigned int *dlen);
59870 -};
59871 +} __no_const;
59872
59873 struct rng_tfm {
59874 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59875 unsigned int dlen);
59876 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59877 -};
59878 +} __no_const;
59879
59880 #define crt_ablkcipher crt_u.ablkcipher
59881 #define crt_aead crt_u.aead
59882 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59883 index 7925bf0..d5143d2 100644
59884 --- a/include/linux/decompress/mm.h
59885 +++ b/include/linux/decompress/mm.h
59886 @@ -77,7 +77,7 @@ static void free(void *where)
59887 * warnings when not needed (indeed large_malloc / large_free are not
59888 * needed by inflate */
59889
59890 -#define malloc(a) kmalloc(a, GFP_KERNEL)
59891 +#define malloc(a) kmalloc((a), GFP_KERNEL)
59892 #define free(a) kfree(a)
59893
59894 #define large_malloc(a) vmalloc(a)
59895 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59896 index dfc099e..e583e66 100644
59897 --- a/include/linux/dma-mapping.h
59898 +++ b/include/linux/dma-mapping.h
59899 @@ -51,7 +51,7 @@ struct dma_map_ops {
59900 u64 (*get_required_mask)(struct device *dev);
59901 #endif
59902 int is_phys;
59903 -};
59904 +} __do_const;
59905
59906 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59907
59908 diff --git a/include/linux/efi.h b/include/linux/efi.h
59909 index ec45ccd..9923c32 100644
59910 --- a/include/linux/efi.h
59911 +++ b/include/linux/efi.h
59912 @@ -635,7 +635,7 @@ struct efivar_operations {
59913 efi_get_variable_t *get_variable;
59914 efi_get_next_variable_t *get_next_variable;
59915 efi_set_variable_t *set_variable;
59916 -};
59917 +} __no_const;
59918
59919 struct efivars {
59920 /*
59921 diff --git a/include/linux/elf.h b/include/linux/elf.h
59922 index 999b4f5..57753b4 100644
59923 --- a/include/linux/elf.h
59924 +++ b/include/linux/elf.h
59925 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
59926 #define PT_GNU_EH_FRAME 0x6474e550
59927
59928 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59929 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59930 +
59931 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59932 +
59933 +/* Constants for the e_flags field */
59934 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59935 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59936 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59937 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59938 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59939 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59940
59941 /*
59942 * Extended Numbering
59943 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
59944 #define DT_DEBUG 21
59945 #define DT_TEXTREL 22
59946 #define DT_JMPREL 23
59947 +#define DT_FLAGS 30
59948 + #define DF_TEXTREL 0x00000004
59949 #define DT_ENCODING 32
59950 #define OLD_DT_LOOS 0x60000000
59951 #define DT_LOOS 0x6000000d
59952 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
59953 #define PF_W 0x2
59954 #define PF_X 0x1
59955
59956 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
59957 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
59958 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
59959 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
59960 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
59961 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
59962 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
59963 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
59964 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
59965 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
59966 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
59967 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
59968 +
59969 typedef struct elf32_phdr{
59970 Elf32_Word p_type;
59971 Elf32_Off p_offset;
59972 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
59973 #define EI_OSABI 7
59974 #define EI_PAD 8
59975
59976 +#define EI_PAX 14
59977 +
59978 #define ELFMAG0 0x7f /* EI_MAG */
59979 #define ELFMAG1 'E'
59980 #define ELFMAG2 'L'
59981 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
59982 #define elf_note elf32_note
59983 #define elf_addr_t Elf32_Off
59984 #define Elf_Half Elf32_Half
59985 +#define elf_dyn Elf32_Dyn
59986
59987 #else
59988
59989 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
59990 #define elf_note elf64_note
59991 #define elf_addr_t Elf64_Off
59992 #define Elf_Half Elf64_Half
59993 +#define elf_dyn Elf64_Dyn
59994
59995 #endif
59996
59997 diff --git a/include/linux/filter.h b/include/linux/filter.h
59998 index 8eeb205..d59bfa2 100644
59999 --- a/include/linux/filter.h
60000 +++ b/include/linux/filter.h
60001 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60002
60003 struct sk_buff;
60004 struct sock;
60005 +struct bpf_jit_work;
60006
60007 struct sk_filter
60008 {
60009 @@ -141,6 +142,9 @@ struct sk_filter
60010 unsigned int len; /* Number of filter blocks */
60011 unsigned int (*bpf_func)(const struct sk_buff *skb,
60012 const struct sock_filter *filter);
60013 +#ifdef CONFIG_BPF_JIT
60014 + struct bpf_jit_work *work;
60015 +#endif
60016 struct rcu_head rcu;
60017 struct sock_filter insns[0];
60018 };
60019 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60020 index cdc9b71..ce69fb5 100644
60021 --- a/include/linux/firewire.h
60022 +++ b/include/linux/firewire.h
60023 @@ -413,7 +413,7 @@ struct fw_iso_context {
60024 union {
60025 fw_iso_callback_t sc;
60026 fw_iso_mc_callback_t mc;
60027 - } callback;
60028 + } __no_const callback;
60029 void *callback_data;
60030 };
60031
60032 diff --git a/include/linux/fs.h b/include/linux/fs.h
60033 index 25c40b9..1bfd4f4 100644
60034 --- a/include/linux/fs.h
60035 +++ b/include/linux/fs.h
60036 @@ -1634,7 +1634,8 @@ struct file_operations {
60037 int (*setlease)(struct file *, long, struct file_lock **);
60038 long (*fallocate)(struct file *file, int mode, loff_t offset,
60039 loff_t len);
60040 -};
60041 +} __do_const;
60042 +typedef struct file_operations __no_const file_operations_no_const;
60043
60044 struct inode_operations {
60045 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60046 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60047 index 003dc0f..3c4ea97 100644
60048 --- a/include/linux/fs_struct.h
60049 +++ b/include/linux/fs_struct.h
60050 @@ -6,7 +6,7 @@
60051 #include <linux/seqlock.h>
60052
60053 struct fs_struct {
60054 - int users;
60055 + atomic_t users;
60056 spinlock_t lock;
60057 seqcount_t seq;
60058 int umask;
60059 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60060 index ce31408..b1ad003 100644
60061 --- a/include/linux/fscache-cache.h
60062 +++ b/include/linux/fscache-cache.h
60063 @@ -102,7 +102,7 @@ struct fscache_operation {
60064 fscache_operation_release_t release;
60065 };
60066
60067 -extern atomic_t fscache_op_debug_id;
60068 +extern atomic_unchecked_t fscache_op_debug_id;
60069 extern void fscache_op_work_func(struct work_struct *work);
60070
60071 extern void fscache_enqueue_operation(struct fscache_operation *);
60072 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60073 {
60074 INIT_WORK(&op->work, fscache_op_work_func);
60075 atomic_set(&op->usage, 1);
60076 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60077 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60078 op->processor = processor;
60079 op->release = release;
60080 INIT_LIST_HEAD(&op->pend_link);
60081 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60082 index a6dfe69..569586df 100644
60083 --- a/include/linux/fsnotify.h
60084 +++ b/include/linux/fsnotify.h
60085 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60086 */
60087 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60088 {
60089 - return kstrdup(name, GFP_KERNEL);
60090 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60091 }
60092
60093 /*
60094 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60095 index 91d0e0a3..035666b 100644
60096 --- a/include/linux/fsnotify_backend.h
60097 +++ b/include/linux/fsnotify_backend.h
60098 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60099 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60100 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60101 };
60102 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60103
60104 /*
60105 * A group is a "thing" that wants to receive notification about filesystem
60106 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60107 index 176a939..1462211 100644
60108 --- a/include/linux/ftrace_event.h
60109 +++ b/include/linux/ftrace_event.h
60110 @@ -97,7 +97,7 @@ struct trace_event_functions {
60111 trace_print_func raw;
60112 trace_print_func hex;
60113 trace_print_func binary;
60114 -};
60115 +} __no_const;
60116
60117 struct trace_event {
60118 struct hlist_node node;
60119 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60120 extern int trace_add_event_call(struct ftrace_event_call *call);
60121 extern void trace_remove_event_call(struct ftrace_event_call *call);
60122
60123 -#define is_signed_type(type) (((type)(-1)) < 0)
60124 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60125
60126 int trace_set_clr_event(const char *system, const char *event, int set);
60127
60128 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60129 index 017a7fb..33a8507 100644
60130 --- a/include/linux/genhd.h
60131 +++ b/include/linux/genhd.h
60132 @@ -185,7 +185,7 @@ struct gendisk {
60133 struct kobject *slave_dir;
60134
60135 struct timer_rand_state *random;
60136 - atomic_t sync_io; /* RAID */
60137 + atomic_unchecked_t sync_io; /* RAID */
60138 struct disk_events *ev;
60139 #ifdef CONFIG_BLK_DEV_INTEGRITY
60140 struct blk_integrity *integrity;
60141 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60142 new file mode 100644
60143 index 0000000..c938b1f
60144 --- /dev/null
60145 +++ b/include/linux/gracl.h
60146 @@ -0,0 +1,319 @@
60147 +#ifndef GR_ACL_H
60148 +#define GR_ACL_H
60149 +
60150 +#include <linux/grdefs.h>
60151 +#include <linux/resource.h>
60152 +#include <linux/capability.h>
60153 +#include <linux/dcache.h>
60154 +#include <asm/resource.h>
60155 +
60156 +/* Major status information */
60157 +
60158 +#define GR_VERSION "grsecurity 2.9.1"
60159 +#define GRSECURITY_VERSION 0x2901
60160 +
60161 +enum {
60162 + GR_SHUTDOWN = 0,
60163 + GR_ENABLE = 1,
60164 + GR_SPROLE = 2,
60165 + GR_RELOAD = 3,
60166 + GR_SEGVMOD = 4,
60167 + GR_STATUS = 5,
60168 + GR_UNSPROLE = 6,
60169 + GR_PASSSET = 7,
60170 + GR_SPROLEPAM = 8,
60171 +};
60172 +
60173 +/* Password setup definitions
60174 + * kernel/grhash.c */
60175 +enum {
60176 + GR_PW_LEN = 128,
60177 + GR_SALT_LEN = 16,
60178 + GR_SHA_LEN = 32,
60179 +};
60180 +
60181 +enum {
60182 + GR_SPROLE_LEN = 64,
60183 +};
60184 +
60185 +enum {
60186 + GR_NO_GLOB = 0,
60187 + GR_REG_GLOB,
60188 + GR_CREATE_GLOB
60189 +};
60190 +
60191 +#define GR_NLIMITS 32
60192 +
60193 +/* Begin Data Structures */
60194 +
60195 +struct sprole_pw {
60196 + unsigned char *rolename;
60197 + unsigned char salt[GR_SALT_LEN];
60198 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60199 +};
60200 +
60201 +struct name_entry {
60202 + __u32 key;
60203 + ino_t inode;
60204 + dev_t device;
60205 + char *name;
60206 + __u16 len;
60207 + __u8 deleted;
60208 + struct name_entry *prev;
60209 + struct name_entry *next;
60210 +};
60211 +
60212 +struct inodev_entry {
60213 + struct name_entry *nentry;
60214 + struct inodev_entry *prev;
60215 + struct inodev_entry *next;
60216 +};
60217 +
60218 +struct acl_role_db {
60219 + struct acl_role_label **r_hash;
60220 + __u32 r_size;
60221 +};
60222 +
60223 +struct inodev_db {
60224 + struct inodev_entry **i_hash;
60225 + __u32 i_size;
60226 +};
60227 +
60228 +struct name_db {
60229 + struct name_entry **n_hash;
60230 + __u32 n_size;
60231 +};
60232 +
60233 +struct crash_uid {
60234 + uid_t uid;
60235 + unsigned long expires;
60236 +};
60237 +
60238 +struct gr_hash_struct {
60239 + void **table;
60240 + void **nametable;
60241 + void *first;
60242 + __u32 table_size;
60243 + __u32 used_size;
60244 + int type;
60245 +};
60246 +
60247 +/* Userspace Grsecurity ACL data structures */
60248 +
60249 +struct acl_subject_label {
60250 + char *filename;
60251 + ino_t inode;
60252 + dev_t device;
60253 + __u32 mode;
60254 + kernel_cap_t cap_mask;
60255 + kernel_cap_t cap_lower;
60256 + kernel_cap_t cap_invert_audit;
60257 +
60258 + struct rlimit res[GR_NLIMITS];
60259 + __u32 resmask;
60260 +
60261 + __u8 user_trans_type;
60262 + __u8 group_trans_type;
60263 + uid_t *user_transitions;
60264 + gid_t *group_transitions;
60265 + __u16 user_trans_num;
60266 + __u16 group_trans_num;
60267 +
60268 + __u32 sock_families[2];
60269 + __u32 ip_proto[8];
60270 + __u32 ip_type;
60271 + struct acl_ip_label **ips;
60272 + __u32 ip_num;
60273 + __u32 inaddr_any_override;
60274 +
60275 + __u32 crashes;
60276 + unsigned long expires;
60277 +
60278 + struct acl_subject_label *parent_subject;
60279 + struct gr_hash_struct *hash;
60280 + struct acl_subject_label *prev;
60281 + struct acl_subject_label *next;
60282 +
60283 + struct acl_object_label **obj_hash;
60284 + __u32 obj_hash_size;
60285 + __u16 pax_flags;
60286 +};
60287 +
60288 +struct role_allowed_ip {
60289 + __u32 addr;
60290 + __u32 netmask;
60291 +
60292 + struct role_allowed_ip *prev;
60293 + struct role_allowed_ip *next;
60294 +};
60295 +
60296 +struct role_transition {
60297 + char *rolename;
60298 +
60299 + struct role_transition *prev;
60300 + struct role_transition *next;
60301 +};
60302 +
60303 +struct acl_role_label {
60304 + char *rolename;
60305 + uid_t uidgid;
60306 + __u16 roletype;
60307 +
60308 + __u16 auth_attempts;
60309 + unsigned long expires;
60310 +
60311 + struct acl_subject_label *root_label;
60312 + struct gr_hash_struct *hash;
60313 +
60314 + struct acl_role_label *prev;
60315 + struct acl_role_label *next;
60316 +
60317 + struct role_transition *transitions;
60318 + struct role_allowed_ip *allowed_ips;
60319 + uid_t *domain_children;
60320 + __u16 domain_child_num;
60321 +
60322 + umode_t umask;
60323 +
60324 + struct acl_subject_label **subj_hash;
60325 + __u32 subj_hash_size;
60326 +};
60327 +
60328 +struct user_acl_role_db {
60329 + struct acl_role_label **r_table;
60330 + __u32 num_pointers; /* Number of allocations to track */
60331 + __u32 num_roles; /* Number of roles */
60332 + __u32 num_domain_children; /* Number of domain children */
60333 + __u32 num_subjects; /* Number of subjects */
60334 + __u32 num_objects; /* Number of objects */
60335 +};
60336 +
60337 +struct acl_object_label {
60338 + char *filename;
60339 + ino_t inode;
60340 + dev_t device;
60341 + __u32 mode;
60342 +
60343 + struct acl_subject_label *nested;
60344 + struct acl_object_label *globbed;
60345 +
60346 + /* next two structures not used */
60347 +
60348 + struct acl_object_label *prev;
60349 + struct acl_object_label *next;
60350 +};
60351 +
60352 +struct acl_ip_label {
60353 + char *iface;
60354 + __u32 addr;
60355 + __u32 netmask;
60356 + __u16 low, high;
60357 + __u8 mode;
60358 + __u32 type;
60359 + __u32 proto[8];
60360 +
60361 + /* next two structures not used */
60362 +
60363 + struct acl_ip_label *prev;
60364 + struct acl_ip_label *next;
60365 +};
60366 +
60367 +struct gr_arg {
60368 + struct user_acl_role_db role_db;
60369 + unsigned char pw[GR_PW_LEN];
60370 + unsigned char salt[GR_SALT_LEN];
60371 + unsigned char sum[GR_SHA_LEN];
60372 + unsigned char sp_role[GR_SPROLE_LEN];
60373 + struct sprole_pw *sprole_pws;
60374 + dev_t segv_device;
60375 + ino_t segv_inode;
60376 + uid_t segv_uid;
60377 + __u16 num_sprole_pws;
60378 + __u16 mode;
60379 +};
60380 +
60381 +struct gr_arg_wrapper {
60382 + struct gr_arg *arg;
60383 + __u32 version;
60384 + __u32 size;
60385 +};
60386 +
60387 +struct subject_map {
60388 + struct acl_subject_label *user;
60389 + struct acl_subject_label *kernel;
60390 + struct subject_map *prev;
60391 + struct subject_map *next;
60392 +};
60393 +
60394 +struct acl_subj_map_db {
60395 + struct subject_map **s_hash;
60396 + __u32 s_size;
60397 +};
60398 +
60399 +/* End Data Structures Section */
60400 +
60401 +/* Hash functions generated by empirical testing by Brad Spengler
60402 + Makes good use of the low bits of the inode. Generally 0-1 times
60403 + in loop for successful match. 0-3 for unsuccessful match.
60404 + Shift/add algorithm with modulus of table size and an XOR*/
60405 +
60406 +static __inline__ unsigned int
60407 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60408 +{
60409 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
60410 +}
60411 +
60412 + static __inline__ unsigned int
60413 +shash(const struct acl_subject_label *userp, const unsigned int sz)
60414 +{
60415 + return ((const unsigned long)userp % sz);
60416 +}
60417 +
60418 +static __inline__ unsigned int
60419 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60420 +{
60421 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60422 +}
60423 +
60424 +static __inline__ unsigned int
60425 +nhash(const char *name, const __u16 len, const unsigned int sz)
60426 +{
60427 + return full_name_hash((const unsigned char *)name, len) % sz;
60428 +}
60429 +
60430 +#define FOR_EACH_ROLE_START(role) \
60431 + role = role_list; \
60432 + while (role) {
60433 +
60434 +#define FOR_EACH_ROLE_END(role) \
60435 + role = role->prev; \
60436 + }
60437 +
60438 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60439 + subj = NULL; \
60440 + iter = 0; \
60441 + while (iter < role->subj_hash_size) { \
60442 + if (subj == NULL) \
60443 + subj = role->subj_hash[iter]; \
60444 + if (subj == NULL) { \
60445 + iter++; \
60446 + continue; \
60447 + }
60448 +
60449 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60450 + subj = subj->next; \
60451 + if (subj == NULL) \
60452 + iter++; \
60453 + }
60454 +
60455 +
60456 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60457 + subj = role->hash->first; \
60458 + while (subj != NULL) {
60459 +
60460 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60461 + subj = subj->next; \
60462 + }
60463 +
60464 +#endif
60465 +
60466 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60467 new file mode 100644
60468 index 0000000..323ecf2
60469 --- /dev/null
60470 +++ b/include/linux/gralloc.h
60471 @@ -0,0 +1,9 @@
60472 +#ifndef __GRALLOC_H
60473 +#define __GRALLOC_H
60474 +
60475 +void acl_free_all(void);
60476 +int acl_alloc_stack_init(unsigned long size);
60477 +void *acl_alloc(unsigned long len);
60478 +void *acl_alloc_num(unsigned long num, unsigned long len);
60479 +
60480 +#endif
60481 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60482 new file mode 100644
60483 index 0000000..b30e9bc
60484 --- /dev/null
60485 +++ b/include/linux/grdefs.h
60486 @@ -0,0 +1,140 @@
60487 +#ifndef GRDEFS_H
60488 +#define GRDEFS_H
60489 +
60490 +/* Begin grsecurity status declarations */
60491 +
60492 +enum {
60493 + GR_READY = 0x01,
60494 + GR_STATUS_INIT = 0x00 // disabled state
60495 +};
60496 +
60497 +/* Begin ACL declarations */
60498 +
60499 +/* Role flags */
60500 +
60501 +enum {
60502 + GR_ROLE_USER = 0x0001,
60503 + GR_ROLE_GROUP = 0x0002,
60504 + GR_ROLE_DEFAULT = 0x0004,
60505 + GR_ROLE_SPECIAL = 0x0008,
60506 + GR_ROLE_AUTH = 0x0010,
60507 + GR_ROLE_NOPW = 0x0020,
60508 + GR_ROLE_GOD = 0x0040,
60509 + GR_ROLE_LEARN = 0x0080,
60510 + GR_ROLE_TPE = 0x0100,
60511 + GR_ROLE_DOMAIN = 0x0200,
60512 + GR_ROLE_PAM = 0x0400,
60513 + GR_ROLE_PERSIST = 0x0800
60514 +};
60515 +
60516 +/* ACL Subject and Object mode flags */
60517 +enum {
60518 + GR_DELETED = 0x80000000
60519 +};
60520 +
60521 +/* ACL Object-only mode flags */
60522 +enum {
60523 + GR_READ = 0x00000001,
60524 + GR_APPEND = 0x00000002,
60525 + GR_WRITE = 0x00000004,
60526 + GR_EXEC = 0x00000008,
60527 + GR_FIND = 0x00000010,
60528 + GR_INHERIT = 0x00000020,
60529 + GR_SETID = 0x00000040,
60530 + GR_CREATE = 0x00000080,
60531 + GR_DELETE = 0x00000100,
60532 + GR_LINK = 0x00000200,
60533 + GR_AUDIT_READ = 0x00000400,
60534 + GR_AUDIT_APPEND = 0x00000800,
60535 + GR_AUDIT_WRITE = 0x00001000,
60536 + GR_AUDIT_EXEC = 0x00002000,
60537 + GR_AUDIT_FIND = 0x00004000,
60538 + GR_AUDIT_INHERIT= 0x00008000,
60539 + GR_AUDIT_SETID = 0x00010000,
60540 + GR_AUDIT_CREATE = 0x00020000,
60541 + GR_AUDIT_DELETE = 0x00040000,
60542 + GR_AUDIT_LINK = 0x00080000,
60543 + GR_PTRACERD = 0x00100000,
60544 + GR_NOPTRACE = 0x00200000,
60545 + GR_SUPPRESS = 0x00400000,
60546 + GR_NOLEARN = 0x00800000,
60547 + GR_INIT_TRANSFER= 0x01000000
60548 +};
60549 +
60550 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60551 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60552 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60553 +
60554 +/* ACL subject-only mode flags */
60555 +enum {
60556 + GR_KILL = 0x00000001,
60557 + GR_VIEW = 0x00000002,
60558 + GR_PROTECTED = 0x00000004,
60559 + GR_LEARN = 0x00000008,
60560 + GR_OVERRIDE = 0x00000010,
60561 + /* just a placeholder, this mode is only used in userspace */
60562 + GR_DUMMY = 0x00000020,
60563 + GR_PROTSHM = 0x00000040,
60564 + GR_KILLPROC = 0x00000080,
60565 + GR_KILLIPPROC = 0x00000100,
60566 + /* just a placeholder, this mode is only used in userspace */
60567 + GR_NOTROJAN = 0x00000200,
60568 + GR_PROTPROCFD = 0x00000400,
60569 + GR_PROCACCT = 0x00000800,
60570 + GR_RELAXPTRACE = 0x00001000,
60571 + GR_NESTED = 0x00002000,
60572 + GR_INHERITLEARN = 0x00004000,
60573 + GR_PROCFIND = 0x00008000,
60574 + GR_POVERRIDE = 0x00010000,
60575 + GR_KERNELAUTH = 0x00020000,
60576 + GR_ATSECURE = 0x00040000,
60577 + GR_SHMEXEC = 0x00080000
60578 +};
60579 +
60580 +enum {
60581 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60582 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60583 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60584 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60585 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60586 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60587 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60588 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60589 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60590 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60591 +};
60592 +
60593 +enum {
60594 + GR_ID_USER = 0x01,
60595 + GR_ID_GROUP = 0x02,
60596 +};
60597 +
60598 +enum {
60599 + GR_ID_ALLOW = 0x01,
60600 + GR_ID_DENY = 0x02,
60601 +};
60602 +
60603 +#define GR_CRASH_RES 31
60604 +#define GR_UIDTABLE_MAX 500
60605 +
60606 +/* begin resource learning section */
60607 +enum {
60608 + GR_RLIM_CPU_BUMP = 60,
60609 + GR_RLIM_FSIZE_BUMP = 50000,
60610 + GR_RLIM_DATA_BUMP = 10000,
60611 + GR_RLIM_STACK_BUMP = 1000,
60612 + GR_RLIM_CORE_BUMP = 10000,
60613 + GR_RLIM_RSS_BUMP = 500000,
60614 + GR_RLIM_NPROC_BUMP = 1,
60615 + GR_RLIM_NOFILE_BUMP = 5,
60616 + GR_RLIM_MEMLOCK_BUMP = 50000,
60617 + GR_RLIM_AS_BUMP = 500000,
60618 + GR_RLIM_LOCKS_BUMP = 2,
60619 + GR_RLIM_SIGPENDING_BUMP = 5,
60620 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60621 + GR_RLIM_NICE_BUMP = 1,
60622 + GR_RLIM_RTPRIO_BUMP = 1,
60623 + GR_RLIM_RTTIME_BUMP = 1000000
60624 +};
60625 +
60626 +#endif
60627 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60628 new file mode 100644
60629 index 0000000..c9292f7
60630 --- /dev/null
60631 +++ b/include/linux/grinternal.h
60632 @@ -0,0 +1,223 @@
60633 +#ifndef __GRINTERNAL_H
60634 +#define __GRINTERNAL_H
60635 +
60636 +#ifdef CONFIG_GRKERNSEC
60637 +
60638 +#include <linux/fs.h>
60639 +#include <linux/mnt_namespace.h>
60640 +#include <linux/nsproxy.h>
60641 +#include <linux/gracl.h>
60642 +#include <linux/grdefs.h>
60643 +#include <linux/grmsg.h>
60644 +
60645 +void gr_add_learn_entry(const char *fmt, ...)
60646 + __attribute__ ((format (printf, 1, 2)));
60647 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60648 + const struct vfsmount *mnt);
60649 +__u32 gr_check_create(const struct dentry *new_dentry,
60650 + const struct dentry *parent,
60651 + const struct vfsmount *mnt, const __u32 mode);
60652 +int gr_check_protected_task(const struct task_struct *task);
60653 +__u32 to_gr_audit(const __u32 reqmode);
60654 +int gr_set_acls(const int type);
60655 +int gr_apply_subject_to_task(struct task_struct *task);
60656 +int gr_acl_is_enabled(void);
60657 +char gr_roletype_to_char(void);
60658 +
60659 +void gr_handle_alertkill(struct task_struct *task);
60660 +char *gr_to_filename(const struct dentry *dentry,
60661 + const struct vfsmount *mnt);
60662 +char *gr_to_filename1(const struct dentry *dentry,
60663 + const struct vfsmount *mnt);
60664 +char *gr_to_filename2(const struct dentry *dentry,
60665 + const struct vfsmount *mnt);
60666 +char *gr_to_filename3(const struct dentry *dentry,
60667 + const struct vfsmount *mnt);
60668 +
60669 +extern int grsec_enable_ptrace_readexec;
60670 +extern int grsec_enable_harden_ptrace;
60671 +extern int grsec_enable_link;
60672 +extern int grsec_enable_fifo;
60673 +extern int grsec_enable_execve;
60674 +extern int grsec_enable_shm;
60675 +extern int grsec_enable_execlog;
60676 +extern int grsec_enable_signal;
60677 +extern int grsec_enable_audit_ptrace;
60678 +extern int grsec_enable_forkfail;
60679 +extern int grsec_enable_time;
60680 +extern int grsec_enable_rofs;
60681 +extern int grsec_enable_chroot_shmat;
60682 +extern int grsec_enable_chroot_mount;
60683 +extern int grsec_enable_chroot_double;
60684 +extern int grsec_enable_chroot_pivot;
60685 +extern int grsec_enable_chroot_chdir;
60686 +extern int grsec_enable_chroot_chmod;
60687 +extern int grsec_enable_chroot_mknod;
60688 +extern int grsec_enable_chroot_fchdir;
60689 +extern int grsec_enable_chroot_nice;
60690 +extern int grsec_enable_chroot_execlog;
60691 +extern int grsec_enable_chroot_caps;
60692 +extern int grsec_enable_chroot_sysctl;
60693 +extern int grsec_enable_chroot_unix;
60694 +extern int grsec_enable_symlinkown;
60695 +extern int grsec_symlinkown_gid;
60696 +extern int grsec_enable_tpe;
60697 +extern int grsec_tpe_gid;
60698 +extern int grsec_enable_tpe_all;
60699 +extern int grsec_enable_tpe_invert;
60700 +extern int grsec_enable_socket_all;
60701 +extern int grsec_socket_all_gid;
60702 +extern int grsec_enable_socket_client;
60703 +extern int grsec_socket_client_gid;
60704 +extern int grsec_enable_socket_server;
60705 +extern int grsec_socket_server_gid;
60706 +extern int grsec_audit_gid;
60707 +extern int grsec_enable_group;
60708 +extern int grsec_enable_audit_textrel;
60709 +extern int grsec_enable_log_rwxmaps;
60710 +extern int grsec_enable_mount;
60711 +extern int grsec_enable_chdir;
60712 +extern int grsec_resource_logging;
60713 +extern int grsec_enable_blackhole;
60714 +extern int grsec_lastack_retries;
60715 +extern int grsec_enable_brute;
60716 +extern int grsec_lock;
60717 +
60718 +extern spinlock_t grsec_alert_lock;
60719 +extern unsigned long grsec_alert_wtime;
60720 +extern unsigned long grsec_alert_fyet;
60721 +
60722 +extern spinlock_t grsec_audit_lock;
60723 +
60724 +extern rwlock_t grsec_exec_file_lock;
60725 +
60726 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60727 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60728 + (tsk)->exec_file->f_vfsmnt) : "/")
60729 +
60730 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60731 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60732 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60733 +
60734 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60735 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60736 + (tsk)->exec_file->f_vfsmnt) : "/")
60737 +
60738 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60739 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60740 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60741 +
60742 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60743 +
60744 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60745 +
60746 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60747 + (task)->pid, (cred)->uid, \
60748 + (cred)->euid, (cred)->gid, (cred)->egid, \
60749 + gr_parent_task_fullpath(task), \
60750 + (task)->real_parent->comm, (task)->real_parent->pid, \
60751 + (pcred)->uid, (pcred)->euid, \
60752 + (pcred)->gid, (pcred)->egid
60753 +
60754 +#define GR_CHROOT_CAPS {{ \
60755 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60756 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60757 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60758 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60759 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60760 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60761 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60762 +
60763 +#define security_learn(normal_msg,args...) \
60764 +({ \
60765 + read_lock(&grsec_exec_file_lock); \
60766 + gr_add_learn_entry(normal_msg "\n", ## args); \
60767 + read_unlock(&grsec_exec_file_lock); \
60768 +})
60769 +
60770 +enum {
60771 + GR_DO_AUDIT,
60772 + GR_DONT_AUDIT,
60773 + /* used for non-audit messages that we shouldn't kill the task on */
60774 + GR_DONT_AUDIT_GOOD
60775 +};
60776 +
60777 +enum {
60778 + GR_TTYSNIFF,
60779 + GR_RBAC,
60780 + GR_RBAC_STR,
60781 + GR_STR_RBAC,
60782 + GR_RBAC_MODE2,
60783 + GR_RBAC_MODE3,
60784 + GR_FILENAME,
60785 + GR_SYSCTL_HIDDEN,
60786 + GR_NOARGS,
60787 + GR_ONE_INT,
60788 + GR_ONE_INT_TWO_STR,
60789 + GR_ONE_STR,
60790 + GR_STR_INT,
60791 + GR_TWO_STR_INT,
60792 + GR_TWO_INT,
60793 + GR_TWO_U64,
60794 + GR_THREE_INT,
60795 + GR_FIVE_INT_TWO_STR,
60796 + GR_TWO_STR,
60797 + GR_THREE_STR,
60798 + GR_FOUR_STR,
60799 + GR_STR_FILENAME,
60800 + GR_FILENAME_STR,
60801 + GR_FILENAME_TWO_INT,
60802 + GR_FILENAME_TWO_INT_STR,
60803 + GR_TEXTREL,
60804 + GR_PTRACE,
60805 + GR_RESOURCE,
60806 + GR_CAP,
60807 + GR_SIG,
60808 + GR_SIG2,
60809 + GR_CRASH1,
60810 + GR_CRASH2,
60811 + GR_PSACCT,
60812 + GR_RWXMAP
60813 +};
60814 +
60815 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60816 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60817 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60818 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60819 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60820 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60821 +#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)
60822 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60823 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60824 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60825 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60826 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60827 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60828 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60829 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60830 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60831 +#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)
60832 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60833 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60834 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60835 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60836 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60837 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60838 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60839 +#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)
60840 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60841 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60842 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60843 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60844 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60845 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60846 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60847 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60848 +#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)
60849 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60850 +
60851 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60852 +
60853 +#endif
60854 +
60855 +#endif
60856 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60857 new file mode 100644
60858 index 0000000..54f4e85
60859 --- /dev/null
60860 +++ b/include/linux/grmsg.h
60861 @@ -0,0 +1,110 @@
60862 +#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"
60863 +#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"
60864 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60865 +#define GR_STOPMOD_MSG "denied modification of module state by "
60866 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60867 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60868 +#define GR_IOPERM_MSG "denied use of ioperm() by "
60869 +#define GR_IOPL_MSG "denied use of iopl() by "
60870 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60871 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60872 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60873 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60874 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60875 +#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"
60876 +#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"
60877 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60878 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60879 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60880 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60881 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60882 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60883 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60884 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60885 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60886 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60887 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60888 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60889 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60890 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60891 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60892 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60893 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60894 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60895 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60896 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60897 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60898 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60899 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60900 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60901 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60902 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60903 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60904 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60905 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60906 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60907 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60908 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60909 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60910 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60911 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60912 +#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"
60913 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60914 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60915 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60916 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60917 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60918 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60919 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60920 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60921 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60922 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60923 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60924 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60925 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60926 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60927 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60928 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60929 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60930 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60931 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60932 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60933 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
60934 +#define GR_NICE_CHROOT_MSG "denied priority change by "
60935 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60936 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60937 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60938 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60939 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60940 +#define GR_TIME_MSG "time set by "
60941 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60942 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60943 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60944 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
60945 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
60946 +#define GR_BIND_MSG "denied bind() by "
60947 +#define GR_CONNECT_MSG "denied connect() by "
60948 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
60949 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
60950 +#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"
60951 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
60952 +#define GR_CAP_ACL_MSG "use of %s denied for "
60953 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
60954 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
60955 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
60956 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
60957 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
60958 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
60959 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
60960 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
60961 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
60962 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
60963 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
60964 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
60965 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
60966 +#define GR_VM86_MSG "denied use of vm86 by "
60967 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
60968 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
60969 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
60970 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
60971 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
60972 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
60973 new file mode 100644
60974 index 0000000..38bfb04
60975 --- /dev/null
60976 +++ b/include/linux/grsecurity.h
60977 @@ -0,0 +1,233 @@
60978 +#ifndef GR_SECURITY_H
60979 +#define GR_SECURITY_H
60980 +#include <linux/fs.h>
60981 +#include <linux/fs_struct.h>
60982 +#include <linux/binfmts.h>
60983 +#include <linux/gracl.h>
60984 +
60985 +/* notify of brain-dead configs */
60986 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60987 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
60988 +#endif
60989 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
60990 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
60991 +#endif
60992 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
60993 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
60994 +#endif
60995 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
60996 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
60997 +#endif
60998 +
60999 +#include <linux/compat.h>
61000 +
61001 +struct user_arg_ptr {
61002 +#ifdef CONFIG_COMPAT
61003 + bool is_compat;
61004 +#endif
61005 + union {
61006 + const char __user *const __user *native;
61007 +#ifdef CONFIG_COMPAT
61008 + compat_uptr_t __user *compat;
61009 +#endif
61010 + } ptr;
61011 +};
61012 +
61013 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61014 +void gr_handle_brute_check(void);
61015 +void gr_handle_kernel_exploit(void);
61016 +int gr_process_user_ban(void);
61017 +
61018 +char gr_roletype_to_char(void);
61019 +
61020 +int gr_acl_enable_at_secure(void);
61021 +
61022 +int gr_check_user_change(int real, int effective, int fs);
61023 +int gr_check_group_change(int real, int effective, int fs);
61024 +
61025 +void gr_del_task_from_ip_table(struct task_struct *p);
61026 +
61027 +int gr_pid_is_chrooted(struct task_struct *p);
61028 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61029 +int gr_handle_chroot_nice(void);
61030 +int gr_handle_chroot_sysctl(const int op);
61031 +int gr_handle_chroot_setpriority(struct task_struct *p,
61032 + const int niceval);
61033 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61034 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61035 + const struct vfsmount *mnt);
61036 +void gr_handle_chroot_chdir(struct path *path);
61037 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61038 + const struct vfsmount *mnt, const int mode);
61039 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61040 + const struct vfsmount *mnt, const int mode);
61041 +int gr_handle_chroot_mount(const struct dentry *dentry,
61042 + const struct vfsmount *mnt,
61043 + const char *dev_name);
61044 +int gr_handle_chroot_pivot(void);
61045 +int gr_handle_chroot_unix(const pid_t pid);
61046 +
61047 +int gr_handle_rawio(const struct inode *inode);
61048 +
61049 +void gr_handle_ioperm(void);
61050 +void gr_handle_iopl(void);
61051 +
61052 +umode_t gr_acl_umask(void);
61053 +
61054 +int gr_tpe_allow(const struct file *file);
61055 +
61056 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61057 +void gr_clear_chroot_entries(struct task_struct *task);
61058 +
61059 +void gr_log_forkfail(const int retval);
61060 +void gr_log_timechange(void);
61061 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61062 +void gr_log_chdir(const struct dentry *dentry,
61063 + const struct vfsmount *mnt);
61064 +void gr_log_chroot_exec(const struct dentry *dentry,
61065 + const struct vfsmount *mnt);
61066 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61067 +void gr_log_remount(const char *devname, const int retval);
61068 +void gr_log_unmount(const char *devname, const int retval);
61069 +void gr_log_mount(const char *from, const char *to, const int retval);
61070 +void gr_log_textrel(struct vm_area_struct *vma);
61071 +void gr_log_rwxmmap(struct file *file);
61072 +void gr_log_rwxmprotect(struct file *file);
61073 +
61074 +int gr_handle_follow_link(const struct inode *parent,
61075 + const struct inode *inode,
61076 + const struct dentry *dentry,
61077 + const struct vfsmount *mnt);
61078 +int gr_handle_fifo(const struct dentry *dentry,
61079 + const struct vfsmount *mnt,
61080 + const struct dentry *dir, const int flag,
61081 + const int acc_mode);
61082 +int gr_handle_hardlink(const struct dentry *dentry,
61083 + const struct vfsmount *mnt,
61084 + struct inode *inode,
61085 + const int mode, const char *to);
61086 +
61087 +int gr_is_capable(const int cap);
61088 +int gr_is_capable_nolog(const int cap);
61089 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61090 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61091 +
61092 +void gr_learn_resource(const struct task_struct *task, const int limit,
61093 + const unsigned long wanted, const int gt);
61094 +void gr_copy_label(struct task_struct *tsk);
61095 +void gr_handle_crash(struct task_struct *task, const int sig);
61096 +int gr_handle_signal(const struct task_struct *p, const int sig);
61097 +int gr_check_crash_uid(const uid_t uid);
61098 +int gr_check_protected_task(const struct task_struct *task);
61099 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61100 +int gr_acl_handle_mmap(const struct file *file,
61101 + const unsigned long prot);
61102 +int gr_acl_handle_mprotect(const struct file *file,
61103 + const unsigned long prot);
61104 +int gr_check_hidden_task(const struct task_struct *tsk);
61105 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61106 + const struct vfsmount *mnt);
61107 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61108 + const struct vfsmount *mnt);
61109 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61110 + const struct vfsmount *mnt, const int fmode);
61111 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61112 + const struct vfsmount *mnt, umode_t *mode);
61113 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61114 + const struct vfsmount *mnt);
61115 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61116 + const struct vfsmount *mnt);
61117 +int gr_handle_ptrace(struct task_struct *task, const long request);
61118 +int gr_handle_proc_ptrace(struct task_struct *task);
61119 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61120 + const struct vfsmount *mnt);
61121 +int gr_check_crash_exec(const struct file *filp);
61122 +int gr_acl_is_enabled(void);
61123 +void gr_set_kernel_label(struct task_struct *task);
61124 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61125 + const gid_t gid);
61126 +int gr_set_proc_label(const struct dentry *dentry,
61127 + const struct vfsmount *mnt,
61128 + const int unsafe_flags);
61129 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61130 + const struct vfsmount *mnt);
61131 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61132 + const struct vfsmount *mnt, int acc_mode);
61133 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61134 + const struct dentry *p_dentry,
61135 + const struct vfsmount *p_mnt,
61136 + int open_flags, int acc_mode, const int imode);
61137 +void gr_handle_create(const struct dentry *dentry,
61138 + const struct vfsmount *mnt);
61139 +void gr_handle_proc_create(const struct dentry *dentry,
61140 + const struct inode *inode);
61141 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61142 + const struct dentry *parent_dentry,
61143 + const struct vfsmount *parent_mnt,
61144 + const int mode);
61145 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61146 + const struct dentry *parent_dentry,
61147 + const struct vfsmount *parent_mnt);
61148 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61149 + const struct vfsmount *mnt);
61150 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61151 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61152 + const struct vfsmount *mnt);
61153 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61154 + const struct dentry *parent_dentry,
61155 + const struct vfsmount *parent_mnt,
61156 + const char *from);
61157 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61158 + const struct dentry *parent_dentry,
61159 + const struct vfsmount *parent_mnt,
61160 + const struct dentry *old_dentry,
61161 + const struct vfsmount *old_mnt, const char *to);
61162 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
61163 +int gr_acl_handle_rename(struct dentry *new_dentry,
61164 + struct dentry *parent_dentry,
61165 + const struct vfsmount *parent_mnt,
61166 + struct dentry *old_dentry,
61167 + struct inode *old_parent_inode,
61168 + struct vfsmount *old_mnt, const char *newname);
61169 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61170 + struct dentry *old_dentry,
61171 + struct dentry *new_dentry,
61172 + struct vfsmount *mnt, const __u8 replace);
61173 +__u32 gr_check_link(const struct dentry *new_dentry,
61174 + const struct dentry *parent_dentry,
61175 + const struct vfsmount *parent_mnt,
61176 + const struct dentry *old_dentry,
61177 + const struct vfsmount *old_mnt);
61178 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61179 + const unsigned int namelen, const ino_t ino);
61180 +
61181 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61182 + const struct vfsmount *mnt);
61183 +void gr_acl_handle_exit(void);
61184 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61185 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61186 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61187 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61188 +void gr_audit_ptrace(struct task_struct *task);
61189 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61190 +
61191 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61192 +
61193 +#ifdef CONFIG_GRKERNSEC
61194 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61195 +void gr_handle_vm86(void);
61196 +void gr_handle_mem_readwrite(u64 from, u64 to);
61197 +
61198 +void gr_log_badprocpid(const char *entry);
61199 +
61200 +extern int grsec_enable_dmesg;
61201 +extern int grsec_disable_privio;
61202 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61203 +extern int grsec_enable_chroot_findtask;
61204 +#endif
61205 +#ifdef CONFIG_GRKERNSEC_SETXID
61206 +extern int grsec_enable_setxid;
61207 +#endif
61208 +#endif
61209 +
61210 +#endif
61211 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61212 new file mode 100644
61213 index 0000000..e7ffaaf
61214 --- /dev/null
61215 +++ b/include/linux/grsock.h
61216 @@ -0,0 +1,19 @@
61217 +#ifndef __GRSOCK_H
61218 +#define __GRSOCK_H
61219 +
61220 +extern void gr_attach_curr_ip(const struct sock *sk);
61221 +extern int gr_handle_sock_all(const int family, const int type,
61222 + const int protocol);
61223 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61224 +extern int gr_handle_sock_server_other(const struct sock *sck);
61225 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61226 +extern int gr_search_connect(struct socket * sock,
61227 + struct sockaddr_in * addr);
61228 +extern int gr_search_bind(struct socket * sock,
61229 + struct sockaddr_in * addr);
61230 +extern int gr_search_listen(struct socket * sock);
61231 +extern int gr_search_accept(struct socket * sock);
61232 +extern int gr_search_socket(const int domain, const int type,
61233 + const int protocol);
61234 +
61235 +#endif
61236 diff --git a/include/linux/hid.h b/include/linux/hid.h
61237 index 3a95da6..51986f1 100644
61238 --- a/include/linux/hid.h
61239 +++ b/include/linux/hid.h
61240 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61241 unsigned int code, int value);
61242
61243 int (*parse)(struct hid_device *hdev);
61244 -};
61245 +} __no_const;
61246
61247 #define PM_HINT_FULLON 1<<5
61248 #define PM_HINT_NORMAL 1<<1
61249 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61250 index d3999b4..1304cb4 100644
61251 --- a/include/linux/highmem.h
61252 +++ b/include/linux/highmem.h
61253 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61254 kunmap_atomic(kaddr);
61255 }
61256
61257 +static inline void sanitize_highpage(struct page *page)
61258 +{
61259 + void *kaddr;
61260 + unsigned long flags;
61261 +
61262 + local_irq_save(flags);
61263 + kaddr = kmap_atomic(page);
61264 + clear_page(kaddr);
61265 + kunmap_atomic(kaddr);
61266 + local_irq_restore(flags);
61267 +}
61268 +
61269 static inline void zero_user_segments(struct page *page,
61270 unsigned start1, unsigned end1,
61271 unsigned start2, unsigned end2)
61272 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61273 index 195d8b3..e20cfab 100644
61274 --- a/include/linux/i2c.h
61275 +++ b/include/linux/i2c.h
61276 @@ -365,6 +365,7 @@ struct i2c_algorithm {
61277 /* To determine what the adapter supports */
61278 u32 (*functionality) (struct i2c_adapter *);
61279 };
61280 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61281
61282 /*
61283 * i2c_adapter is the structure used to identify a physical i2c bus along
61284 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61285 index d23c3c2..eb63c81 100644
61286 --- a/include/linux/i2o.h
61287 +++ b/include/linux/i2o.h
61288 @@ -565,7 +565,7 @@ struct i2o_controller {
61289 struct i2o_device *exec; /* Executive */
61290 #if BITS_PER_LONG == 64
61291 spinlock_t context_list_lock; /* lock for context_list */
61292 - atomic_t context_list_counter; /* needed for unique contexts */
61293 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61294 struct list_head context_list; /* list of context id's
61295 and pointers */
61296 #endif
61297 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61298 index 58404b0..439ed95 100644
61299 --- a/include/linux/if_team.h
61300 +++ b/include/linux/if_team.h
61301 @@ -64,6 +64,7 @@ struct team_mode_ops {
61302 void (*port_leave)(struct team *team, struct team_port *port);
61303 void (*port_change_mac)(struct team *team, struct team_port *port);
61304 };
61305 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61306
61307 enum team_option_type {
61308 TEAM_OPTION_TYPE_U32,
61309 @@ -112,7 +113,7 @@ struct team {
61310 struct list_head option_list;
61311
61312 const struct team_mode *mode;
61313 - struct team_mode_ops ops;
61314 + team_mode_ops_no_const ops;
61315 long mode_priv[TEAM_MODE_PRIV_LONGS];
61316 };
61317
61318 diff --git a/include/linux/init.h b/include/linux/init.h
61319 index 6b95109..4aca62c 100644
61320 --- a/include/linux/init.h
61321 +++ b/include/linux/init.h
61322 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61323
61324 /* Each module must use one module_init(). */
61325 #define module_init(initfn) \
61326 - static inline initcall_t __inittest(void) \
61327 + static inline __used initcall_t __inittest(void) \
61328 { return initfn; } \
61329 int init_module(void) __attribute__((alias(#initfn)));
61330
61331 /* This is only required if you want to be unloadable. */
61332 #define module_exit(exitfn) \
61333 - static inline exitcall_t __exittest(void) \
61334 + static inline __used exitcall_t __exittest(void) \
61335 { return exitfn; } \
61336 void cleanup_module(void) __attribute__((alias(#exitfn)));
61337
61338 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61339 index e4baff5..83bb175 100644
61340 --- a/include/linux/init_task.h
61341 +++ b/include/linux/init_task.h
61342 @@ -134,6 +134,12 @@ extern struct cred init_cred;
61343
61344 #define INIT_TASK_COMM "swapper"
61345
61346 +#ifdef CONFIG_X86
61347 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61348 +#else
61349 +#define INIT_TASK_THREAD_INFO
61350 +#endif
61351 +
61352 /*
61353 * INIT_TASK is used to set up the first task table, touch at
61354 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61355 @@ -172,6 +178,7 @@ extern struct cred init_cred;
61356 RCU_INIT_POINTER(.cred, &init_cred), \
61357 .comm = INIT_TASK_COMM, \
61358 .thread = INIT_THREAD, \
61359 + INIT_TASK_THREAD_INFO \
61360 .fs = &init_fs, \
61361 .files = &init_files, \
61362 .signal = &init_signals, \
61363 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61364 index e6ca56d..8583707 100644
61365 --- a/include/linux/intel-iommu.h
61366 +++ b/include/linux/intel-iommu.h
61367 @@ -296,7 +296,7 @@ struct iommu_flush {
61368 u8 fm, u64 type);
61369 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61370 unsigned int size_order, u64 type);
61371 -};
61372 +} __no_const;
61373
61374 enum {
61375 SR_DMAR_FECTL_REG,
61376 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61377 index 2aea5d2..0b82f0c 100644
61378 --- a/include/linux/interrupt.h
61379 +++ b/include/linux/interrupt.h
61380 @@ -439,7 +439,7 @@ enum
61381 /* map softirq index to softirq name. update 'softirq_to_name' in
61382 * kernel/softirq.c when adding a new softirq.
61383 */
61384 -extern char *softirq_to_name[NR_SOFTIRQS];
61385 +extern const char * const softirq_to_name[NR_SOFTIRQS];
61386
61387 /* softirq mask and active fields moved to irq_cpustat_t in
61388 * asm/hardirq.h to get better cache usage. KAO
61389 @@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61390
61391 struct softirq_action
61392 {
61393 - void (*action)(struct softirq_action *);
61394 + void (*action)(void);
61395 };
61396
61397 asmlinkage void do_softirq(void);
61398 asmlinkage void __do_softirq(void);
61399 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61400 +extern void open_softirq(int nr, void (*action)(void));
61401 extern void softirq_init(void);
61402 extern void __raise_softirq_irqoff(unsigned int nr);
61403
61404 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61405 index 3875719..4cd454c 100644
61406 --- a/include/linux/kallsyms.h
61407 +++ b/include/linux/kallsyms.h
61408 @@ -15,7 +15,8 @@
61409
61410 struct module;
61411
61412 -#ifdef CONFIG_KALLSYMS
61413 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61414 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61415 /* Lookup the address for a symbol. Returns 0 if not found. */
61416 unsigned long kallsyms_lookup_name(const char *name);
61417
61418 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61419 /* Stupid that this does nothing, but I didn't create this mess. */
61420 #define __print_symbol(fmt, addr)
61421 #endif /*CONFIG_KALLSYMS*/
61422 +#else /* when included by kallsyms.c, vsnprintf.c, or
61423 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61424 +extern void __print_symbol(const char *fmt, unsigned long address);
61425 +extern int sprint_backtrace(char *buffer, unsigned long address);
61426 +extern int sprint_symbol(char *buffer, unsigned long address);
61427 +const char *kallsyms_lookup(unsigned long addr,
61428 + unsigned long *symbolsize,
61429 + unsigned long *offset,
61430 + char **modname, char *namebuf);
61431 +#endif
61432
61433 /* This macro allows us to keep printk typechecking */
61434 static __printf(1, 2)
61435 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61436 index c4d2fc1..5df9c19 100644
61437 --- a/include/linux/kgdb.h
61438 +++ b/include/linux/kgdb.h
61439 @@ -53,7 +53,7 @@ extern int kgdb_connected;
61440 extern int kgdb_io_module_registered;
61441
61442 extern atomic_t kgdb_setting_breakpoint;
61443 -extern atomic_t kgdb_cpu_doing_single_step;
61444 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61445
61446 extern struct task_struct *kgdb_usethread;
61447 extern struct task_struct *kgdb_contthread;
61448 @@ -252,7 +252,7 @@ struct kgdb_arch {
61449 void (*disable_hw_break)(struct pt_regs *regs);
61450 void (*remove_all_hw_break)(void);
61451 void (*correct_hw_break)(void);
61452 -};
61453 +} __do_const;
61454
61455 /**
61456 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61457 @@ -277,7 +277,7 @@ struct kgdb_io {
61458 void (*pre_exception) (void);
61459 void (*post_exception) (void);
61460 int is_console;
61461 -};
61462 +} __do_const;
61463
61464 extern struct kgdb_arch arch_kgdb_ops;
61465
61466 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61467 index dd99c32..da06047 100644
61468 --- a/include/linux/kmod.h
61469 +++ b/include/linux/kmod.h
61470 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61471 * usually useless though. */
61472 extern __printf(2, 3)
61473 int __request_module(bool wait, const char *name, ...);
61474 +extern __printf(3, 4)
61475 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61476 #define request_module(mod...) __request_module(true, mod)
61477 #define request_module_nowait(mod...) __request_module(false, mod)
61478 #define try_then_request_module(x, mod...) \
61479 diff --git a/include/linux/kref.h b/include/linux/kref.h
61480 index 9c07dce..a92fa71 100644
61481 --- a/include/linux/kref.h
61482 +++ b/include/linux/kref.h
61483 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61484 static inline int kref_sub(struct kref *kref, unsigned int count,
61485 void (*release)(struct kref *kref))
61486 {
61487 - WARN_ON(release == NULL);
61488 + BUG_ON(release == NULL);
61489
61490 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61491 release(kref);
61492 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61493 index 72cbf08..dd0201d 100644
61494 --- a/include/linux/kvm_host.h
61495 +++ b/include/linux/kvm_host.h
61496 @@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61497 void vcpu_load(struct kvm_vcpu *vcpu);
61498 void vcpu_put(struct kvm_vcpu *vcpu);
61499
61500 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61501 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61502 struct module *module);
61503 void kvm_exit(void);
61504
61505 @@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61506 struct kvm_guest_debug *dbg);
61507 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61508
61509 -int kvm_arch_init(void *opaque);
61510 +int kvm_arch_init(const void *opaque);
61511 void kvm_arch_exit(void);
61512
61513 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61514 diff --git a/include/linux/libata.h b/include/linux/libata.h
61515 index 6e887c7..4539601 100644
61516 --- a/include/linux/libata.h
61517 +++ b/include/linux/libata.h
61518 @@ -910,7 +910,7 @@ struct ata_port_operations {
61519 * fields must be pointers.
61520 */
61521 const struct ata_port_operations *inherits;
61522 -};
61523 +} __do_const;
61524
61525 struct ata_port_info {
61526 unsigned long flags;
61527 diff --git a/include/linux/mca.h b/include/linux/mca.h
61528 index 3797270..7765ede 100644
61529 --- a/include/linux/mca.h
61530 +++ b/include/linux/mca.h
61531 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61532 int region);
61533 void * (*mca_transform_memory)(struct mca_device *,
61534 void *memory);
61535 -};
61536 +} __no_const;
61537
61538 struct mca_bus {
61539 u64 default_dma_mask;
61540 diff --git a/include/linux/memory.h b/include/linux/memory.h
61541 index 1ac7f6e..a5794d0 100644
61542 --- a/include/linux/memory.h
61543 +++ b/include/linux/memory.h
61544 @@ -143,7 +143,7 @@ struct memory_accessor {
61545 size_t count);
61546 ssize_t (*write)(struct memory_accessor *, const char *buf,
61547 off_t offset, size_t count);
61548 -};
61549 +} __no_const;
61550
61551 /*
61552 * Kernel text modification mutex, used for code patching. Users of this lock
61553 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61554 index ee96cd5..7823c3a 100644
61555 --- a/include/linux/mfd/abx500.h
61556 +++ b/include/linux/mfd/abx500.h
61557 @@ -455,6 +455,7 @@ struct abx500_ops {
61558 int (*event_registers_startup_state_get) (struct device *, u8 *);
61559 int (*startup_irq_enabled) (struct device *, unsigned int);
61560 };
61561 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61562
61563 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61564 void abx500_remove_ops(struct device *dev);
61565 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
61566 index 9b07725..3d55001 100644
61567 --- a/include/linux/mfd/abx500/ux500_chargalg.h
61568 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
61569 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
61570 int (*enable) (struct ux500_charger *, int, int, int);
61571 int (*kick_wd) (struct ux500_charger *);
61572 int (*update_curr) (struct ux500_charger *, int);
61573 -};
61574 +} __no_const;
61575
61576 /**
61577 * struct ux500_charger - power supply ux500 charger sub class
61578 diff --git a/include/linux/mm.h b/include/linux/mm.h
61579 index 74aa71b..4ae97ba 100644
61580 --- a/include/linux/mm.h
61581 +++ b/include/linux/mm.h
61582 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
61583
61584 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61585 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61586 +
61587 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61588 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61589 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61590 +#else
61591 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61592 +#endif
61593 +
61594 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61595 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61596
61597 @@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
61598 int set_page_dirty_lock(struct page *page);
61599 int clear_page_dirty_for_io(struct page *page);
61600
61601 -/* Is the vma a continuation of the stack vma above it? */
61602 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61603 -{
61604 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61605 -}
61606 -
61607 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61608 - unsigned long addr)
61609 -{
61610 - return (vma->vm_flags & VM_GROWSDOWN) &&
61611 - (vma->vm_start == addr) &&
61612 - !vma_growsdown(vma->vm_prev, addr);
61613 -}
61614 -
61615 -/* Is the vma a continuation of the stack vma below it? */
61616 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61617 -{
61618 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61619 -}
61620 -
61621 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61622 - unsigned long addr)
61623 -{
61624 - return (vma->vm_flags & VM_GROWSUP) &&
61625 - (vma->vm_end == addr) &&
61626 - !vma_growsup(vma->vm_next, addr);
61627 -}
61628 -
61629 extern pid_t
61630 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
61631
61632 @@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
61633 }
61634 #endif
61635
61636 +#ifdef CONFIG_MMU
61637 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61638 +#else
61639 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61640 +{
61641 + return __pgprot(0);
61642 +}
61643 +#endif
61644 +
61645 int vma_wants_writenotify(struct vm_area_struct *vma);
61646
61647 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61648 @@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
61649 {
61650 return 0;
61651 }
61652 +
61653 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
61654 + unsigned long address)
61655 +{
61656 + return 0;
61657 +}
61658 #else
61659 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61660 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61661 #endif
61662
61663 #ifdef __PAGETABLE_PMD_FOLDED
61664 @@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
61665 {
61666 return 0;
61667 }
61668 +
61669 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
61670 + unsigned long address)
61671 +{
61672 + return 0;
61673 +}
61674 #else
61675 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
61676 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
61677 #endif
61678
61679 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
61680 @@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
61681 NULL: pud_offset(pgd, address);
61682 }
61683
61684 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
61685 +{
61686 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
61687 + NULL: pud_offset(pgd, address);
61688 +}
61689 +
61690 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
61691 {
61692 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
61693 NULL: pmd_offset(pud, address);
61694 }
61695 +
61696 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
61697 +{
61698 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
61699 + NULL: pmd_offset(pud, address);
61700 +}
61701 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
61702
61703 #if USE_SPLIT_PTLOCKS
61704 @@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
61705 unsigned long, unsigned long,
61706 unsigned long, unsigned long);
61707 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61708 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61709
61710 /* These take the mm semaphore themselves */
61711 extern unsigned long vm_brk(unsigned long, unsigned long);
61712 @@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61713 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61714 struct vm_area_struct **pprev);
61715
61716 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61717 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61718 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61719 +
61720 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61721 NULL if none. Assume start_addr < end_addr. */
61722 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61723 @@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61724 return vma;
61725 }
61726
61727 -#ifdef CONFIG_MMU
61728 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61729 -#else
61730 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61731 -{
61732 - return __pgprot(0);
61733 -}
61734 -#endif
61735 -
61736 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61737 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61738 unsigned long pfn, unsigned long size, pgprot_t);
61739 @@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
61740 extern int sysctl_memory_failure_early_kill;
61741 extern int sysctl_memory_failure_recovery;
61742 extern void shake_page(struct page *p, int access);
61743 -extern atomic_long_t mce_bad_pages;
61744 +extern atomic_long_unchecked_t mce_bad_pages;
61745 extern int soft_offline_page(struct page *page, int flags);
61746
61747 extern void dump_page(struct page *page);
61748 @@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61749 static inline bool page_is_guard(struct page *page) { return false; }
61750 #endif /* CONFIG_DEBUG_PAGEALLOC */
61751
61752 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61753 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61754 +#else
61755 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61756 +#endif
61757 +
61758 #endif /* __KERNEL__ */
61759 #endif /* _LINUX_MM_H */
61760 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61761 index b35752f..41075a0 100644
61762 --- a/include/linux/mm_types.h
61763 +++ b/include/linux/mm_types.h
61764 @@ -262,6 +262,8 @@ struct vm_area_struct {
61765 #ifdef CONFIG_NUMA
61766 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61767 #endif
61768 +
61769 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61770 };
61771
61772 struct core_thread {
61773 @@ -336,7 +338,7 @@ struct mm_struct {
61774 unsigned long def_flags;
61775 unsigned long nr_ptes; /* Page table pages */
61776 unsigned long start_code, end_code, start_data, end_data;
61777 - unsigned long start_brk, brk, start_stack;
61778 + unsigned long brk_gap, start_brk, brk, start_stack;
61779 unsigned long arg_start, arg_end, env_start, env_end;
61780
61781 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
61782 @@ -398,6 +400,24 @@ struct mm_struct {
61783 #ifdef CONFIG_CPUMASK_OFFSTACK
61784 struct cpumask cpumask_allocation;
61785 #endif
61786 +
61787 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
61788 + unsigned long pax_flags;
61789 +#endif
61790 +
61791 +#ifdef CONFIG_PAX_DLRESOLVE
61792 + unsigned long call_dl_resolve;
61793 +#endif
61794 +
61795 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61796 + unsigned long call_syscall;
61797 +#endif
61798 +
61799 +#ifdef CONFIG_PAX_ASLR
61800 + unsigned long delta_mmap; /* randomized offset */
61801 + unsigned long delta_stack; /* randomized offset */
61802 +#endif
61803 +
61804 };
61805
61806 static inline void mm_init_cpumask(struct mm_struct *mm)
61807 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61808 index 1d1b1e1..2a13c78 100644
61809 --- a/include/linux/mmu_notifier.h
61810 +++ b/include/linux/mmu_notifier.h
61811 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61812 */
61813 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61814 ({ \
61815 - pte_t __pte; \
61816 + pte_t ___pte; \
61817 struct vm_area_struct *___vma = __vma; \
61818 unsigned long ___address = __address; \
61819 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61820 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61821 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61822 - __pte; \
61823 + ___pte; \
61824 })
61825
61826 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61827 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61828 index 5f6806b..49db2b2 100644
61829 --- a/include/linux/mmzone.h
61830 +++ b/include/linux/mmzone.h
61831 @@ -380,7 +380,7 @@ struct zone {
61832 unsigned long flags; /* zone flags, see below */
61833
61834 /* Zone statistics */
61835 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61836 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61837
61838 /*
61839 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61840 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61841 index 501da4c..ba79bb4 100644
61842 --- a/include/linux/mod_devicetable.h
61843 +++ b/include/linux/mod_devicetable.h
61844 @@ -12,7 +12,7 @@
61845 typedef unsigned long kernel_ulong_t;
61846 #endif
61847
61848 -#define PCI_ANY_ID (~0)
61849 +#define PCI_ANY_ID ((__u16)~0)
61850
61851 struct pci_device_id {
61852 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61853 @@ -131,7 +131,7 @@ struct usb_device_id {
61854 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61855 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61856
61857 -#define HID_ANY_ID (~0)
61858 +#define HID_ANY_ID (~0U)
61859
61860 struct hid_device_id {
61861 __u16 bus;
61862 diff --git a/include/linux/module.h b/include/linux/module.h
61863 index fbcafe2..e5d9587 100644
61864 --- a/include/linux/module.h
61865 +++ b/include/linux/module.h
61866 @@ -17,6 +17,7 @@
61867 #include <linux/moduleparam.h>
61868 #include <linux/tracepoint.h>
61869 #include <linux/export.h>
61870 +#include <linux/fs.h>
61871
61872 #include <linux/percpu.h>
61873 #include <asm/module.h>
61874 @@ -273,19 +274,16 @@ struct module
61875 int (*init)(void);
61876
61877 /* If this is non-NULL, vfree after init() returns */
61878 - void *module_init;
61879 + void *module_init_rx, *module_init_rw;
61880
61881 /* Here is the actual code + data, vfree'd on unload. */
61882 - void *module_core;
61883 + void *module_core_rx, *module_core_rw;
61884
61885 /* Here are the sizes of the init and core sections */
61886 - unsigned int init_size, core_size;
61887 + unsigned int init_size_rw, core_size_rw;
61888
61889 /* The size of the executable code in each section. */
61890 - unsigned int init_text_size, core_text_size;
61891 -
61892 - /* Size of RO sections of the module (text+rodata) */
61893 - unsigned int init_ro_size, core_ro_size;
61894 + unsigned int init_size_rx, core_size_rx;
61895
61896 /* Arch-specific module values */
61897 struct mod_arch_specific arch;
61898 @@ -341,6 +339,10 @@ struct module
61899 #ifdef CONFIG_EVENT_TRACING
61900 struct ftrace_event_call **trace_events;
61901 unsigned int num_trace_events;
61902 + struct file_operations trace_id;
61903 + struct file_operations trace_enable;
61904 + struct file_operations trace_format;
61905 + struct file_operations trace_filter;
61906 #endif
61907 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61908 unsigned int num_ftrace_callsites;
61909 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
61910 bool is_module_percpu_address(unsigned long addr);
61911 bool is_module_text_address(unsigned long addr);
61912
61913 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61914 +{
61915 +
61916 +#ifdef CONFIG_PAX_KERNEXEC
61917 + if (ktla_ktva(addr) >= (unsigned long)start &&
61918 + ktla_ktva(addr) < (unsigned long)start + size)
61919 + return 1;
61920 +#endif
61921 +
61922 + return ((void *)addr >= start && (void *)addr < start + size);
61923 +}
61924 +
61925 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61926 +{
61927 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61928 +}
61929 +
61930 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61931 +{
61932 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61933 +}
61934 +
61935 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61936 +{
61937 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61938 +}
61939 +
61940 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61941 +{
61942 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61943 +}
61944 +
61945 static inline int within_module_core(unsigned long addr, struct module *mod)
61946 {
61947 - return (unsigned long)mod->module_core <= addr &&
61948 - addr < (unsigned long)mod->module_core + mod->core_size;
61949 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
61950 }
61951
61952 static inline int within_module_init(unsigned long addr, struct module *mod)
61953 {
61954 - return (unsigned long)mod->module_init <= addr &&
61955 - addr < (unsigned long)mod->module_init + mod->init_size;
61956 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
61957 }
61958
61959 /* Search for module by name: must hold module_mutex. */
61960 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
61961 index b2be02e..72d2f78 100644
61962 --- a/include/linux/moduleloader.h
61963 +++ b/include/linux/moduleloader.h
61964 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
61965
61966 /* Allocator used for allocating struct module, core sections and init
61967 sections. Returns NULL on failure. */
61968 -void *module_alloc(unsigned long size);
61969 +void *module_alloc(unsigned long size) __size_overflow(1);
61970 +
61971 +#ifdef CONFIG_PAX_KERNEXEC
61972 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
61973 +#else
61974 +#define module_alloc_exec(x) module_alloc(x)
61975 +#endif
61976
61977 /* Free memory returned from module_alloc. */
61978 void module_free(struct module *mod, void *module_region);
61979
61980 +#ifdef CONFIG_PAX_KERNEXEC
61981 +void module_free_exec(struct module *mod, void *module_region);
61982 +#else
61983 +#define module_free_exec(x, y) module_free((x), (y))
61984 +#endif
61985 +
61986 /* Apply the given relocation to the (simplified) ELF. Return -error
61987 or 0. */
61988 int apply_relocate(Elf_Shdr *sechdrs,
61989 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
61990 index 944bc18..042d291 100644
61991 --- a/include/linux/moduleparam.h
61992 +++ b/include/linux/moduleparam.h
61993 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
61994 * @len is usually just sizeof(string).
61995 */
61996 #define module_param_string(name, string, len, perm) \
61997 - static const struct kparam_string __param_string_##name \
61998 + static const struct kparam_string __param_string_##name __used \
61999 = { len, string }; \
62000 __module_param_call(MODULE_PARAM_PREFIX, name, \
62001 &param_ops_string, \
62002 @@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62003 */
62004 #define module_param_array_named(name, array, type, nump, perm) \
62005 param_check_##type(name, &(array)[0]); \
62006 - static const struct kparam_array __param_arr_##name \
62007 + static const struct kparam_array __param_arr_##name __used \
62008 = { .max = ARRAY_SIZE(array), .num = nump, \
62009 .ops = &param_ops_##type, \
62010 .elemsize = sizeof(array[0]), .elem = array }; \
62011 diff --git a/include/linux/namei.h b/include/linux/namei.h
62012 index ffc0213..2c1f2cb 100644
62013 --- a/include/linux/namei.h
62014 +++ b/include/linux/namei.h
62015 @@ -24,7 +24,7 @@ struct nameidata {
62016 unsigned seq;
62017 int last_type;
62018 unsigned depth;
62019 - char *saved_names[MAX_NESTED_LINKS + 1];
62020 + const char *saved_names[MAX_NESTED_LINKS + 1];
62021
62022 /* Intent data */
62023 union {
62024 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62025 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62026 extern void unlock_rename(struct dentry *, struct dentry *);
62027
62028 -static inline void nd_set_link(struct nameidata *nd, char *path)
62029 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62030 {
62031 nd->saved_names[nd->depth] = path;
62032 }
62033
62034 -static inline char *nd_get_link(struct nameidata *nd)
62035 +static inline const char *nd_get_link(const struct nameidata *nd)
62036 {
62037 return nd->saved_names[nd->depth];
62038 }
62039 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62040 index 33900a5..2072000 100644
62041 --- a/include/linux/netdevice.h
62042 +++ b/include/linux/netdevice.h
62043 @@ -1003,6 +1003,7 @@ struct net_device_ops {
62044 int (*ndo_neigh_construct)(struct neighbour *n);
62045 void (*ndo_neigh_destroy)(struct neighbour *n);
62046 };
62047 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62048
62049 /*
62050 * The DEVICE structure.
62051 @@ -1064,7 +1065,7 @@ struct net_device {
62052 int iflink;
62053
62054 struct net_device_stats stats;
62055 - atomic_long_t rx_dropped; /* dropped packets by core network
62056 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62057 * Do not use this in drivers.
62058 */
62059
62060 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62061 new file mode 100644
62062 index 0000000..33f4af8
62063 --- /dev/null
62064 +++ b/include/linux/netfilter/xt_gradm.h
62065 @@ -0,0 +1,9 @@
62066 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62067 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62068 +
62069 +struct xt_gradm_mtinfo {
62070 + __u16 flags;
62071 + __u16 invflags;
62072 +};
62073 +
62074 +#endif
62075 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62076 index c65a18a..0c05f3a 100644
62077 --- a/include/linux/of_pdt.h
62078 +++ b/include/linux/of_pdt.h
62079 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62080
62081 /* return 0 on success; fill in 'len' with number of bytes in path */
62082 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62083 -};
62084 +} __no_const;
62085
62086 extern void *prom_early_alloc(unsigned long size);
62087
62088 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62089 index a4c5624..79d6d88 100644
62090 --- a/include/linux/oprofile.h
62091 +++ b/include/linux/oprofile.h
62092 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62093 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62094 char const * name, ulong * val);
62095
62096 -/** Create a file for read-only access to an atomic_t. */
62097 +/** Create a file for read-only access to an atomic_unchecked_t. */
62098 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62099 - char const * name, atomic_t * val);
62100 + char const * name, atomic_unchecked_t * val);
62101
62102 /** create a directory */
62103 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62104 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62105 index ddbb6a9..be1680e 100644
62106 --- a/include/linux/perf_event.h
62107 +++ b/include/linux/perf_event.h
62108 @@ -879,8 +879,8 @@ struct perf_event {
62109
62110 enum perf_event_active_state state;
62111 unsigned int attach_state;
62112 - local64_t count;
62113 - atomic64_t child_count;
62114 + local64_t count; /* PaX: fix it one day */
62115 + atomic64_unchecked_t child_count;
62116
62117 /*
62118 * These are the total time in nanoseconds that the event
62119 @@ -931,8 +931,8 @@ struct perf_event {
62120 * These accumulate total time (in nanoseconds) that children
62121 * events have been enabled and running, respectively.
62122 */
62123 - atomic64_t child_total_time_enabled;
62124 - atomic64_t child_total_time_running;
62125 + atomic64_unchecked_t child_total_time_enabled;
62126 + atomic64_unchecked_t child_total_time_running;
62127
62128 /*
62129 * Protect attach/detach and child_list:
62130 diff --git a/include/linux/personality.h b/include/linux/personality.h
62131 index 8fc7dd1a..c19d89e 100644
62132 --- a/include/linux/personality.h
62133 +++ b/include/linux/personality.h
62134 @@ -44,6 +44,7 @@ enum {
62135 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62136 ADDR_NO_RANDOMIZE | \
62137 ADDR_COMPAT_LAYOUT | \
62138 + ADDR_LIMIT_3GB | \
62139 MMAP_PAGE_ZERO)
62140
62141 /*
62142 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62143 index e1ac1ce..0675fed 100644
62144 --- a/include/linux/pipe_fs_i.h
62145 +++ b/include/linux/pipe_fs_i.h
62146 @@ -45,9 +45,9 @@ struct pipe_buffer {
62147 struct pipe_inode_info {
62148 wait_queue_head_t wait;
62149 unsigned int nrbufs, curbuf, buffers;
62150 - unsigned int readers;
62151 - unsigned int writers;
62152 - unsigned int waiting_writers;
62153 + atomic_t readers;
62154 + atomic_t writers;
62155 + atomic_t waiting_writers;
62156 unsigned int r_counter;
62157 unsigned int w_counter;
62158 struct page *tmp_page;
62159 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62160 index 609daae..5392427 100644
62161 --- a/include/linux/pm_runtime.h
62162 +++ b/include/linux/pm_runtime.h
62163 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62164
62165 static inline void pm_runtime_mark_last_busy(struct device *dev)
62166 {
62167 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62168 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62169 }
62170
62171 #else /* !CONFIG_PM_RUNTIME */
62172 diff --git a/include/linux/poison.h b/include/linux/poison.h
62173 index 2110a81..13a11bb 100644
62174 --- a/include/linux/poison.h
62175 +++ b/include/linux/poison.h
62176 @@ -19,8 +19,8 @@
62177 * under normal circumstances, used to verify that nobody uses
62178 * non-initialized list entries.
62179 */
62180 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62181 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62182 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62183 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62184
62185 /********** include/linux/timer.h **********/
62186 /*
62187 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62188 index 5a710b9..0b0dab9 100644
62189 --- a/include/linux/preempt.h
62190 +++ b/include/linux/preempt.h
62191 @@ -126,7 +126,7 @@ struct preempt_ops {
62192 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62193 void (*sched_out)(struct preempt_notifier *notifier,
62194 struct task_struct *next);
62195 -};
62196 +} __no_const;
62197
62198 /**
62199 * preempt_notifier - key for installing preemption notifiers
62200 diff --git a/include/linux/printk.h b/include/linux/printk.h
62201 index 0525927..a5388b6 100644
62202 --- a/include/linux/printk.h
62203 +++ b/include/linux/printk.h
62204 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62205 extern int printk_needs_cpu(int cpu);
62206 extern void printk_tick(void);
62207
62208 +extern int kptr_restrict;
62209 +
62210 #ifdef CONFIG_PRINTK
62211 asmlinkage __printf(1, 0)
62212 int vprintk(const char *fmt, va_list args);
62213 @@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62214
62215 extern int printk_delay_msec;
62216 extern int dmesg_restrict;
62217 -extern int kptr_restrict;
62218
62219 void log_buf_kexec_setup(void);
62220 void __init setup_log_buf(int early);
62221 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62222 index 85c5073..51fac8b 100644
62223 --- a/include/linux/proc_fs.h
62224 +++ b/include/linux/proc_fs.h
62225 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62226 return proc_create_data(name, mode, parent, proc_fops, NULL);
62227 }
62228
62229 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62230 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62231 +{
62232 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62233 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62234 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62235 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62236 +#else
62237 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62238 +#endif
62239 +}
62240 +
62241 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62242 umode_t mode, struct proc_dir_entry *base,
62243 read_proc_t *read_proc, void * data)
62244 @@ -258,7 +270,7 @@ union proc_op {
62245 int (*proc_show)(struct seq_file *m,
62246 struct pid_namespace *ns, struct pid *pid,
62247 struct task_struct *task);
62248 -};
62249 +} __no_const;
62250
62251 struct ctl_table_header;
62252 struct ctl_table;
62253 diff --git a/include/linux/random.h b/include/linux/random.h
62254 index 8f74538..02a1012 100644
62255 --- a/include/linux/random.h
62256 +++ b/include/linux/random.h
62257 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62258
62259 u32 prandom32(struct rnd_state *);
62260
62261 +static inline unsigned long pax_get_random_long(void)
62262 +{
62263 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62264 +}
62265 +
62266 /*
62267 * Handle minimum values for seeds
62268 */
62269 static inline u32 __seed(u32 x, u32 m)
62270 {
62271 - return (x < m) ? x + m : x;
62272 + return (x <= m) ? x + m + 1 : x;
62273 }
62274
62275 /**
62276 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62277 index e0879a7..a12f962 100644
62278 --- a/include/linux/reboot.h
62279 +++ b/include/linux/reboot.h
62280 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62281 * Architecture-specific implementations of sys_reboot commands.
62282 */
62283
62284 -extern void machine_restart(char *cmd);
62285 -extern void machine_halt(void);
62286 -extern void machine_power_off(void);
62287 +extern void machine_restart(char *cmd) __noreturn;
62288 +extern void machine_halt(void) __noreturn;
62289 +extern void machine_power_off(void) __noreturn;
62290
62291 extern void machine_shutdown(void);
62292 struct pt_regs;
62293 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62294 */
62295
62296 extern void kernel_restart_prepare(char *cmd);
62297 -extern void kernel_restart(char *cmd);
62298 -extern void kernel_halt(void);
62299 -extern void kernel_power_off(void);
62300 +extern void kernel_restart(char *cmd) __noreturn;
62301 +extern void kernel_halt(void) __noreturn;
62302 +extern void kernel_power_off(void) __noreturn;
62303
62304 extern int C_A_D; /* for sysctl */
62305 void ctrl_alt_del(void);
62306 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62307 * Emergency restart, callable from an interrupt handler.
62308 */
62309
62310 -extern void emergency_restart(void);
62311 +extern void emergency_restart(void) __noreturn;
62312 #include <asm/emergency-restart.h>
62313
62314 #endif
62315 diff --git a/include/linux/relay.h b/include/linux/relay.h
62316 index 91cacc3..b55ff74 100644
62317 --- a/include/linux/relay.h
62318 +++ b/include/linux/relay.h
62319 @@ -160,7 +160,7 @@ struct rchan_callbacks
62320 * The callback should return 0 if successful, negative if not.
62321 */
62322 int (*remove_buf_file)(struct dentry *dentry);
62323 -};
62324 +} __no_const;
62325
62326 /*
62327 * CONFIG_RELAY kernel API, kernel/relay.c
62328 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62329 index 6fdf027..ff72610 100644
62330 --- a/include/linux/rfkill.h
62331 +++ b/include/linux/rfkill.h
62332 @@ -147,6 +147,7 @@ struct rfkill_ops {
62333 void (*query)(struct rfkill *rfkill, void *data);
62334 int (*set_block)(void *data, bool blocked);
62335 };
62336 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62337
62338 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62339 /**
62340 diff --git a/include/linux/rio.h b/include/linux/rio.h
62341 index 4d50611..c6858a2 100644
62342 --- a/include/linux/rio.h
62343 +++ b/include/linux/rio.h
62344 @@ -315,7 +315,7 @@ struct rio_ops {
62345 int mbox, void *buffer, size_t len);
62346 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62347 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62348 -};
62349 +} __no_const;
62350
62351 #define RIO_RESOURCE_MEM 0x00000100
62352 #define RIO_RESOURCE_DOORBELL 0x00000200
62353 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62354 index fd07c45..4676b8e 100644
62355 --- a/include/linux/rmap.h
62356 +++ b/include/linux/rmap.h
62357 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62358 void anon_vma_init(void); /* create anon_vma_cachep */
62359 int anon_vma_prepare(struct vm_area_struct *);
62360 void unlink_anon_vmas(struct vm_area_struct *);
62361 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62362 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62363 void anon_vma_moveto_tail(struct vm_area_struct *);
62364 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62365 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62366
62367 static inline void anon_vma_merge(struct vm_area_struct *vma,
62368 struct vm_area_struct *next)
62369 diff --git a/include/linux/sched.h b/include/linux/sched.h
62370 index 81a173c..85ccd8f 100644
62371 --- a/include/linux/sched.h
62372 +++ b/include/linux/sched.h
62373 @@ -100,6 +100,7 @@ struct bio_list;
62374 struct fs_struct;
62375 struct perf_event_context;
62376 struct blk_plug;
62377 +struct linux_binprm;
62378
62379 /*
62380 * List of flags we want to share for kernel threads,
62381 @@ -382,10 +383,13 @@ struct user_namespace;
62382 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62383
62384 extern int sysctl_max_map_count;
62385 +extern unsigned long sysctl_heap_stack_gap;
62386
62387 #include <linux/aio.h>
62388
62389 #ifdef CONFIG_MMU
62390 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62391 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62392 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62393 extern unsigned long
62394 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62395 @@ -643,6 +647,17 @@ struct signal_struct {
62396 #ifdef CONFIG_TASKSTATS
62397 struct taskstats *stats;
62398 #endif
62399 +
62400 +#ifdef CONFIG_GRKERNSEC
62401 + u32 curr_ip;
62402 + u32 saved_ip;
62403 + u32 gr_saddr;
62404 + u32 gr_daddr;
62405 + u16 gr_sport;
62406 + u16 gr_dport;
62407 + u8 used_accept:1;
62408 +#endif
62409 +
62410 #ifdef CONFIG_AUDIT
62411 unsigned audit_tty;
62412 struct tty_audit_buf *tty_audit_buf;
62413 @@ -726,6 +741,11 @@ struct user_struct {
62414 struct key *session_keyring; /* UID's default session keyring */
62415 #endif
62416
62417 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62418 + unsigned int banned;
62419 + unsigned long ban_expires;
62420 +#endif
62421 +
62422 /* Hash table maintenance information */
62423 struct hlist_node uidhash_node;
62424 uid_t uid;
62425 @@ -1386,8 +1406,8 @@ struct task_struct {
62426 struct list_head thread_group;
62427
62428 struct completion *vfork_done; /* for vfork() */
62429 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62430 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62431 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62432 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62433
62434 cputime_t utime, stime, utimescaled, stimescaled;
62435 cputime_t gtime;
62436 @@ -1403,13 +1423,6 @@ struct task_struct {
62437 struct task_cputime cputime_expires;
62438 struct list_head cpu_timers[3];
62439
62440 -/* process credentials */
62441 - const struct cred __rcu *real_cred; /* objective and real subjective task
62442 - * credentials (COW) */
62443 - const struct cred __rcu *cred; /* effective (overridable) subjective task
62444 - * credentials (COW) */
62445 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62446 -
62447 char comm[TASK_COMM_LEN]; /* executable name excluding path
62448 - access with [gs]et_task_comm (which lock
62449 it with task_lock())
62450 @@ -1426,8 +1439,16 @@ struct task_struct {
62451 #endif
62452 /* CPU-specific state of this task */
62453 struct thread_struct thread;
62454 +/* thread_info moved to task_struct */
62455 +#ifdef CONFIG_X86
62456 + struct thread_info tinfo;
62457 +#endif
62458 /* filesystem information */
62459 struct fs_struct *fs;
62460 +
62461 + const struct cred __rcu *cred; /* effective (overridable) subjective task
62462 + * credentials (COW) */
62463 +
62464 /* open file information */
62465 struct files_struct *files;
62466 /* namespaces */
62467 @@ -1469,6 +1490,11 @@ struct task_struct {
62468 struct rt_mutex_waiter *pi_blocked_on;
62469 #endif
62470
62471 +/* process credentials */
62472 + const struct cred __rcu *real_cred; /* objective and real subjective task
62473 + * credentials (COW) */
62474 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62475 +
62476 #ifdef CONFIG_DEBUG_MUTEXES
62477 /* mutex deadlock detection */
62478 struct mutex_waiter *blocked_on;
62479 @@ -1585,6 +1611,27 @@ struct task_struct {
62480 unsigned long default_timer_slack_ns;
62481
62482 struct list_head *scm_work_list;
62483 +
62484 +#ifdef CONFIG_GRKERNSEC
62485 + /* grsecurity */
62486 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62487 + u64 exec_id;
62488 +#endif
62489 +#ifdef CONFIG_GRKERNSEC_SETXID
62490 + const struct cred *delayed_cred;
62491 +#endif
62492 + struct dentry *gr_chroot_dentry;
62493 + struct acl_subject_label *acl;
62494 + struct acl_role_label *role;
62495 + struct file *exec_file;
62496 + u16 acl_role_id;
62497 + /* is this the task that authenticated to the special role */
62498 + u8 acl_sp_role;
62499 + u8 is_writable;
62500 + u8 brute;
62501 + u8 gr_is_chrooted;
62502 +#endif
62503 +
62504 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62505 /* Index of current stored address in ret_stack */
62506 int curr_ret_stack;
62507 @@ -1619,6 +1666,51 @@ struct task_struct {
62508 #endif
62509 };
62510
62511 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62512 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62513 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62514 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62515 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62516 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62517 +
62518 +#ifdef CONFIG_PAX_SOFTMODE
62519 +extern int pax_softmode;
62520 +#endif
62521 +
62522 +extern int pax_check_flags(unsigned long *);
62523 +
62524 +/* if tsk != current then task_lock must be held on it */
62525 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62526 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62527 +{
62528 + if (likely(tsk->mm))
62529 + return tsk->mm->pax_flags;
62530 + else
62531 + return 0UL;
62532 +}
62533 +
62534 +/* if tsk != current then task_lock must be held on it */
62535 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62536 +{
62537 + if (likely(tsk->mm)) {
62538 + tsk->mm->pax_flags = flags;
62539 + return 0;
62540 + }
62541 + return -EINVAL;
62542 +}
62543 +#endif
62544 +
62545 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62546 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62547 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62548 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62549 +#endif
62550 +
62551 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62552 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62553 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62554 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62555 +
62556 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62557 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62558
62559 @@ -2138,7 +2230,9 @@ void yield(void);
62560 extern struct exec_domain default_exec_domain;
62561
62562 union thread_union {
62563 +#ifndef CONFIG_X86
62564 struct thread_info thread_info;
62565 +#endif
62566 unsigned long stack[THREAD_SIZE/sizeof(long)];
62567 };
62568
62569 @@ -2171,6 +2265,7 @@ extern struct pid_namespace init_pid_ns;
62570 */
62571
62572 extern struct task_struct *find_task_by_vpid(pid_t nr);
62573 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62574 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62575 struct pid_namespace *ns);
62576
62577 @@ -2314,7 +2409,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62578 extern void exit_itimers(struct signal_struct *);
62579 extern void flush_itimer_signals(void);
62580
62581 -extern void do_group_exit(int);
62582 +extern __noreturn void do_group_exit(int);
62583
62584 extern void daemonize(const char *, ...);
62585 extern int allow_signal(int);
62586 @@ -2515,13 +2610,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62587
62588 #endif
62589
62590 -static inline int object_is_on_stack(void *obj)
62591 +static inline int object_starts_on_stack(void *obj)
62592 {
62593 - void *stack = task_stack_page(current);
62594 + const void *stack = task_stack_page(current);
62595
62596 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62597 }
62598
62599 +#ifdef CONFIG_PAX_USERCOPY
62600 +extern int object_is_on_stack(const void *obj, unsigned long len);
62601 +#endif
62602 +
62603 extern void thread_info_cache_init(void);
62604
62605 #ifdef CONFIG_DEBUG_STACK_USAGE
62606 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62607 index 899fbb4..1cb4138 100644
62608 --- a/include/linux/screen_info.h
62609 +++ b/include/linux/screen_info.h
62610 @@ -43,7 +43,8 @@ struct screen_info {
62611 __u16 pages; /* 0x32 */
62612 __u16 vesa_attributes; /* 0x34 */
62613 __u32 capabilities; /* 0x36 */
62614 - __u8 _reserved[6]; /* 0x3a */
62615 + __u16 vesapm_size; /* 0x3a */
62616 + __u8 _reserved[4]; /* 0x3c */
62617 } __attribute__((packed));
62618
62619 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62620 diff --git a/include/linux/security.h b/include/linux/security.h
62621 index 673afbb..2b7454b 100644
62622 --- a/include/linux/security.h
62623 +++ b/include/linux/security.h
62624 @@ -26,6 +26,7 @@
62625 #include <linux/capability.h>
62626 #include <linux/slab.h>
62627 #include <linux/err.h>
62628 +#include <linux/grsecurity.h>
62629
62630 struct linux_binprm;
62631 struct cred;
62632 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62633 index fc61854..d7c490b 100644
62634 --- a/include/linux/seq_file.h
62635 +++ b/include/linux/seq_file.h
62636 @@ -25,6 +25,9 @@ struct seq_file {
62637 struct mutex lock;
62638 const struct seq_operations *op;
62639 int poll_event;
62640 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62641 + u64 exec_id;
62642 +#endif
62643 void *private;
62644 };
62645
62646 @@ -34,6 +37,7 @@ struct seq_operations {
62647 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62648 int (*show) (struct seq_file *m, void *v);
62649 };
62650 +typedef struct seq_operations __no_const seq_operations_no_const;
62651
62652 #define SEQ_SKIP 1
62653
62654 diff --git a/include/linux/shm.h b/include/linux/shm.h
62655 index 92808b8..c28cac4 100644
62656 --- a/include/linux/shm.h
62657 +++ b/include/linux/shm.h
62658 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62659
62660 /* The task created the shm object. NULL if the task is dead. */
62661 struct task_struct *shm_creator;
62662 +#ifdef CONFIG_GRKERNSEC
62663 + time_t shm_createtime;
62664 + pid_t shm_lapid;
62665 +#endif
62666 };
62667
62668 /* shm_mode upper byte flags */
62669 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62670 index c1bae8d..2dbcd31 100644
62671 --- a/include/linux/skbuff.h
62672 +++ b/include/linux/skbuff.h
62673 @@ -663,7 +663,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62674 */
62675 static inline int skb_queue_empty(const struct sk_buff_head *list)
62676 {
62677 - return list->next == (struct sk_buff *)list;
62678 + return list->next == (const struct sk_buff *)list;
62679 }
62680
62681 /**
62682 @@ -676,7 +676,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62683 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62684 const struct sk_buff *skb)
62685 {
62686 - return skb->next == (struct sk_buff *)list;
62687 + return skb->next == (const struct sk_buff *)list;
62688 }
62689
62690 /**
62691 @@ -689,7 +689,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62692 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62693 const struct sk_buff *skb)
62694 {
62695 - return skb->prev == (struct sk_buff *)list;
62696 + return skb->prev == (const struct sk_buff *)list;
62697 }
62698
62699 /**
62700 @@ -1584,7 +1584,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62701 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62702 */
62703 #ifndef NET_SKB_PAD
62704 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62705 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62706 #endif
62707
62708 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62709 diff --git a/include/linux/slab.h b/include/linux/slab.h
62710 index a595dce..c403597 100644
62711 --- a/include/linux/slab.h
62712 +++ b/include/linux/slab.h
62713 @@ -11,12 +11,20 @@
62714
62715 #include <linux/gfp.h>
62716 #include <linux/types.h>
62717 +#include <linux/err.h>
62718
62719 /*
62720 * Flags to pass to kmem_cache_create().
62721 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62722 */
62723 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62724 +
62725 +#ifdef CONFIG_PAX_USERCOPY
62726 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62727 +#else
62728 +#define SLAB_USERCOPY 0x00000000UL
62729 +#endif
62730 +
62731 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62732 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62733 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62734 @@ -87,10 +95,13 @@
62735 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62736 * Both make kfree a no-op.
62737 */
62738 -#define ZERO_SIZE_PTR ((void *)16)
62739 +#define ZERO_SIZE_PTR \
62740 +({ \
62741 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62742 + (void *)(-MAX_ERRNO-1L); \
62743 +})
62744
62745 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62746 - (unsigned long)ZERO_SIZE_PTR)
62747 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62748
62749 /*
62750 * struct kmem_cache related prototypes
62751 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62752 void kfree(const void *);
62753 void kzfree(const void *);
62754 size_t ksize(const void *);
62755 +void check_object_size(const void *ptr, unsigned long n, bool to);
62756
62757 /*
62758 * Allocator specific definitions. These are mainly used to establish optimized
62759 @@ -240,6 +252,7 @@ size_t ksize(const void *);
62760 * for general use, and so are not documented here. For a full list of
62761 * potential flags, always refer to linux/gfp.h.
62762 */
62763 +static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
62764 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
62765 {
62766 if (size != 0 && n > ULONG_MAX / size)
62767 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
62768 */
62769 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62770 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62771 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62772 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
62773 #define kmalloc_track_caller(size, flags) \
62774 __kmalloc_track_caller(size, flags, _RET_IP_)
62775 #else
62776 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62777 */
62778 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62779 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62780 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
62781 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
62782 #define kmalloc_node_track_caller(size, flags, node) \
62783 __kmalloc_node_track_caller(size, flags, node, \
62784 _RET_IP_)
62785 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62786 index fbd1117..d4d8ef8 100644
62787 --- a/include/linux/slab_def.h
62788 +++ b/include/linux/slab_def.h
62789 @@ -66,10 +66,10 @@ struct kmem_cache {
62790 unsigned long node_allocs;
62791 unsigned long node_frees;
62792 unsigned long node_overflow;
62793 - atomic_t allochit;
62794 - atomic_t allocmiss;
62795 - atomic_t freehit;
62796 - atomic_t freemiss;
62797 + atomic_unchecked_t allochit;
62798 + atomic_unchecked_t allocmiss;
62799 + atomic_unchecked_t freehit;
62800 + atomic_unchecked_t freemiss;
62801
62802 /*
62803 * If debugging is enabled, then the allocator can add additional
62804 @@ -107,7 +107,7 @@ struct cache_sizes {
62805 extern struct cache_sizes malloc_sizes[];
62806
62807 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62808 -void *__kmalloc(size_t size, gfp_t flags);
62809 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62810
62811 #ifdef CONFIG_TRACING
62812 extern void *kmem_cache_alloc_trace(size_t size,
62813 @@ -160,7 +160,7 @@ found:
62814 }
62815
62816 #ifdef CONFIG_NUMA
62817 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
62818 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62819 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62820
62821 #ifdef CONFIG_TRACING
62822 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
62823 index 0ec00b3..39cb7fc 100644
62824 --- a/include/linux/slob_def.h
62825 +++ b/include/linux/slob_def.h
62826 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
62827 return kmem_cache_alloc_node(cachep, flags, -1);
62828 }
62829
62830 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
62831 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62832
62833 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
62834 {
62835 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62836 return __kmalloc_node(size, flags, -1);
62837 }
62838
62839 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62840 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
62841 {
62842 return kmalloc(size, flags);
62843 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62844 index c2f8c8b..be9e036 100644
62845 --- a/include/linux/slub_def.h
62846 +++ b/include/linux/slub_def.h
62847 @@ -92,7 +92,7 @@ struct kmem_cache {
62848 struct kmem_cache_order_objects max;
62849 struct kmem_cache_order_objects min;
62850 gfp_t allocflags; /* gfp flags to use on each alloc */
62851 - int refcount; /* Refcount for slab cache destroy */
62852 + atomic_t refcount; /* Refcount for slab cache destroy */
62853 void (*ctor)(void *);
62854 int inuse; /* Offset to metadata */
62855 int align; /* Alignment */
62856 @@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
62857 * Sorry that the following has to be that ugly but some versions of GCC
62858 * have trouble with constant propagation and loops.
62859 */
62860 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
62861 static __always_inline int kmalloc_index(size_t size)
62862 {
62863 if (!size)
62864 @@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62865 }
62866
62867 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62868 -void *__kmalloc(size_t size, gfp_t flags);
62869 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
62870
62871 static __always_inline void *
62872 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62873 @@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
62874 }
62875 #endif
62876
62877 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
62878 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
62879 {
62880 unsigned int order = get_order(size);
62881 @@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62882 }
62883
62884 #ifdef CONFIG_NUMA
62885 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
62886 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62887 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62888
62889 #ifdef CONFIG_TRACING
62890 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62891 index de8832d..0147b46 100644
62892 --- a/include/linux/sonet.h
62893 +++ b/include/linux/sonet.h
62894 @@ -61,7 +61,7 @@ struct sonet_stats {
62895 #include <linux/atomic.h>
62896
62897 struct k_sonet_stats {
62898 -#define __HANDLE_ITEM(i) atomic_t i
62899 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62900 __SONET_ITEMS
62901 #undef __HANDLE_ITEM
62902 };
62903 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62904 index 523547e..2cb7140 100644
62905 --- a/include/linux/sunrpc/clnt.h
62906 +++ b/include/linux/sunrpc/clnt.h
62907 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62908 {
62909 switch (sap->sa_family) {
62910 case AF_INET:
62911 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
62912 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62913 case AF_INET6:
62914 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62915 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62916 }
62917 return 0;
62918 }
62919 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62920 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62921 const struct sockaddr *src)
62922 {
62923 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62924 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62925 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62926
62927 dsin->sin_family = ssin->sin_family;
62928 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62929 if (sa->sa_family != AF_INET6)
62930 return 0;
62931
62932 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62933 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62934 }
62935
62936 #endif /* __KERNEL__ */
62937 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62938 index dc0c3cc..8503fb6 100644
62939 --- a/include/linux/sunrpc/sched.h
62940 +++ b/include/linux/sunrpc/sched.h
62941 @@ -106,6 +106,7 @@ struct rpc_call_ops {
62942 void (*rpc_count_stats)(struct rpc_task *, void *);
62943 void (*rpc_release)(void *);
62944 };
62945 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
62946
62947 struct rpc_task_setup {
62948 struct rpc_task *task;
62949 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
62950 index 0b8e3e6..33e0a01 100644
62951 --- a/include/linux/sunrpc/svc_rdma.h
62952 +++ b/include/linux/sunrpc/svc_rdma.h
62953 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
62954 extern unsigned int svcrdma_max_requests;
62955 extern unsigned int svcrdma_max_req_size;
62956
62957 -extern atomic_t rdma_stat_recv;
62958 -extern atomic_t rdma_stat_read;
62959 -extern atomic_t rdma_stat_write;
62960 -extern atomic_t rdma_stat_sq_starve;
62961 -extern atomic_t rdma_stat_rq_starve;
62962 -extern atomic_t rdma_stat_rq_poll;
62963 -extern atomic_t rdma_stat_rq_prod;
62964 -extern atomic_t rdma_stat_sq_poll;
62965 -extern atomic_t rdma_stat_sq_prod;
62966 +extern atomic_unchecked_t rdma_stat_recv;
62967 +extern atomic_unchecked_t rdma_stat_read;
62968 +extern atomic_unchecked_t rdma_stat_write;
62969 +extern atomic_unchecked_t rdma_stat_sq_starve;
62970 +extern atomic_unchecked_t rdma_stat_rq_starve;
62971 +extern atomic_unchecked_t rdma_stat_rq_poll;
62972 +extern atomic_unchecked_t rdma_stat_rq_prod;
62973 +extern atomic_unchecked_t rdma_stat_sq_poll;
62974 +extern atomic_unchecked_t rdma_stat_sq_prod;
62975
62976 #define RPCRDMA_VERSION 1
62977
62978 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
62979 index c34b4c8..a65b67d 100644
62980 --- a/include/linux/sysctl.h
62981 +++ b/include/linux/sysctl.h
62982 @@ -155,7 +155,11 @@ enum
62983 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
62984 };
62985
62986 -
62987 +#ifdef CONFIG_PAX_SOFTMODE
62988 +enum {
62989 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
62990 +};
62991 +#endif
62992
62993 /* CTL_VM names: */
62994 enum
62995 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
62996
62997 extern int proc_dostring(struct ctl_table *, int,
62998 void __user *, size_t *, loff_t *);
62999 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63000 + void __user *, size_t *, loff_t *);
63001 extern int proc_dointvec(struct ctl_table *, int,
63002 void __user *, size_t *, loff_t *);
63003 extern int proc_dointvec_minmax(struct ctl_table *, int,
63004 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63005 index ff7dc08..893e1bd 100644
63006 --- a/include/linux/tty_ldisc.h
63007 +++ b/include/linux/tty_ldisc.h
63008 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63009
63010 struct module *owner;
63011
63012 - int refcount;
63013 + atomic_t refcount;
63014 };
63015
63016 struct tty_ldisc {
63017 diff --git a/include/linux/types.h b/include/linux/types.h
63018 index 7f480db..175c256 100644
63019 --- a/include/linux/types.h
63020 +++ b/include/linux/types.h
63021 @@ -220,10 +220,26 @@ typedef struct {
63022 int counter;
63023 } atomic_t;
63024
63025 +#ifdef CONFIG_PAX_REFCOUNT
63026 +typedef struct {
63027 + int counter;
63028 +} atomic_unchecked_t;
63029 +#else
63030 +typedef atomic_t atomic_unchecked_t;
63031 +#endif
63032 +
63033 #ifdef CONFIG_64BIT
63034 typedef struct {
63035 long counter;
63036 } atomic64_t;
63037 +
63038 +#ifdef CONFIG_PAX_REFCOUNT
63039 +typedef struct {
63040 + long counter;
63041 +} atomic64_unchecked_t;
63042 +#else
63043 +typedef atomic64_t atomic64_unchecked_t;
63044 +#endif
63045 #endif
63046
63047 struct list_head {
63048 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63049 index 5ca0951..ab496a5 100644
63050 --- a/include/linux/uaccess.h
63051 +++ b/include/linux/uaccess.h
63052 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63053 long ret; \
63054 mm_segment_t old_fs = get_fs(); \
63055 \
63056 - set_fs(KERNEL_DS); \
63057 pagefault_disable(); \
63058 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63059 - pagefault_enable(); \
63060 + set_fs(KERNEL_DS); \
63061 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63062 set_fs(old_fs); \
63063 + pagefault_enable(); \
63064 ret; \
63065 })
63066
63067 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63068 index 99c1b4d..bb94261 100644
63069 --- a/include/linux/unaligned/access_ok.h
63070 +++ b/include/linux/unaligned/access_ok.h
63071 @@ -6,32 +6,32 @@
63072
63073 static inline u16 get_unaligned_le16(const void *p)
63074 {
63075 - return le16_to_cpup((__le16 *)p);
63076 + return le16_to_cpup((const __le16 *)p);
63077 }
63078
63079 static inline u32 get_unaligned_le32(const void *p)
63080 {
63081 - return le32_to_cpup((__le32 *)p);
63082 + return le32_to_cpup((const __le32 *)p);
63083 }
63084
63085 static inline u64 get_unaligned_le64(const void *p)
63086 {
63087 - return le64_to_cpup((__le64 *)p);
63088 + return le64_to_cpup((const __le64 *)p);
63089 }
63090
63091 static inline u16 get_unaligned_be16(const void *p)
63092 {
63093 - return be16_to_cpup((__be16 *)p);
63094 + return be16_to_cpup((const __be16 *)p);
63095 }
63096
63097 static inline u32 get_unaligned_be32(const void *p)
63098 {
63099 - return be32_to_cpup((__be32 *)p);
63100 + return be32_to_cpup((const __be32 *)p);
63101 }
63102
63103 static inline u64 get_unaligned_be64(const void *p)
63104 {
63105 - return be64_to_cpup((__be64 *)p);
63106 + return be64_to_cpup((const __be64 *)p);
63107 }
63108
63109 static inline void put_unaligned_le16(u16 val, void *p)
63110 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63111 index 547e59c..db6ad19 100644
63112 --- a/include/linux/usb/renesas_usbhs.h
63113 +++ b/include/linux/usb/renesas_usbhs.h
63114 @@ -39,7 +39,7 @@ enum {
63115 */
63116 struct renesas_usbhs_driver_callback {
63117 int (*notify_hotplug)(struct platform_device *pdev);
63118 -};
63119 +} __no_const;
63120
63121 /*
63122 * callback functions for platform
63123 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63124 * VBUS control is needed for Host
63125 */
63126 int (*set_vbus)(struct platform_device *pdev, int enable);
63127 -};
63128 +} __no_const;
63129
63130 /*
63131 * parameters for renesas usbhs
63132 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63133 index 6f8fbcf..8259001 100644
63134 --- a/include/linux/vermagic.h
63135 +++ b/include/linux/vermagic.h
63136 @@ -25,9 +25,35 @@
63137 #define MODULE_ARCH_VERMAGIC ""
63138 #endif
63139
63140 +#ifdef CONFIG_PAX_REFCOUNT
63141 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63142 +#else
63143 +#define MODULE_PAX_REFCOUNT ""
63144 +#endif
63145 +
63146 +#ifdef CONSTIFY_PLUGIN
63147 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63148 +#else
63149 +#define MODULE_CONSTIFY_PLUGIN ""
63150 +#endif
63151 +
63152 +#ifdef STACKLEAK_PLUGIN
63153 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63154 +#else
63155 +#define MODULE_STACKLEAK_PLUGIN ""
63156 +#endif
63157 +
63158 +#ifdef CONFIG_GRKERNSEC
63159 +#define MODULE_GRSEC "GRSEC "
63160 +#else
63161 +#define MODULE_GRSEC ""
63162 +#endif
63163 +
63164 #define VERMAGIC_STRING \
63165 UTS_RELEASE " " \
63166 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63167 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63168 - MODULE_ARCH_VERMAGIC
63169 + MODULE_ARCH_VERMAGIC \
63170 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63171 + MODULE_GRSEC
63172
63173 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63174 index dcdfc2b..ec79ab5 100644
63175 --- a/include/linux/vmalloc.h
63176 +++ b/include/linux/vmalloc.h
63177 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63178 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63179 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63180 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63181 +
63182 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63183 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63184 +#endif
63185 +
63186 /* bits [20..32] reserved for arch specific ioremap internals */
63187
63188 /*
63189 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63190 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63191 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63192 unsigned long start, unsigned long end, gfp_t gfp_mask,
63193 - pgprot_t prot, int node, void *caller);
63194 + pgprot_t prot, int node, void *caller) __size_overflow(1);
63195 extern void vfree(const void *addr);
63196
63197 extern void *vmap(struct page **pages, unsigned int count,
63198 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63199 extern void free_vm_area(struct vm_struct *area);
63200
63201 /* for /dev/kmem */
63202 -extern long vread(char *buf, char *addr, unsigned long count);
63203 -extern long vwrite(char *buf, char *addr, unsigned long count);
63204 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63205 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63206
63207 /*
63208 * Internals. Dont't use..
63209 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63210 index 65efb92..137adbb 100644
63211 --- a/include/linux/vmstat.h
63212 +++ b/include/linux/vmstat.h
63213 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63214 /*
63215 * Zone based page accounting with per cpu differentials.
63216 */
63217 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63218 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63219
63220 static inline void zone_page_state_add(long x, struct zone *zone,
63221 enum zone_stat_item item)
63222 {
63223 - atomic_long_add(x, &zone->vm_stat[item]);
63224 - atomic_long_add(x, &vm_stat[item]);
63225 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63226 + atomic_long_add_unchecked(x, &vm_stat[item]);
63227 }
63228
63229 static inline unsigned long global_page_state(enum zone_stat_item item)
63230 {
63231 - long x = atomic_long_read(&vm_stat[item]);
63232 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63233 #ifdef CONFIG_SMP
63234 if (x < 0)
63235 x = 0;
63236 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63237 static inline unsigned long zone_page_state(struct zone *zone,
63238 enum zone_stat_item item)
63239 {
63240 - long x = atomic_long_read(&zone->vm_stat[item]);
63241 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63242 #ifdef CONFIG_SMP
63243 if (x < 0)
63244 x = 0;
63245 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63246 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63247 enum zone_stat_item item)
63248 {
63249 - long x = atomic_long_read(&zone->vm_stat[item]);
63250 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63251
63252 #ifdef CONFIG_SMP
63253 int cpu;
63254 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63255
63256 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63257 {
63258 - atomic_long_inc(&zone->vm_stat[item]);
63259 - atomic_long_inc(&vm_stat[item]);
63260 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
63261 + atomic_long_inc_unchecked(&vm_stat[item]);
63262 }
63263
63264 static inline void __inc_zone_page_state(struct page *page,
63265 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63266
63267 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63268 {
63269 - atomic_long_dec(&zone->vm_stat[item]);
63270 - atomic_long_dec(&vm_stat[item]);
63271 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
63272 + atomic_long_dec_unchecked(&vm_stat[item]);
63273 }
63274
63275 static inline void __dec_zone_page_state(struct page *page,
63276 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63277 index e5d1220..ef6e406 100644
63278 --- a/include/linux/xattr.h
63279 +++ b/include/linux/xattr.h
63280 @@ -57,6 +57,11 @@
63281 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63282 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63283
63284 +/* User namespace */
63285 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63286 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
63287 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63288 +
63289 #ifdef __KERNEL__
63290
63291 #include <linux/types.h>
63292 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63293 index 4aeff96..b378cdc 100644
63294 --- a/include/media/saa7146_vv.h
63295 +++ b/include/media/saa7146_vv.h
63296 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
63297 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63298
63299 /* the extension can override this */
63300 - struct v4l2_ioctl_ops ops;
63301 + v4l2_ioctl_ops_no_const ops;
63302 /* pointer to the saa7146 core ops */
63303 const struct v4l2_ioctl_ops *core_ops;
63304
63305 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63306 index 96d2221..2292f89 100644
63307 --- a/include/media/v4l2-dev.h
63308 +++ b/include/media/v4l2-dev.h
63309 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63310
63311
63312 struct v4l2_file_operations {
63313 - struct module *owner;
63314 + struct module * const owner;
63315 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63316 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63317 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63318 @@ -71,6 +71,7 @@ struct v4l2_file_operations {
63319 int (*open) (struct file *);
63320 int (*release) (struct file *);
63321 };
63322 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63323
63324 /*
63325 * Newer version of video_device, handled by videodev2.c
63326 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63327 index 3cb939c..f23c6bb 100644
63328 --- a/include/media/v4l2-ioctl.h
63329 +++ b/include/media/v4l2-ioctl.h
63330 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63331 long (*vidioc_default) (struct file *file, void *fh,
63332 bool valid_prio, int cmd, void *arg);
63333 };
63334 -
63335 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63336
63337 /* v4l debugging and diagnostics */
63338
63339 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63340 index 6db8ecf..8c23861 100644
63341 --- a/include/net/caif/caif_hsi.h
63342 +++ b/include/net/caif/caif_hsi.h
63343 @@ -98,7 +98,7 @@ struct cfhsi_drv {
63344 void (*rx_done_cb) (struct cfhsi_drv *drv);
63345 void (*wake_up_cb) (struct cfhsi_drv *drv);
63346 void (*wake_down_cb) (struct cfhsi_drv *drv);
63347 -};
63348 +} __no_const;
63349
63350 /* Structure implemented by HSI device. */
63351 struct cfhsi_dev {
63352 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63353 index 9e5425b..8136ffc 100644
63354 --- a/include/net/caif/cfctrl.h
63355 +++ b/include/net/caif/cfctrl.h
63356 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
63357 void (*radioset_rsp)(void);
63358 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63359 struct cflayer *client_layer);
63360 -};
63361 +} __no_const;
63362
63363 /* Link Setup Parameters for CAIF-Links. */
63364 struct cfctrl_link_param {
63365 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
63366 struct cfctrl {
63367 struct cfsrvl serv;
63368 struct cfctrl_rsp res;
63369 - atomic_t req_seq_no;
63370 - atomic_t rsp_seq_no;
63371 + atomic_unchecked_t req_seq_no;
63372 + atomic_unchecked_t rsp_seq_no;
63373 struct list_head list;
63374 /* Protects from simultaneous access to first_req list */
63375 spinlock_t info_list_lock;
63376 diff --git a/include/net/flow.h b/include/net/flow.h
63377 index 6c469db..7743b8e 100644
63378 --- a/include/net/flow.h
63379 +++ b/include/net/flow.h
63380 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63381
63382 extern void flow_cache_flush(void);
63383 extern void flow_cache_flush_deferred(void);
63384 -extern atomic_t flow_cache_genid;
63385 +extern atomic_unchecked_t flow_cache_genid;
63386
63387 #endif
63388 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63389 index 2040bff..f4c0733 100644
63390 --- a/include/net/inetpeer.h
63391 +++ b/include/net/inetpeer.h
63392 @@ -51,8 +51,8 @@ struct inet_peer {
63393 */
63394 union {
63395 struct {
63396 - atomic_t rid; /* Frag reception counter */
63397 - atomic_t ip_id_count; /* IP ID for the next packet */
63398 + atomic_unchecked_t rid; /* Frag reception counter */
63399 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63400 __u32 tcp_ts;
63401 __u32 tcp_ts_stamp;
63402 };
63403 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63404 more++;
63405 inet_peer_refcheck(p);
63406 do {
63407 - old = atomic_read(&p->ip_id_count);
63408 + old = atomic_read_unchecked(&p->ip_id_count);
63409 new = old + more;
63410 if (!new)
63411 new = 1;
63412 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63413 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63414 return new;
63415 }
63416
63417 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63418 index 10422ef..662570f 100644
63419 --- a/include/net/ip_fib.h
63420 +++ b/include/net/ip_fib.h
63421 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63422
63423 #define FIB_RES_SADDR(net, res) \
63424 ((FIB_RES_NH(res).nh_saddr_genid == \
63425 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63426 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63427 FIB_RES_NH(res).nh_saddr : \
63428 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63429 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63430 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63431 index 72522f0..6f03a2b 100644
63432 --- a/include/net/ip_vs.h
63433 +++ b/include/net/ip_vs.h
63434 @@ -510,7 +510,7 @@ struct ip_vs_conn {
63435 struct ip_vs_conn *control; /* Master control connection */
63436 atomic_t n_control; /* Number of controlled ones */
63437 struct ip_vs_dest *dest; /* real server */
63438 - atomic_t in_pkts; /* incoming packet counter */
63439 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63440
63441 /* packet transmitter for different forwarding methods. If it
63442 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63443 @@ -648,7 +648,7 @@ struct ip_vs_dest {
63444 __be16 port; /* port number of the server */
63445 union nf_inet_addr addr; /* IP address of the server */
63446 volatile unsigned flags; /* dest status flags */
63447 - atomic_t conn_flags; /* flags to copy to conn */
63448 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63449 atomic_t weight; /* server weight */
63450
63451 atomic_t refcnt; /* reference counter */
63452 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63453 index 69b610a..fe3962c 100644
63454 --- a/include/net/irda/ircomm_core.h
63455 +++ b/include/net/irda/ircomm_core.h
63456 @@ -51,7 +51,7 @@ typedef struct {
63457 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63458 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63459 struct ircomm_info *);
63460 -} call_t;
63461 +} __no_const call_t;
63462
63463 struct ircomm_cb {
63464 irda_queue_t queue;
63465 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63466 index 59ba38bc..d515662 100644
63467 --- a/include/net/irda/ircomm_tty.h
63468 +++ b/include/net/irda/ircomm_tty.h
63469 @@ -35,6 +35,7 @@
63470 #include <linux/termios.h>
63471 #include <linux/timer.h>
63472 #include <linux/tty.h> /* struct tty_struct */
63473 +#include <asm/local.h>
63474
63475 #include <net/irda/irias_object.h>
63476 #include <net/irda/ircomm_core.h>
63477 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63478 unsigned short close_delay;
63479 unsigned short closing_wait; /* time to wait before closing */
63480
63481 - int open_count;
63482 - int blocked_open; /* # of blocked opens */
63483 + local_t open_count;
63484 + local_t blocked_open; /* # of blocked opens */
63485
63486 /* Protect concurent access to :
63487 * o self->open_count
63488 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63489 index cc7c197..9f2da2a 100644
63490 --- a/include/net/iucv/af_iucv.h
63491 +++ b/include/net/iucv/af_iucv.h
63492 @@ -141,7 +141,7 @@ struct iucv_sock {
63493 struct iucv_sock_list {
63494 struct hlist_head head;
63495 rwlock_t lock;
63496 - atomic_t autobind_name;
63497 + atomic_unchecked_t autobind_name;
63498 };
63499
63500 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63501 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63502 index 34c996f..bb3b4d4 100644
63503 --- a/include/net/neighbour.h
63504 +++ b/include/net/neighbour.h
63505 @@ -123,7 +123,7 @@ struct neigh_ops {
63506 void (*error_report)(struct neighbour *, struct sk_buff *);
63507 int (*output)(struct neighbour *, struct sk_buff *);
63508 int (*connected_output)(struct neighbour *, struct sk_buff *);
63509 -};
63510 +} __do_const;
63511
63512 struct pneigh_entry {
63513 struct pneigh_entry *next;
63514 diff --git a/include/net/netlink.h b/include/net/netlink.h
63515 index f394fe5..fd073f9 100644
63516 --- a/include/net/netlink.h
63517 +++ b/include/net/netlink.h
63518 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63519 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63520 {
63521 if (mark)
63522 - skb_trim(skb, (unsigned char *) mark - skb->data);
63523 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63524 }
63525
63526 /**
63527 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63528 index bbd023a..97c6d0d 100644
63529 --- a/include/net/netns/ipv4.h
63530 +++ b/include/net/netns/ipv4.h
63531 @@ -57,8 +57,8 @@ struct netns_ipv4 {
63532 unsigned int sysctl_ping_group_range[2];
63533 long sysctl_tcp_mem[3];
63534
63535 - atomic_t rt_genid;
63536 - atomic_t dev_addr_genid;
63537 + atomic_unchecked_t rt_genid;
63538 + atomic_unchecked_t dev_addr_genid;
63539
63540 #ifdef CONFIG_IP_MROUTE
63541 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63542 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63543 index a2ef814..31a8e3f 100644
63544 --- a/include/net/sctp/sctp.h
63545 +++ b/include/net/sctp/sctp.h
63546 @@ -318,9 +318,9 @@ do { \
63547
63548 #else /* SCTP_DEBUG */
63549
63550 -#define SCTP_DEBUG_PRINTK(whatever...)
63551 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63552 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63553 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63554 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63555 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63556 #define SCTP_ENABLE_DEBUG
63557 #define SCTP_DISABLE_DEBUG
63558 #define SCTP_ASSERT(expr, str, func)
63559 diff --git a/include/net/sock.h b/include/net/sock.h
63560 index 5a0a58a..2e3d4d0 100644
63561 --- a/include/net/sock.h
63562 +++ b/include/net/sock.h
63563 @@ -302,7 +302,7 @@ struct sock {
63564 #ifdef CONFIG_RPS
63565 __u32 sk_rxhash;
63566 #endif
63567 - atomic_t sk_drops;
63568 + atomic_unchecked_t sk_drops;
63569 int sk_rcvbuf;
63570
63571 struct sk_filter __rcu *sk_filter;
63572 @@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63573 }
63574
63575 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63576 - char __user *from, char *to,
63577 + char __user *from, unsigned char *to,
63578 int copy, int offset)
63579 {
63580 if (skb->ip_summed == CHECKSUM_NONE) {
63581 diff --git a/include/net/tcp.h b/include/net/tcp.h
63582 index f75a04d..702cf06 100644
63583 --- a/include/net/tcp.h
63584 +++ b/include/net/tcp.h
63585 @@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
63586 char *name;
63587 sa_family_t family;
63588 const struct file_operations *seq_fops;
63589 - struct seq_operations seq_ops;
63590 + seq_operations_no_const seq_ops;
63591 };
63592
63593 struct tcp_iter_state {
63594 diff --git a/include/net/udp.h b/include/net/udp.h
63595 index 5d606d9..e879f7b 100644
63596 --- a/include/net/udp.h
63597 +++ b/include/net/udp.h
63598 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
63599 sa_family_t family;
63600 struct udp_table *udp_table;
63601 const struct file_operations *seq_fops;
63602 - struct seq_operations seq_ops;
63603 + seq_operations_no_const seq_ops;
63604 };
63605
63606 struct udp_iter_state {
63607 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63608 index 96239e7..c85b032 100644
63609 --- a/include/net/xfrm.h
63610 +++ b/include/net/xfrm.h
63611 @@ -505,7 +505,7 @@ struct xfrm_policy {
63612 struct timer_list timer;
63613
63614 struct flow_cache_object flo;
63615 - atomic_t genid;
63616 + atomic_unchecked_t genid;
63617 u32 priority;
63618 u32 index;
63619 struct xfrm_mark mark;
63620 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63621 index 1a046b1..ee0bef0 100644
63622 --- a/include/rdma/iw_cm.h
63623 +++ b/include/rdma/iw_cm.h
63624 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63625 int backlog);
63626
63627 int (*destroy_listen)(struct iw_cm_id *cm_id);
63628 -};
63629 +} __no_const;
63630
63631 /**
63632 * iw_create_cm_id - Create an IW CM identifier.
63633 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63634 index 8f9dfba..610ab6c 100644
63635 --- a/include/scsi/libfc.h
63636 +++ b/include/scsi/libfc.h
63637 @@ -756,6 +756,7 @@ struct libfc_function_template {
63638 */
63639 void (*disc_stop_final) (struct fc_lport *);
63640 };
63641 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63642
63643 /**
63644 * struct fc_disc - Discovery context
63645 @@ -861,7 +862,7 @@ struct fc_lport {
63646 struct fc_vport *vport;
63647
63648 /* Operational Information */
63649 - struct libfc_function_template tt;
63650 + libfc_function_template_no_const tt;
63651 u8 link_up;
63652 u8 qfull;
63653 enum fc_lport_state state;
63654 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63655 index ba96988..ecf2eb9 100644
63656 --- a/include/scsi/scsi_device.h
63657 +++ b/include/scsi/scsi_device.h
63658 @@ -163,9 +163,9 @@ struct scsi_device {
63659 unsigned int max_device_blocked; /* what device_blocked counts down from */
63660 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63661
63662 - atomic_t iorequest_cnt;
63663 - atomic_t iodone_cnt;
63664 - atomic_t ioerr_cnt;
63665 + atomic_unchecked_t iorequest_cnt;
63666 + atomic_unchecked_t iodone_cnt;
63667 + atomic_unchecked_t ioerr_cnt;
63668
63669 struct device sdev_gendev,
63670 sdev_dev;
63671 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63672 index 719faf1..d1154d4 100644
63673 --- a/include/scsi/scsi_transport_fc.h
63674 +++ b/include/scsi/scsi_transport_fc.h
63675 @@ -739,7 +739,7 @@ struct fc_function_template {
63676 unsigned long show_host_system_hostname:1;
63677
63678 unsigned long disable_target_scan:1;
63679 -};
63680 +} __do_const;
63681
63682
63683 /**
63684 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63685 index 030b87c..98a6954 100644
63686 --- a/include/sound/ak4xxx-adda.h
63687 +++ b/include/sound/ak4xxx-adda.h
63688 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63689 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63690 unsigned char val);
63691 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63692 -};
63693 +} __no_const;
63694
63695 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63696
63697 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63698 index 8c05e47..2b5df97 100644
63699 --- a/include/sound/hwdep.h
63700 +++ b/include/sound/hwdep.h
63701 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63702 struct snd_hwdep_dsp_status *status);
63703 int (*dsp_load)(struct snd_hwdep *hw,
63704 struct snd_hwdep_dsp_image *image);
63705 -};
63706 +} __no_const;
63707
63708 struct snd_hwdep {
63709 struct snd_card *card;
63710 diff --git a/include/sound/info.h b/include/sound/info.h
63711 index 9ca1a49..aba1728 100644
63712 --- a/include/sound/info.h
63713 +++ b/include/sound/info.h
63714 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63715 struct snd_info_buffer *buffer);
63716 void (*write)(struct snd_info_entry *entry,
63717 struct snd_info_buffer *buffer);
63718 -};
63719 +} __no_const;
63720
63721 struct snd_info_entry_ops {
63722 int (*open)(struct snd_info_entry *entry,
63723 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63724 index 0d11128..814178e 100644
63725 --- a/include/sound/pcm.h
63726 +++ b/include/sound/pcm.h
63727 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63728 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63729 int (*ack)(struct snd_pcm_substream *substream);
63730 };
63731 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63732
63733 /*
63734 *
63735 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63736 index af1b49e..a5d55a5 100644
63737 --- a/include/sound/sb16_csp.h
63738 +++ b/include/sound/sb16_csp.h
63739 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63740 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63741 int (*csp_stop) (struct snd_sb_csp * p);
63742 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63743 -};
63744 +} __no_const;
63745
63746 /*
63747 * CSP private data
63748 diff --git a/include/sound/soc.h b/include/sound/soc.h
63749 index 2ebf787..0276839 100644
63750 --- a/include/sound/soc.h
63751 +++ b/include/sound/soc.h
63752 @@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
63753 /* platform IO - used for platform DAPM */
63754 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63755 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63756 -};
63757 +} __do_const;
63758
63759 struct snd_soc_platform {
63760 const char *name;
63761 @@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
63762 struct snd_soc_dai_link *dai_link;
63763 struct mutex pcm_mutex;
63764 enum snd_soc_pcm_subclass pcm_subclass;
63765 - struct snd_pcm_ops ops;
63766 + snd_pcm_ops_no_const ops;
63767
63768 unsigned int complete:1;
63769 unsigned int dev_registered:1;
63770 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63771 index 4119966..1a4671c 100644
63772 --- a/include/sound/ymfpci.h
63773 +++ b/include/sound/ymfpci.h
63774 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63775 spinlock_t reg_lock;
63776 spinlock_t voice_lock;
63777 wait_queue_head_t interrupt_sleep;
63778 - atomic_t interrupt_sleep_count;
63779 + atomic_unchecked_t interrupt_sleep_count;
63780 struct snd_info_entry *proc_entry;
63781 const struct firmware *dsp_microcode;
63782 const struct firmware *controller_microcode;
63783 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63784 index aaccc5f..092d568 100644
63785 --- a/include/target/target_core_base.h
63786 +++ b/include/target/target_core_base.h
63787 @@ -447,7 +447,7 @@ struct t10_reservation_ops {
63788 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63789 int (*t10_pr_register)(struct se_cmd *);
63790 int (*t10_pr_clear)(struct se_cmd *);
63791 -};
63792 +} __no_const;
63793
63794 struct t10_reservation {
63795 /* Reservation effects all target ports */
63796 @@ -576,7 +576,7 @@ struct se_cmd {
63797 atomic_t t_se_count;
63798 atomic_t t_task_cdbs_left;
63799 atomic_t t_task_cdbs_ex_left;
63800 - atomic_t t_task_cdbs_sent;
63801 + atomic_unchecked_t t_task_cdbs_sent;
63802 unsigned int transport_state;
63803 #define CMD_T_ABORTED (1 << 0)
63804 #define CMD_T_ACTIVE (1 << 1)
63805 @@ -802,7 +802,7 @@ struct se_device {
63806 spinlock_t stats_lock;
63807 /* Active commands on this virtual SE device */
63808 atomic_t simple_cmds;
63809 - atomic_t dev_ordered_id;
63810 + atomic_unchecked_t dev_ordered_id;
63811 atomic_t execute_tasks;
63812 atomic_t dev_ordered_sync;
63813 atomic_t dev_qf_count;
63814 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
63815 new file mode 100644
63816 index 0000000..2efe49d
63817 --- /dev/null
63818 +++ b/include/trace/events/fs.h
63819 @@ -0,0 +1,53 @@
63820 +#undef TRACE_SYSTEM
63821 +#define TRACE_SYSTEM fs
63822 +
63823 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
63824 +#define _TRACE_FS_H
63825 +
63826 +#include <linux/fs.h>
63827 +#include <linux/tracepoint.h>
63828 +
63829 +TRACE_EVENT(do_sys_open,
63830 +
63831 + TP_PROTO(char *filename, int flags, int mode),
63832 +
63833 + TP_ARGS(filename, flags, mode),
63834 +
63835 + TP_STRUCT__entry(
63836 + __string( filename, filename )
63837 + __field( int, flags )
63838 + __field( int, mode )
63839 + ),
63840 +
63841 + TP_fast_assign(
63842 + __assign_str(filename, filename);
63843 + __entry->flags = flags;
63844 + __entry->mode = mode;
63845 + ),
63846 +
63847 + TP_printk("\"%s\" %x %o",
63848 + __get_str(filename), __entry->flags, __entry->mode)
63849 +);
63850 +
63851 +TRACE_EVENT(open_exec,
63852 +
63853 + TP_PROTO(const char *filename),
63854 +
63855 + TP_ARGS(filename),
63856 +
63857 + TP_STRUCT__entry(
63858 + __string( filename, filename )
63859 + ),
63860 +
63861 + TP_fast_assign(
63862 + __assign_str(filename, filename);
63863 + ),
63864 +
63865 + TP_printk("\"%s\"",
63866 + __get_str(filename))
63867 +);
63868 +
63869 +#endif /* _TRACE_FS_H */
63870 +
63871 +/* This part must be outside protection */
63872 +#include <trace/define_trace.h>
63873 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63874 index 1c09820..7f5ec79 100644
63875 --- a/include/trace/events/irq.h
63876 +++ b/include/trace/events/irq.h
63877 @@ -36,7 +36,7 @@ struct softirq_action;
63878 */
63879 TRACE_EVENT(irq_handler_entry,
63880
63881 - TP_PROTO(int irq, struct irqaction *action),
63882 + TP_PROTO(int irq, const struct irqaction *action),
63883
63884 TP_ARGS(irq, action),
63885
63886 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63887 */
63888 TRACE_EVENT(irq_handler_exit,
63889
63890 - TP_PROTO(int irq, struct irqaction *action, int ret),
63891 + TP_PROTO(int irq, const struct irqaction *action, int ret),
63892
63893 TP_ARGS(irq, action, ret),
63894
63895 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63896 index f9466fa..f4e2b81 100644
63897 --- a/include/video/udlfb.h
63898 +++ b/include/video/udlfb.h
63899 @@ -53,10 +53,10 @@ struct dlfb_data {
63900 u32 pseudo_palette[256];
63901 int blank_mode; /*one of FB_BLANK_ */
63902 /* blit-only rendering path metrics, exposed through sysfs */
63903 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63904 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63905 - atomic_t bytes_sent; /* to usb, after compression including overhead */
63906 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63907 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63908 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63909 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63910 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63911 };
63912
63913 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63914 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63915 index 0993a22..32ba2fe 100644
63916 --- a/include/video/uvesafb.h
63917 +++ b/include/video/uvesafb.h
63918 @@ -177,6 +177,7 @@ struct uvesafb_par {
63919 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63920 u8 pmi_setpal; /* PMI for palette changes */
63921 u16 *pmi_base; /* protected mode interface location */
63922 + u8 *pmi_code; /* protected mode code location */
63923 void *pmi_start;
63924 void *pmi_pal;
63925 u8 *vbe_state_orig; /*
63926 diff --git a/init/Kconfig b/init/Kconfig
63927 index 6cfd71d..16006e6 100644
63928 --- a/init/Kconfig
63929 +++ b/init/Kconfig
63930 @@ -790,6 +790,7 @@ endif # CGROUPS
63931
63932 config CHECKPOINT_RESTORE
63933 bool "Checkpoint/restore support" if EXPERT
63934 + depends on !GRKERNSEC
63935 default n
63936 help
63937 Enables additional kernel features in a sake of checkpoint/restore.
63938 @@ -1240,7 +1241,7 @@ config SLUB_DEBUG
63939
63940 config COMPAT_BRK
63941 bool "Disable heap randomization"
63942 - default y
63943 + default n
63944 help
63945 Randomizing heap placement makes heap exploits harder, but it
63946 also breaks ancient binaries (including anything libc5 based).
63947 @@ -1423,7 +1424,7 @@ config INIT_ALL_POSSIBLE
63948 config STOP_MACHINE
63949 bool
63950 default y
63951 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
63952 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
63953 help
63954 Need stop_machine() primitive.
63955
63956 diff --git a/init/do_mounts.c b/init/do_mounts.c
63957 index 42b0707..c06eef4 100644
63958 --- a/init/do_mounts.c
63959 +++ b/init/do_mounts.c
63960 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
63961 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
63962 {
63963 struct super_block *s;
63964 - int err = sys_mount(name, "/root", fs, flags, data);
63965 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
63966 if (err)
63967 return err;
63968
63969 - sys_chdir((const char __user __force *)"/root");
63970 + sys_chdir((const char __force_user *)"/root");
63971 s = current->fs->pwd.dentry->d_sb;
63972 ROOT_DEV = s->s_dev;
63973 printk(KERN_INFO
63974 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
63975 va_start(args, fmt);
63976 vsprintf(buf, fmt, args);
63977 va_end(args);
63978 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
63979 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
63980 if (fd >= 0) {
63981 sys_ioctl(fd, FDEJECT, 0);
63982 sys_close(fd);
63983 }
63984 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
63985 - fd = sys_open("/dev/console", O_RDWR, 0);
63986 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
63987 if (fd >= 0) {
63988 sys_ioctl(fd, TCGETS, (long)&termios);
63989 termios.c_lflag &= ~ICANON;
63990 sys_ioctl(fd, TCSETSF, (long)&termios);
63991 - sys_read(fd, &c, 1);
63992 + sys_read(fd, (char __user *)&c, 1);
63993 termios.c_lflag |= ICANON;
63994 sys_ioctl(fd, TCSETSF, (long)&termios);
63995 sys_close(fd);
63996 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
63997 mount_root();
63998 out:
63999 devtmpfs_mount("dev");
64000 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64001 - sys_chroot((const char __user __force *)".");
64002 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64003 + sys_chroot((const char __force_user *)".");
64004 }
64005 diff --git a/init/do_mounts.h b/init/do_mounts.h
64006 index f5b978a..69dbfe8 100644
64007 --- a/init/do_mounts.h
64008 +++ b/init/do_mounts.h
64009 @@ -15,15 +15,15 @@ extern int root_mountflags;
64010
64011 static inline int create_dev(char *name, dev_t dev)
64012 {
64013 - sys_unlink(name);
64014 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64015 + sys_unlink((char __force_user *)name);
64016 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64017 }
64018
64019 #if BITS_PER_LONG == 32
64020 static inline u32 bstat(char *name)
64021 {
64022 struct stat64 stat;
64023 - if (sys_stat64(name, &stat) != 0)
64024 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64025 return 0;
64026 if (!S_ISBLK(stat.st_mode))
64027 return 0;
64028 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64029 static inline u32 bstat(char *name)
64030 {
64031 struct stat stat;
64032 - if (sys_newstat(name, &stat) != 0)
64033 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64034 return 0;
64035 if (!S_ISBLK(stat.st_mode))
64036 return 0;
64037 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64038 index 9047330..de0d1fb 100644
64039 --- a/init/do_mounts_initrd.c
64040 +++ b/init/do_mounts_initrd.c
64041 @@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64042 create_dev("/dev/root.old", Root_RAM0);
64043 /* mount initrd on rootfs' /root */
64044 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64045 - sys_mkdir("/old", 0700);
64046 - root_fd = sys_open("/", 0, 0);
64047 - old_fd = sys_open("/old", 0, 0);
64048 + sys_mkdir((const char __force_user *)"/old", 0700);
64049 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64050 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64051 /* move initrd over / and chdir/chroot in initrd root */
64052 - sys_chdir("/root");
64053 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64054 - sys_chroot(".");
64055 + sys_chdir((const char __force_user *)"/root");
64056 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64057 + sys_chroot((const char __force_user *)".");
64058
64059 /*
64060 * In case that a resume from disk is carried out by linuxrc or one of
64061 @@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64062
64063 /* move initrd to rootfs' /old */
64064 sys_fchdir(old_fd);
64065 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64066 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64067 /* switch root and cwd back to / of rootfs */
64068 sys_fchdir(root_fd);
64069 - sys_chroot(".");
64070 + sys_chroot((const char __force_user *)".");
64071 sys_close(old_fd);
64072 sys_close(root_fd);
64073
64074 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64075 - sys_chdir("/old");
64076 + sys_chdir((const char __force_user *)"/old");
64077 return;
64078 }
64079
64080 @@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64081 mount_root();
64082
64083 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64084 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64085 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64086 if (!error)
64087 printk("okay\n");
64088 else {
64089 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64090 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64091 if (error == -ENOENT)
64092 printk("/initrd does not exist. Ignored.\n");
64093 else
64094 printk("failed\n");
64095 printk(KERN_NOTICE "Unmounting old root\n");
64096 - sys_umount("/old", MNT_DETACH);
64097 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64098 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64099 if (fd < 0) {
64100 error = fd;
64101 @@ -115,11 +115,11 @@ int __init initrd_load(void)
64102 * mounted in the normal path.
64103 */
64104 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64105 - sys_unlink("/initrd.image");
64106 + sys_unlink((const char __force_user *)"/initrd.image");
64107 handle_initrd();
64108 return 1;
64109 }
64110 }
64111 - sys_unlink("/initrd.image");
64112 + sys_unlink((const char __force_user *)"/initrd.image");
64113 return 0;
64114 }
64115 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64116 index 32c4799..c27ee74 100644
64117 --- a/init/do_mounts_md.c
64118 +++ b/init/do_mounts_md.c
64119 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64120 partitioned ? "_d" : "", minor,
64121 md_setup_args[ent].device_names);
64122
64123 - fd = sys_open(name, 0, 0);
64124 + fd = sys_open((char __force_user *)name, 0, 0);
64125 if (fd < 0) {
64126 printk(KERN_ERR "md: open failed - cannot start "
64127 "array %s\n", name);
64128 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64129 * array without it
64130 */
64131 sys_close(fd);
64132 - fd = sys_open(name, 0, 0);
64133 + fd = sys_open((char __force_user *)name, 0, 0);
64134 sys_ioctl(fd, BLKRRPART, 0);
64135 }
64136 sys_close(fd);
64137 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64138
64139 wait_for_device_probe();
64140
64141 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64142 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64143 if (fd >= 0) {
64144 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64145 sys_close(fd);
64146 diff --git a/init/initramfs.c b/init/initramfs.c
64147 index 8216c30..25e8e32 100644
64148 --- a/init/initramfs.c
64149 +++ b/init/initramfs.c
64150 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64151 }
64152 }
64153
64154 -static long __init do_utime(char __user *filename, time_t mtime)
64155 +static long __init do_utime(__force char __user *filename, time_t mtime)
64156 {
64157 struct timespec t[2];
64158
64159 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64160 struct dir_entry *de, *tmp;
64161 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64162 list_del(&de->list);
64163 - do_utime(de->name, de->mtime);
64164 + do_utime((char __force_user *)de->name, de->mtime);
64165 kfree(de->name);
64166 kfree(de);
64167 }
64168 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64169 if (nlink >= 2) {
64170 char *old = find_link(major, minor, ino, mode, collected);
64171 if (old)
64172 - return (sys_link(old, collected) < 0) ? -1 : 1;
64173 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64174 }
64175 return 0;
64176 }
64177 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64178 {
64179 struct stat st;
64180
64181 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64182 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64183 if (S_ISDIR(st.st_mode))
64184 - sys_rmdir(path);
64185 + sys_rmdir((char __force_user *)path);
64186 else
64187 - sys_unlink(path);
64188 + sys_unlink((char __force_user *)path);
64189 }
64190 }
64191
64192 @@ -305,7 +305,7 @@ static int __init do_name(void)
64193 int openflags = O_WRONLY|O_CREAT;
64194 if (ml != 1)
64195 openflags |= O_TRUNC;
64196 - wfd = sys_open(collected, openflags, mode);
64197 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64198
64199 if (wfd >= 0) {
64200 sys_fchown(wfd, uid, gid);
64201 @@ -317,17 +317,17 @@ static int __init do_name(void)
64202 }
64203 }
64204 } else if (S_ISDIR(mode)) {
64205 - sys_mkdir(collected, mode);
64206 - sys_chown(collected, uid, gid);
64207 - sys_chmod(collected, mode);
64208 + sys_mkdir((char __force_user *)collected, mode);
64209 + sys_chown((char __force_user *)collected, uid, gid);
64210 + sys_chmod((char __force_user *)collected, mode);
64211 dir_add(collected, mtime);
64212 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64213 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64214 if (maybe_link() == 0) {
64215 - sys_mknod(collected, mode, rdev);
64216 - sys_chown(collected, uid, gid);
64217 - sys_chmod(collected, mode);
64218 - do_utime(collected, mtime);
64219 + sys_mknod((char __force_user *)collected, mode, rdev);
64220 + sys_chown((char __force_user *)collected, uid, gid);
64221 + sys_chmod((char __force_user *)collected, mode);
64222 + do_utime((char __force_user *)collected, mtime);
64223 }
64224 }
64225 return 0;
64226 @@ -336,15 +336,15 @@ static int __init do_name(void)
64227 static int __init do_copy(void)
64228 {
64229 if (count >= body_len) {
64230 - sys_write(wfd, victim, body_len);
64231 + sys_write(wfd, (char __force_user *)victim, body_len);
64232 sys_close(wfd);
64233 - do_utime(vcollected, mtime);
64234 + do_utime((char __force_user *)vcollected, mtime);
64235 kfree(vcollected);
64236 eat(body_len);
64237 state = SkipIt;
64238 return 0;
64239 } else {
64240 - sys_write(wfd, victim, count);
64241 + sys_write(wfd, (char __force_user *)victim, count);
64242 body_len -= count;
64243 eat(count);
64244 return 1;
64245 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64246 {
64247 collected[N_ALIGN(name_len) + body_len] = '\0';
64248 clean_path(collected, 0);
64249 - sys_symlink(collected + N_ALIGN(name_len), collected);
64250 - sys_lchown(collected, uid, gid);
64251 - do_utime(collected, mtime);
64252 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64253 + sys_lchown((char __force_user *)collected, uid, gid);
64254 + do_utime((char __force_user *)collected, mtime);
64255 state = SkipIt;
64256 next_state = Reset;
64257 return 0;
64258 diff --git a/init/main.c b/init/main.c
64259 index b08c5f7..09f865e 100644
64260 --- a/init/main.c
64261 +++ b/init/main.c
64262 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64263 extern void tc_init(void);
64264 #endif
64265
64266 +extern void grsecurity_init(void);
64267 +
64268 /*
64269 * Debug helper: via this flag we know that we are in 'early bootup code'
64270 * where only the boot processor is running with IRQ disabled. This means
64271 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64272
64273 __setup("reset_devices", set_reset_devices);
64274
64275 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64276 +extern char pax_enter_kernel_user[];
64277 +extern char pax_exit_kernel_user[];
64278 +extern pgdval_t clone_pgd_mask;
64279 +#endif
64280 +
64281 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64282 +static int __init setup_pax_nouderef(char *str)
64283 +{
64284 +#ifdef CONFIG_X86_32
64285 + unsigned int cpu;
64286 + struct desc_struct *gdt;
64287 +
64288 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64289 + gdt = get_cpu_gdt_table(cpu);
64290 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64291 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64292 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64293 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64294 + }
64295 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64296 +#else
64297 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64298 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64299 + clone_pgd_mask = ~(pgdval_t)0UL;
64300 +#endif
64301 +
64302 + return 0;
64303 +}
64304 +early_param("pax_nouderef", setup_pax_nouderef);
64305 +#endif
64306 +
64307 +#ifdef CONFIG_PAX_SOFTMODE
64308 +int pax_softmode;
64309 +
64310 +static int __init setup_pax_softmode(char *str)
64311 +{
64312 + get_option(&str, &pax_softmode);
64313 + return 1;
64314 +}
64315 +__setup("pax_softmode=", setup_pax_softmode);
64316 +#endif
64317 +
64318 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64319 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64320 static const char *panic_later, *panic_param;
64321 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64322 {
64323 int count = preempt_count();
64324 int ret;
64325 + const char *msg1 = "", *msg2 = "";
64326
64327 if (initcall_debug)
64328 ret = do_one_initcall_debug(fn);
64329 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64330 sprintf(msgbuf, "error code %d ", ret);
64331
64332 if (preempt_count() != count) {
64333 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64334 + msg1 = " preemption imbalance";
64335 preempt_count() = count;
64336 }
64337 if (irqs_disabled()) {
64338 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64339 + msg2 = " disabled interrupts";
64340 local_irq_enable();
64341 }
64342 - if (msgbuf[0]) {
64343 - printk("initcall %pF returned with %s\n", fn, msgbuf);
64344 + if (msgbuf[0] || *msg1 || *msg2) {
64345 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64346 }
64347
64348 return ret;
64349 @@ -865,7 +911,7 @@ static int __init kernel_init(void * unused)
64350 do_basic_setup();
64351
64352 /* Open the /dev/console on the rootfs, this should never fail */
64353 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64354 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64355 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64356
64357 (void) sys_dup(0);
64358 @@ -878,11 +924,13 @@ static int __init kernel_init(void * unused)
64359 if (!ramdisk_execute_command)
64360 ramdisk_execute_command = "/init";
64361
64362 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64363 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64364 ramdisk_execute_command = NULL;
64365 prepare_namespace();
64366 }
64367
64368 + grsecurity_init();
64369 +
64370 /*
64371 * Ok, we have completed the initial bootup, and
64372 * we're essentially up and running. Get rid of the
64373 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64374 index 28bd64d..c66b72a 100644
64375 --- a/ipc/mqueue.c
64376 +++ b/ipc/mqueue.c
64377 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64378 mq_bytes = (mq_msg_tblsz +
64379 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64380
64381 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64382 spin_lock(&mq_lock);
64383 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64384 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
64385 diff --git a/ipc/msg.c b/ipc/msg.c
64386 index 7385de2..a8180e08 100644
64387 --- a/ipc/msg.c
64388 +++ b/ipc/msg.c
64389 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64390 return security_msg_queue_associate(msq, msgflg);
64391 }
64392
64393 +static struct ipc_ops msg_ops = {
64394 + .getnew = newque,
64395 + .associate = msg_security,
64396 + .more_checks = NULL
64397 +};
64398 +
64399 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64400 {
64401 struct ipc_namespace *ns;
64402 - struct ipc_ops msg_ops;
64403 struct ipc_params msg_params;
64404
64405 ns = current->nsproxy->ipc_ns;
64406
64407 - msg_ops.getnew = newque;
64408 - msg_ops.associate = msg_security;
64409 - msg_ops.more_checks = NULL;
64410 -
64411 msg_params.key = key;
64412 msg_params.flg = msgflg;
64413
64414 diff --git a/ipc/sem.c b/ipc/sem.c
64415 index 5215a81..cfc0cac 100644
64416 --- a/ipc/sem.c
64417 +++ b/ipc/sem.c
64418 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64419 return 0;
64420 }
64421
64422 +static struct ipc_ops sem_ops = {
64423 + .getnew = newary,
64424 + .associate = sem_security,
64425 + .more_checks = sem_more_checks
64426 +};
64427 +
64428 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64429 {
64430 struct ipc_namespace *ns;
64431 - struct ipc_ops sem_ops;
64432 struct ipc_params sem_params;
64433
64434 ns = current->nsproxy->ipc_ns;
64435 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64436 if (nsems < 0 || nsems > ns->sc_semmsl)
64437 return -EINVAL;
64438
64439 - sem_ops.getnew = newary;
64440 - sem_ops.associate = sem_security;
64441 - sem_ops.more_checks = sem_more_checks;
64442 -
64443 sem_params.key = key;
64444 sem_params.flg = semflg;
64445 sem_params.u.nsems = nsems;
64446 diff --git a/ipc/shm.c b/ipc/shm.c
64447 index 406c5b2..bc66d67 100644
64448 --- a/ipc/shm.c
64449 +++ b/ipc/shm.c
64450 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64451 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64452 #endif
64453
64454 +#ifdef CONFIG_GRKERNSEC
64455 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64456 + const time_t shm_createtime, const uid_t cuid,
64457 + const int shmid);
64458 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64459 + const time_t shm_createtime);
64460 +#endif
64461 +
64462 void shm_init_ns(struct ipc_namespace *ns)
64463 {
64464 ns->shm_ctlmax = SHMMAX;
64465 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64466 shp->shm_lprid = 0;
64467 shp->shm_atim = shp->shm_dtim = 0;
64468 shp->shm_ctim = get_seconds();
64469 +#ifdef CONFIG_GRKERNSEC
64470 + {
64471 + struct timespec timeval;
64472 + do_posix_clock_monotonic_gettime(&timeval);
64473 +
64474 + shp->shm_createtime = timeval.tv_sec;
64475 + }
64476 +#endif
64477 shp->shm_segsz = size;
64478 shp->shm_nattch = 0;
64479 shp->shm_file = file;
64480 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64481 return 0;
64482 }
64483
64484 +static struct ipc_ops shm_ops = {
64485 + .getnew = newseg,
64486 + .associate = shm_security,
64487 + .more_checks = shm_more_checks
64488 +};
64489 +
64490 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64491 {
64492 struct ipc_namespace *ns;
64493 - struct ipc_ops shm_ops;
64494 struct ipc_params shm_params;
64495
64496 ns = current->nsproxy->ipc_ns;
64497
64498 - shm_ops.getnew = newseg;
64499 - shm_ops.associate = shm_security;
64500 - shm_ops.more_checks = shm_more_checks;
64501 -
64502 shm_params.key = key;
64503 shm_params.flg = shmflg;
64504 shm_params.u.size = size;
64505 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64506 f_mode = FMODE_READ | FMODE_WRITE;
64507 }
64508 if (shmflg & SHM_EXEC) {
64509 +
64510 +#ifdef CONFIG_PAX_MPROTECT
64511 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64512 + goto out;
64513 +#endif
64514 +
64515 prot |= PROT_EXEC;
64516 acc_mode |= S_IXUGO;
64517 }
64518 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64519 if (err)
64520 goto out_unlock;
64521
64522 +#ifdef CONFIG_GRKERNSEC
64523 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64524 + shp->shm_perm.cuid, shmid) ||
64525 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64526 + err = -EACCES;
64527 + goto out_unlock;
64528 + }
64529 +#endif
64530 +
64531 path = shp->shm_file->f_path;
64532 path_get(&path);
64533 shp->shm_nattch++;
64534 +#ifdef CONFIG_GRKERNSEC
64535 + shp->shm_lapid = current->pid;
64536 +#endif
64537 size = i_size_read(path.dentry->d_inode);
64538 shm_unlock(shp);
64539
64540 diff --git a/kernel/acct.c b/kernel/acct.c
64541 index 02e6167..54824f7 100644
64542 --- a/kernel/acct.c
64543 +++ b/kernel/acct.c
64544 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64545 */
64546 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64547 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64548 - file->f_op->write(file, (char *)&ac,
64549 + file->f_op->write(file, (char __force_user *)&ac,
64550 sizeof(acct_t), &file->f_pos);
64551 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64552 set_fs(fs);
64553 diff --git a/kernel/audit.c b/kernel/audit.c
64554 index 1c7f2c6..9ba5359 100644
64555 --- a/kernel/audit.c
64556 +++ b/kernel/audit.c
64557 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64558 3) suppressed due to audit_rate_limit
64559 4) suppressed due to audit_backlog_limit
64560 */
64561 -static atomic_t audit_lost = ATOMIC_INIT(0);
64562 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64563
64564 /* The netlink socket. */
64565 static struct sock *audit_sock;
64566 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64567 unsigned long now;
64568 int print;
64569
64570 - atomic_inc(&audit_lost);
64571 + atomic_inc_unchecked(&audit_lost);
64572
64573 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64574
64575 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64576 printk(KERN_WARNING
64577 "audit: audit_lost=%d audit_rate_limit=%d "
64578 "audit_backlog_limit=%d\n",
64579 - atomic_read(&audit_lost),
64580 + atomic_read_unchecked(&audit_lost),
64581 audit_rate_limit,
64582 audit_backlog_limit);
64583 audit_panic(message);
64584 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64585 status_set.pid = audit_pid;
64586 status_set.rate_limit = audit_rate_limit;
64587 status_set.backlog_limit = audit_backlog_limit;
64588 - status_set.lost = atomic_read(&audit_lost);
64589 + status_set.lost = atomic_read_unchecked(&audit_lost);
64590 status_set.backlog = skb_queue_len(&audit_skb_queue);
64591 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64592 &status_set, sizeof(status_set));
64593 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64594 index af1de0f..06dfe57 100644
64595 --- a/kernel/auditsc.c
64596 +++ b/kernel/auditsc.c
64597 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64598 }
64599
64600 /* global counter which is incremented every time something logs in */
64601 -static atomic_t session_id = ATOMIC_INIT(0);
64602 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64603
64604 /**
64605 * audit_set_loginuid - set current task's audit_context loginuid
64606 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64607 return -EPERM;
64608 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64609
64610 - sessionid = atomic_inc_return(&session_id);
64611 + sessionid = atomic_inc_return_unchecked(&session_id);
64612 if (context && context->in_syscall) {
64613 struct audit_buffer *ab;
64614
64615 diff --git a/kernel/capability.c b/kernel/capability.c
64616 index 3f1adb6..c564db0 100644
64617 --- a/kernel/capability.c
64618 +++ b/kernel/capability.c
64619 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64620 * before modification is attempted and the application
64621 * fails.
64622 */
64623 + if (tocopy > ARRAY_SIZE(kdata))
64624 + return -EFAULT;
64625 +
64626 if (copy_to_user(dataptr, kdata, tocopy
64627 * sizeof(struct __user_cap_data_struct))) {
64628 return -EFAULT;
64629 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64630 int ret;
64631
64632 rcu_read_lock();
64633 - ret = security_capable(__task_cred(t), ns, cap);
64634 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64635 + gr_task_is_capable(t, __task_cred(t), cap);
64636 rcu_read_unlock();
64637
64638 - return (ret == 0);
64639 + return ret;
64640 }
64641
64642 /**
64643 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64644 int ret;
64645
64646 rcu_read_lock();
64647 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
64648 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64649 rcu_read_unlock();
64650
64651 - return (ret == 0);
64652 + return ret;
64653 }
64654
64655 /**
64656 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64657 BUG();
64658 }
64659
64660 - if (security_capable(current_cred(), ns, cap) == 0) {
64661 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64662 current->flags |= PF_SUPERPRIV;
64663 return true;
64664 }
64665 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64666 }
64667 EXPORT_SYMBOL(ns_capable);
64668
64669 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64670 +{
64671 + if (unlikely(!cap_valid(cap))) {
64672 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64673 + BUG();
64674 + }
64675 +
64676 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64677 + current->flags |= PF_SUPERPRIV;
64678 + return true;
64679 + }
64680 + return false;
64681 +}
64682 +EXPORT_SYMBOL(ns_capable_nolog);
64683 +
64684 /**
64685 * capable - Determine if the current task has a superior capability in effect
64686 * @cap: The capability to be tested for
64687 @@ -408,6 +427,12 @@ bool capable(int cap)
64688 }
64689 EXPORT_SYMBOL(capable);
64690
64691 +bool capable_nolog(int cap)
64692 +{
64693 + return ns_capable_nolog(&init_user_ns, cap);
64694 +}
64695 +EXPORT_SYMBOL(capable_nolog);
64696 +
64697 /**
64698 * nsown_capable - Check superior capability to one's own user_ns
64699 * @cap: The capability in question
64700 diff --git a/kernel/compat.c b/kernel/compat.c
64701 index d2c67aa..a629b2e 100644
64702 --- a/kernel/compat.c
64703 +++ b/kernel/compat.c
64704 @@ -13,6 +13,7 @@
64705
64706 #include <linux/linkage.h>
64707 #include <linux/compat.h>
64708 +#include <linux/module.h>
64709 #include <linux/errno.h>
64710 #include <linux/time.h>
64711 #include <linux/signal.h>
64712 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64713 mm_segment_t oldfs;
64714 long ret;
64715
64716 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64717 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64718 oldfs = get_fs();
64719 set_fs(KERNEL_DS);
64720 ret = hrtimer_nanosleep_restart(restart);
64721 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64722 oldfs = get_fs();
64723 set_fs(KERNEL_DS);
64724 ret = hrtimer_nanosleep(&tu,
64725 - rmtp ? (struct timespec __user *)&rmt : NULL,
64726 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64727 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64728 set_fs(oldfs);
64729
64730 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64731 mm_segment_t old_fs = get_fs();
64732
64733 set_fs(KERNEL_DS);
64734 - ret = sys_sigpending((old_sigset_t __user *) &s);
64735 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64736 set_fs(old_fs);
64737 if (ret == 0)
64738 ret = put_user(s, set);
64739 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64740 mm_segment_t old_fs = get_fs();
64741
64742 set_fs(KERNEL_DS);
64743 - ret = sys_old_getrlimit(resource, &r);
64744 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64745 set_fs(old_fs);
64746
64747 if (!ret) {
64748 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64749 mm_segment_t old_fs = get_fs();
64750
64751 set_fs(KERNEL_DS);
64752 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64753 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64754 set_fs(old_fs);
64755
64756 if (ret)
64757 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64758 set_fs (KERNEL_DS);
64759 ret = sys_wait4(pid,
64760 (stat_addr ?
64761 - (unsigned int __user *) &status : NULL),
64762 - options, (struct rusage __user *) &r);
64763 + (unsigned int __force_user *) &status : NULL),
64764 + options, (struct rusage __force_user *) &r);
64765 set_fs (old_fs);
64766
64767 if (ret > 0) {
64768 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64769 memset(&info, 0, sizeof(info));
64770
64771 set_fs(KERNEL_DS);
64772 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64773 - uru ? (struct rusage __user *)&ru : NULL);
64774 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64775 + uru ? (struct rusage __force_user *)&ru : NULL);
64776 set_fs(old_fs);
64777
64778 if ((ret < 0) || (info.si_signo == 0))
64779 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64780 oldfs = get_fs();
64781 set_fs(KERNEL_DS);
64782 err = sys_timer_settime(timer_id, flags,
64783 - (struct itimerspec __user *) &newts,
64784 - (struct itimerspec __user *) &oldts);
64785 + (struct itimerspec __force_user *) &newts,
64786 + (struct itimerspec __force_user *) &oldts);
64787 set_fs(oldfs);
64788 if (!err && old && put_compat_itimerspec(old, &oldts))
64789 return -EFAULT;
64790 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64791 oldfs = get_fs();
64792 set_fs(KERNEL_DS);
64793 err = sys_timer_gettime(timer_id,
64794 - (struct itimerspec __user *) &ts);
64795 + (struct itimerspec __force_user *) &ts);
64796 set_fs(oldfs);
64797 if (!err && put_compat_itimerspec(setting, &ts))
64798 return -EFAULT;
64799 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64800 oldfs = get_fs();
64801 set_fs(KERNEL_DS);
64802 err = sys_clock_settime(which_clock,
64803 - (struct timespec __user *) &ts);
64804 + (struct timespec __force_user *) &ts);
64805 set_fs(oldfs);
64806 return err;
64807 }
64808 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64809 oldfs = get_fs();
64810 set_fs(KERNEL_DS);
64811 err = sys_clock_gettime(which_clock,
64812 - (struct timespec __user *) &ts);
64813 + (struct timespec __force_user *) &ts);
64814 set_fs(oldfs);
64815 if (!err && put_compat_timespec(&ts, tp))
64816 return -EFAULT;
64817 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64818
64819 oldfs = get_fs();
64820 set_fs(KERNEL_DS);
64821 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64822 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64823 set_fs(oldfs);
64824
64825 err = compat_put_timex(utp, &txc);
64826 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64827 oldfs = get_fs();
64828 set_fs(KERNEL_DS);
64829 err = sys_clock_getres(which_clock,
64830 - (struct timespec __user *) &ts);
64831 + (struct timespec __force_user *) &ts);
64832 set_fs(oldfs);
64833 if (!err && tp && put_compat_timespec(&ts, tp))
64834 return -EFAULT;
64835 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64836 long err;
64837 mm_segment_t oldfs;
64838 struct timespec tu;
64839 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64840 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64841
64842 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64843 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64844 oldfs = get_fs();
64845 set_fs(KERNEL_DS);
64846 err = clock_nanosleep_restart(restart);
64847 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64848 oldfs = get_fs();
64849 set_fs(KERNEL_DS);
64850 err = sys_clock_nanosleep(which_clock, flags,
64851 - (struct timespec __user *) &in,
64852 - (struct timespec __user *) &out);
64853 + (struct timespec __force_user *) &in,
64854 + (struct timespec __force_user *) &out);
64855 set_fs(oldfs);
64856
64857 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64858 diff --git a/kernel/configs.c b/kernel/configs.c
64859 index 42e8fa0..9e7406b 100644
64860 --- a/kernel/configs.c
64861 +++ b/kernel/configs.c
64862 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64863 struct proc_dir_entry *entry;
64864
64865 /* create the current config file */
64866 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64867 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64868 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64869 + &ikconfig_file_ops);
64870 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64871 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64872 + &ikconfig_file_ops);
64873 +#endif
64874 +#else
64875 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64876 &ikconfig_file_ops);
64877 +#endif
64878 +
64879 if (!entry)
64880 return -ENOMEM;
64881
64882 diff --git a/kernel/cred.c b/kernel/cred.c
64883 index e70683d..27761b6 100644
64884 --- a/kernel/cred.c
64885 +++ b/kernel/cred.c
64886 @@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
64887 validate_creds(cred);
64888 put_cred(cred);
64889 }
64890 +
64891 +#ifdef CONFIG_GRKERNSEC_SETXID
64892 + cred = (struct cred *) tsk->delayed_cred;
64893 + if (cred) {
64894 + tsk->delayed_cred = NULL;
64895 + validate_creds(cred);
64896 + put_cred(cred);
64897 + }
64898 +#endif
64899 }
64900
64901 /**
64902 @@ -473,7 +482,7 @@ error_put:
64903 * Always returns 0 thus allowing this function to be tail-called at the end
64904 * of, say, sys_setgid().
64905 */
64906 -int commit_creds(struct cred *new)
64907 +static int __commit_creds(struct cred *new)
64908 {
64909 struct task_struct *task = current;
64910 const struct cred *old = task->real_cred;
64911 @@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
64912
64913 get_cred(new); /* we will require a ref for the subj creds too */
64914
64915 + gr_set_role_label(task, new->uid, new->gid);
64916 +
64917 /* dumpability changes */
64918 if (old->euid != new->euid ||
64919 old->egid != new->egid ||
64920 @@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
64921 put_cred(old);
64922 return 0;
64923 }
64924 +#ifdef CONFIG_GRKERNSEC_SETXID
64925 +extern int set_user(struct cred *new);
64926 +
64927 +void gr_delayed_cred_worker(void)
64928 +{
64929 + const struct cred *new = current->delayed_cred;
64930 + struct cred *ncred;
64931 +
64932 + current->delayed_cred = NULL;
64933 +
64934 + if (current_uid() && new != NULL) {
64935 + // from doing get_cred on it when queueing this
64936 + put_cred(new);
64937 + return;
64938 + } else if (new == NULL)
64939 + return;
64940 +
64941 + ncred = prepare_creds();
64942 + if (!ncred)
64943 + goto die;
64944 + // uids
64945 + ncred->uid = new->uid;
64946 + ncred->euid = new->euid;
64947 + ncred->suid = new->suid;
64948 + ncred->fsuid = new->fsuid;
64949 + // gids
64950 + ncred->gid = new->gid;
64951 + ncred->egid = new->egid;
64952 + ncred->sgid = new->sgid;
64953 + ncred->fsgid = new->fsgid;
64954 + // groups
64955 + if (set_groups(ncred, new->group_info) < 0) {
64956 + abort_creds(ncred);
64957 + goto die;
64958 + }
64959 + // caps
64960 + ncred->securebits = new->securebits;
64961 + ncred->cap_inheritable = new->cap_inheritable;
64962 + ncred->cap_permitted = new->cap_permitted;
64963 + ncred->cap_effective = new->cap_effective;
64964 + ncred->cap_bset = new->cap_bset;
64965 +
64966 + if (set_user(ncred)) {
64967 + abort_creds(ncred);
64968 + goto die;
64969 + }
64970 +
64971 + // from doing get_cred on it when queueing this
64972 + put_cred(new);
64973 +
64974 + __commit_creds(ncred);
64975 + return;
64976 +die:
64977 + // from doing get_cred on it when queueing this
64978 + put_cred(new);
64979 + do_group_exit(SIGKILL);
64980 +}
64981 +#endif
64982 +
64983 +int commit_creds(struct cred *new)
64984 +{
64985 +#ifdef CONFIG_GRKERNSEC_SETXID
64986 + int ret;
64987 + int schedule_it = 0;
64988 + struct task_struct *t;
64989 +
64990 + /* we won't get called with tasklist_lock held for writing
64991 + and interrupts disabled as the cred struct in that case is
64992 + init_cred
64993 + */
64994 + if (grsec_enable_setxid && !current_is_single_threaded() &&
64995 + !current_uid() && new->uid) {
64996 + schedule_it = 1;
64997 + }
64998 + ret = __commit_creds(new);
64999 + if (schedule_it) {
65000 + rcu_read_lock();
65001 + read_lock(&tasklist_lock);
65002 + for (t = next_thread(current); t != current;
65003 + t = next_thread(t)) {
65004 + if (t->delayed_cred == NULL) {
65005 + t->delayed_cred = get_cred(new);
65006 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65007 + set_tsk_need_resched(t);
65008 + }
65009 + }
65010 + read_unlock(&tasklist_lock);
65011 + rcu_read_unlock();
65012 + }
65013 + return ret;
65014 +#else
65015 + return __commit_creds(new);
65016 +#endif
65017 +}
65018 +
65019 EXPORT_SYMBOL(commit_creds);
65020
65021 /**
65022 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65023 index 0557f24..1a00d9a 100644
65024 --- a/kernel/debug/debug_core.c
65025 +++ b/kernel/debug/debug_core.c
65026 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65027 */
65028 static atomic_t masters_in_kgdb;
65029 static atomic_t slaves_in_kgdb;
65030 -static atomic_t kgdb_break_tasklet_var;
65031 +static atomic_unchecked_t kgdb_break_tasklet_var;
65032 atomic_t kgdb_setting_breakpoint;
65033
65034 struct task_struct *kgdb_usethread;
65035 @@ -132,7 +132,7 @@ int kgdb_single_step;
65036 static pid_t kgdb_sstep_pid;
65037
65038 /* to keep track of the CPU which is doing the single stepping*/
65039 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65040 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65041
65042 /*
65043 * If you are debugging a problem where roundup (the collection of
65044 @@ -540,7 +540,7 @@ return_normal:
65045 * kernel will only try for the value of sstep_tries before
65046 * giving up and continuing on.
65047 */
65048 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65049 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65050 (kgdb_info[cpu].task &&
65051 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65052 atomic_set(&kgdb_active, -1);
65053 @@ -634,8 +634,8 @@ cpu_master_loop:
65054 }
65055
65056 kgdb_restore:
65057 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65058 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65059 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65060 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65061 if (kgdb_info[sstep_cpu].task)
65062 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65063 else
65064 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65065 static void kgdb_tasklet_bpt(unsigned long ing)
65066 {
65067 kgdb_breakpoint();
65068 - atomic_set(&kgdb_break_tasklet_var, 0);
65069 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65070 }
65071
65072 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65073
65074 void kgdb_schedule_breakpoint(void)
65075 {
65076 - if (atomic_read(&kgdb_break_tasklet_var) ||
65077 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65078 atomic_read(&kgdb_active) != -1 ||
65079 atomic_read(&kgdb_setting_breakpoint))
65080 return;
65081 - atomic_inc(&kgdb_break_tasklet_var);
65082 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65083 tasklet_schedule(&kgdb_tasklet_breakpoint);
65084 }
65085 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65086 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65087 index 67b847d..93834dd 100644
65088 --- a/kernel/debug/kdb/kdb_main.c
65089 +++ b/kernel/debug/kdb/kdb_main.c
65090 @@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65091 list_for_each_entry(mod, kdb_modules, list) {
65092
65093 kdb_printf("%-20s%8u 0x%p ", mod->name,
65094 - mod->core_size, (void *)mod);
65095 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65096 #ifdef CONFIG_MODULE_UNLOAD
65097 kdb_printf("%4ld ", module_refcount(mod));
65098 #endif
65099 @@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65100 kdb_printf(" (Loading)");
65101 else
65102 kdb_printf(" (Live)");
65103 - kdb_printf(" 0x%p", mod->module_core);
65104 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65105
65106 #ifdef CONFIG_MODULE_UNLOAD
65107 {
65108 diff --git a/kernel/events/core.c b/kernel/events/core.c
65109 index fd126f8..70b755b 100644
65110 --- a/kernel/events/core.c
65111 +++ b/kernel/events/core.c
65112 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65113 return 0;
65114 }
65115
65116 -static atomic64_t perf_event_id;
65117 +static atomic64_unchecked_t perf_event_id;
65118
65119 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65120 enum event_type_t event_type);
65121 @@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65122
65123 static inline u64 perf_event_count(struct perf_event *event)
65124 {
65125 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65126 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65127 }
65128
65129 static u64 perf_event_read(struct perf_event *event)
65130 @@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65131 mutex_lock(&event->child_mutex);
65132 total += perf_event_read(event);
65133 *enabled += event->total_time_enabled +
65134 - atomic64_read(&event->child_total_time_enabled);
65135 + atomic64_read_unchecked(&event->child_total_time_enabled);
65136 *running += event->total_time_running +
65137 - atomic64_read(&event->child_total_time_running);
65138 + atomic64_read_unchecked(&event->child_total_time_running);
65139
65140 list_for_each_entry(child, &event->child_list, child_list) {
65141 total += perf_event_read(child);
65142 @@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65143 userpg->offset -= local64_read(&event->hw.prev_count);
65144
65145 userpg->time_enabled = enabled +
65146 - atomic64_read(&event->child_total_time_enabled);
65147 + atomic64_read_unchecked(&event->child_total_time_enabled);
65148
65149 userpg->time_running = running +
65150 - atomic64_read(&event->child_total_time_running);
65151 + atomic64_read_unchecked(&event->child_total_time_running);
65152
65153 arch_perf_update_userpage(userpg, now);
65154
65155 @@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65156 values[n++] = perf_event_count(event);
65157 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65158 values[n++] = enabled +
65159 - atomic64_read(&event->child_total_time_enabled);
65160 + atomic64_read_unchecked(&event->child_total_time_enabled);
65161 }
65162 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65163 values[n++] = running +
65164 - atomic64_read(&event->child_total_time_running);
65165 + atomic64_read_unchecked(&event->child_total_time_running);
65166 }
65167 if (read_format & PERF_FORMAT_ID)
65168 values[n++] = primary_event_id(event);
65169 @@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65170 * need to add enough zero bytes after the string to handle
65171 * the 64bit alignment we do later.
65172 */
65173 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65174 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65175 if (!buf) {
65176 name = strncpy(tmp, "//enomem", sizeof(tmp));
65177 goto got_name;
65178 }
65179 - name = d_path(&file->f_path, buf, PATH_MAX);
65180 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65181 if (IS_ERR(name)) {
65182 name = strncpy(tmp, "//toolong", sizeof(tmp));
65183 goto got_name;
65184 @@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65185 event->parent = parent_event;
65186
65187 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65188 - event->id = atomic64_inc_return(&perf_event_id);
65189 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65190
65191 event->state = PERF_EVENT_STATE_INACTIVE;
65192
65193 @@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65194 /*
65195 * Add back the child's count to the parent's count:
65196 */
65197 - atomic64_add(child_val, &parent_event->child_count);
65198 - atomic64_add(child_event->total_time_enabled,
65199 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65200 + atomic64_add_unchecked(child_event->total_time_enabled,
65201 &parent_event->child_total_time_enabled);
65202 - atomic64_add(child_event->total_time_running,
65203 + atomic64_add_unchecked(child_event->total_time_running,
65204 &parent_event->child_total_time_running);
65205
65206 /*
65207 diff --git a/kernel/exit.c b/kernel/exit.c
65208 index 9d81012..d7911f1 100644
65209 --- a/kernel/exit.c
65210 +++ b/kernel/exit.c
65211 @@ -59,6 +59,10 @@
65212 #include <asm/pgtable.h>
65213 #include <asm/mmu_context.h>
65214
65215 +#ifdef CONFIG_GRKERNSEC
65216 +extern rwlock_t grsec_exec_file_lock;
65217 +#endif
65218 +
65219 static void exit_mm(struct task_struct * tsk);
65220
65221 static void __unhash_process(struct task_struct *p, bool group_dead)
65222 @@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65223 struct task_struct *leader;
65224 int zap_leader;
65225 repeat:
65226 +#ifdef CONFIG_NET
65227 + gr_del_task_from_ip_table(p);
65228 +#endif
65229 +
65230 /* don't need to get the RCU readlock here - the process is dead and
65231 * can't be modifying its own credentials. But shut RCU-lockdep up */
65232 rcu_read_lock();
65233 @@ -382,7 +390,7 @@ int allow_signal(int sig)
65234 * know it'll be handled, so that they don't get converted to
65235 * SIGKILL or just silently dropped.
65236 */
65237 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65238 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65239 recalc_sigpending();
65240 spin_unlock_irq(&current->sighand->siglock);
65241 return 0;
65242 @@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65243 vsnprintf(current->comm, sizeof(current->comm), name, args);
65244 va_end(args);
65245
65246 +#ifdef CONFIG_GRKERNSEC
65247 + write_lock(&grsec_exec_file_lock);
65248 + if (current->exec_file) {
65249 + fput(current->exec_file);
65250 + current->exec_file = NULL;
65251 + }
65252 + write_unlock(&grsec_exec_file_lock);
65253 +#endif
65254 +
65255 + gr_set_kernel_label(current);
65256 +
65257 /*
65258 * If we were started as result of loading a module, close all of the
65259 * user space pages. We don't need them, and if we didn't close them
65260 @@ -901,6 +920,8 @@ void do_exit(long code)
65261 struct task_struct *tsk = current;
65262 int group_dead;
65263
65264 + set_fs(USER_DS);
65265 +
65266 profile_task_exit(tsk);
65267
65268 WARN_ON(blk_needs_flush_plug(tsk));
65269 @@ -917,7 +938,6 @@ void do_exit(long code)
65270 * mm_release()->clear_child_tid() from writing to a user-controlled
65271 * kernel address.
65272 */
65273 - set_fs(USER_DS);
65274
65275 ptrace_event(PTRACE_EVENT_EXIT, code);
65276
65277 @@ -978,6 +998,9 @@ void do_exit(long code)
65278 tsk->exit_code = code;
65279 taskstats_exit(tsk, group_dead);
65280
65281 + gr_acl_handle_psacct(tsk, code);
65282 + gr_acl_handle_exit();
65283 +
65284 exit_mm(tsk);
65285
65286 if (group_dead)
65287 @@ -1094,7 +1117,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65288 * Take down every thread in the group. This is called by fatal signals
65289 * as well as by sys_exit_group (below).
65290 */
65291 -void
65292 +__noreturn void
65293 do_group_exit(int exit_code)
65294 {
65295 struct signal_struct *sig = current->signal;
65296 diff --git a/kernel/fork.c b/kernel/fork.c
65297 index 8163333..aee97f3 100644
65298 --- a/kernel/fork.c
65299 +++ b/kernel/fork.c
65300 @@ -274,19 +274,24 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65301 }
65302
65303 err = arch_dup_task_struct(tsk, orig);
65304 - if (err)
65305 - goto out;
65306
65307 + /*
65308 + * We defer looking at err, because we will need this setup
65309 + * for the clean up path to work correctly.
65310 + */
65311 tsk->stack = ti;
65312 -
65313 setup_thread_stack(tsk, orig);
65314 +
65315 + if (err)
65316 + goto out;
65317 +
65318 clear_user_return_notifier(tsk);
65319 clear_tsk_need_resched(tsk);
65320 stackend = end_of_stack(tsk);
65321 *stackend = STACK_END_MAGIC; /* for overflow detection */
65322
65323 #ifdef CONFIG_CC_STACKPROTECTOR
65324 - tsk->stack_canary = get_random_int();
65325 + tsk->stack_canary = pax_get_random_long();
65326 #endif
65327
65328 /*
65329 @@ -310,13 +315,78 @@ out:
65330 }
65331
65332 #ifdef CONFIG_MMU
65333 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
65334 +{
65335 + struct vm_area_struct *tmp;
65336 + unsigned long charge;
65337 + struct mempolicy *pol;
65338 + struct file *file;
65339 +
65340 + charge = 0;
65341 + if (mpnt->vm_flags & VM_ACCOUNT) {
65342 + unsigned long len;
65343 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65344 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65345 + goto fail_nomem;
65346 + charge = len;
65347 + }
65348 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65349 + if (!tmp)
65350 + goto fail_nomem;
65351 + *tmp = *mpnt;
65352 + tmp->vm_mm = mm;
65353 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
65354 + pol = mpol_dup(vma_policy(mpnt));
65355 + if (IS_ERR(pol))
65356 + goto fail_nomem_policy;
65357 + vma_set_policy(tmp, pol);
65358 + if (anon_vma_fork(tmp, mpnt))
65359 + goto fail_nomem_anon_vma_fork;
65360 + tmp->vm_flags &= ~VM_LOCKED;
65361 + tmp->vm_next = tmp->vm_prev = NULL;
65362 + tmp->vm_mirror = NULL;
65363 + file = tmp->vm_file;
65364 + if (file) {
65365 + struct inode *inode = file->f_path.dentry->d_inode;
65366 + struct address_space *mapping = file->f_mapping;
65367 +
65368 + get_file(file);
65369 + if (tmp->vm_flags & VM_DENYWRITE)
65370 + atomic_dec(&inode->i_writecount);
65371 + mutex_lock(&mapping->i_mmap_mutex);
65372 + if (tmp->vm_flags & VM_SHARED)
65373 + mapping->i_mmap_writable++;
65374 + flush_dcache_mmap_lock(mapping);
65375 + /* insert tmp into the share list, just after mpnt */
65376 + vma_prio_tree_add(tmp, mpnt);
65377 + flush_dcache_mmap_unlock(mapping);
65378 + mutex_unlock(&mapping->i_mmap_mutex);
65379 + }
65380 +
65381 + /*
65382 + * Clear hugetlb-related page reserves for children. This only
65383 + * affects MAP_PRIVATE mappings. Faults generated by the child
65384 + * are not guaranteed to succeed, even if read-only
65385 + */
65386 + if (is_vm_hugetlb_page(tmp))
65387 + reset_vma_resv_huge_pages(tmp);
65388 +
65389 + return tmp;
65390 +
65391 +fail_nomem_anon_vma_fork:
65392 + mpol_put(pol);
65393 +fail_nomem_policy:
65394 + kmem_cache_free(vm_area_cachep, tmp);
65395 +fail_nomem:
65396 + vm_unacct_memory(charge);
65397 + return NULL;
65398 +}
65399 +
65400 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65401 {
65402 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65403 struct rb_node **rb_link, *rb_parent;
65404 int retval;
65405 - unsigned long charge;
65406 - struct mempolicy *pol;
65407
65408 down_write(&oldmm->mmap_sem);
65409 flush_cache_dup_mm(oldmm);
65410 @@ -328,8 +398,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65411 mm->locked_vm = 0;
65412 mm->mmap = NULL;
65413 mm->mmap_cache = NULL;
65414 - mm->free_area_cache = oldmm->mmap_base;
65415 - mm->cached_hole_size = ~0UL;
65416 + mm->free_area_cache = oldmm->free_area_cache;
65417 + mm->cached_hole_size = oldmm->cached_hole_size;
65418 mm->map_count = 0;
65419 cpumask_clear(mm_cpumask(mm));
65420 mm->mm_rb = RB_ROOT;
65421 @@ -345,8 +415,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65422
65423 prev = NULL;
65424 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65425 - struct file *file;
65426 -
65427 if (mpnt->vm_flags & VM_DONTCOPY) {
65428 long pages = vma_pages(mpnt);
65429 mm->total_vm -= pages;
65430 @@ -354,54 +422,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65431 -pages);
65432 continue;
65433 }
65434 - charge = 0;
65435 - if (mpnt->vm_flags & VM_ACCOUNT) {
65436 - unsigned long len;
65437 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65438 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65439 - goto fail_nomem;
65440 - charge = len;
65441 + tmp = dup_vma(mm, oldmm, mpnt);
65442 + if (!tmp) {
65443 + retval = -ENOMEM;
65444 + goto out;
65445 }
65446 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65447 - if (!tmp)
65448 - goto fail_nomem;
65449 - *tmp = *mpnt;
65450 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
65451 - pol = mpol_dup(vma_policy(mpnt));
65452 - retval = PTR_ERR(pol);
65453 - if (IS_ERR(pol))
65454 - goto fail_nomem_policy;
65455 - vma_set_policy(tmp, pol);
65456 - tmp->vm_mm = mm;
65457 - if (anon_vma_fork(tmp, mpnt))
65458 - goto fail_nomem_anon_vma_fork;
65459 - tmp->vm_flags &= ~VM_LOCKED;
65460 - tmp->vm_next = tmp->vm_prev = NULL;
65461 - file = tmp->vm_file;
65462 - if (file) {
65463 - struct inode *inode = file->f_path.dentry->d_inode;
65464 - struct address_space *mapping = file->f_mapping;
65465 -
65466 - get_file(file);
65467 - if (tmp->vm_flags & VM_DENYWRITE)
65468 - atomic_dec(&inode->i_writecount);
65469 - mutex_lock(&mapping->i_mmap_mutex);
65470 - if (tmp->vm_flags & VM_SHARED)
65471 - mapping->i_mmap_writable++;
65472 - flush_dcache_mmap_lock(mapping);
65473 - /* insert tmp into the share list, just after mpnt */
65474 - vma_prio_tree_add(tmp, mpnt);
65475 - flush_dcache_mmap_unlock(mapping);
65476 - mutex_unlock(&mapping->i_mmap_mutex);
65477 - }
65478 -
65479 - /*
65480 - * Clear hugetlb-related page reserves for children. This only
65481 - * affects MAP_PRIVATE mappings. Faults generated by the child
65482 - * are not guaranteed to succeed, even if read-only
65483 - */
65484 - if (is_vm_hugetlb_page(tmp))
65485 - reset_vma_resv_huge_pages(tmp);
65486
65487 /*
65488 * Link in the new vma and copy the page table entries.
65489 @@ -424,6 +449,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65490 if (retval)
65491 goto out;
65492 }
65493 +
65494 +#ifdef CONFIG_PAX_SEGMEXEC
65495 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65496 + struct vm_area_struct *mpnt_m;
65497 +
65498 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65499 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65500 +
65501 + if (!mpnt->vm_mirror)
65502 + continue;
65503 +
65504 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65505 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65506 + mpnt->vm_mirror = mpnt_m;
65507 + } else {
65508 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65509 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65510 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65511 + mpnt->vm_mirror->vm_mirror = mpnt;
65512 + }
65513 + }
65514 + BUG_ON(mpnt_m);
65515 + }
65516 +#endif
65517 +
65518 /* a new mm has just been created */
65519 arch_dup_mmap(oldmm, mm);
65520 retval = 0;
65521 @@ -432,14 +482,6 @@ out:
65522 flush_tlb_mm(oldmm);
65523 up_write(&oldmm->mmap_sem);
65524 return retval;
65525 -fail_nomem_anon_vma_fork:
65526 - mpol_put(pol);
65527 -fail_nomem_policy:
65528 - kmem_cache_free(vm_area_cachep, tmp);
65529 -fail_nomem:
65530 - retval = -ENOMEM;
65531 - vm_unacct_memory(charge);
65532 - goto out;
65533 }
65534
65535 static inline int mm_alloc_pgd(struct mm_struct *mm)
65536 @@ -676,8 +718,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65537 return ERR_PTR(err);
65538
65539 mm = get_task_mm(task);
65540 - if (mm && mm != current->mm &&
65541 - !ptrace_may_access(task, mode)) {
65542 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65543 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65544 mmput(mm);
65545 mm = ERR_PTR(-EACCES);
65546 }
65547 @@ -899,13 +941,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65548 spin_unlock(&fs->lock);
65549 return -EAGAIN;
65550 }
65551 - fs->users++;
65552 + atomic_inc(&fs->users);
65553 spin_unlock(&fs->lock);
65554 return 0;
65555 }
65556 tsk->fs = copy_fs_struct(fs);
65557 if (!tsk->fs)
65558 return -ENOMEM;
65559 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65560 return 0;
65561 }
65562
65563 @@ -1172,6 +1215,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65564 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65565 #endif
65566 retval = -EAGAIN;
65567 +
65568 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65569 +
65570 if (atomic_read(&p->real_cred->user->processes) >=
65571 task_rlimit(p, RLIMIT_NPROC)) {
65572 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65573 @@ -1392,6 +1438,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65574 /* Need tasklist lock for parent etc handling! */
65575 write_lock_irq(&tasklist_lock);
65576
65577 + /* synchronizes with gr_set_acls() */
65578 + gr_copy_label(p);
65579 +
65580 /* CLONE_PARENT re-uses the old parent */
65581 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
65582 p->real_parent = current->real_parent;
65583 @@ -1502,6 +1551,8 @@ bad_fork_cleanup_count:
65584 bad_fork_free:
65585 free_task(p);
65586 fork_out:
65587 + gr_log_forkfail(retval);
65588 +
65589 return ERR_PTR(retval);
65590 }
65591
65592 @@ -1602,6 +1653,8 @@ long do_fork(unsigned long clone_flags,
65593 if (clone_flags & CLONE_PARENT_SETTID)
65594 put_user(nr, parent_tidptr);
65595
65596 + gr_handle_brute_check();
65597 +
65598 if (clone_flags & CLONE_VFORK) {
65599 p->vfork_done = &vfork;
65600 init_completion(&vfork);
65601 @@ -1700,7 +1753,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65602 return 0;
65603
65604 /* don't need lock here; in the worst case we'll do useless copy */
65605 - if (fs->users == 1)
65606 + if (atomic_read(&fs->users) == 1)
65607 return 0;
65608
65609 *new_fsp = copy_fs_struct(fs);
65610 @@ -1789,7 +1842,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65611 fs = current->fs;
65612 spin_lock(&fs->lock);
65613 current->fs = new_fs;
65614 - if (--fs->users)
65615 + gr_set_chroot_entries(current, &current->fs->root);
65616 + if (atomic_dec_return(&fs->users))
65617 new_fs = NULL;
65618 else
65619 new_fs = fs;
65620 diff --git a/kernel/futex.c b/kernel/futex.c
65621 index e2b0fb9..db818ac 100644
65622 --- a/kernel/futex.c
65623 +++ b/kernel/futex.c
65624 @@ -54,6 +54,7 @@
65625 #include <linux/mount.h>
65626 #include <linux/pagemap.h>
65627 #include <linux/syscalls.h>
65628 +#include <linux/ptrace.h>
65629 #include <linux/signal.h>
65630 #include <linux/export.h>
65631 #include <linux/magic.h>
65632 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65633 struct page *page, *page_head;
65634 int err, ro = 0;
65635
65636 +#ifdef CONFIG_PAX_SEGMEXEC
65637 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65638 + return -EFAULT;
65639 +#endif
65640 +
65641 /*
65642 * The futex address must be "naturally" aligned.
65643 */
65644 @@ -2711,6 +2717,7 @@ static int __init futex_init(void)
65645 {
65646 u32 curval;
65647 int i;
65648 + mm_segment_t oldfs;
65649
65650 /*
65651 * This will fail and we want it. Some arch implementations do
65652 @@ -2722,8 +2729,11 @@ static int __init futex_init(void)
65653 * implementation, the non-functional ones will return
65654 * -ENOSYS.
65655 */
65656 + oldfs = get_fs();
65657 + set_fs(USER_DS);
65658 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65659 futex_cmpxchg_enabled = 1;
65660 + set_fs(oldfs);
65661
65662 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65663 plist_head_init(&futex_queues[i].chain);
65664 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65665 index 9b22d03..6295b62 100644
65666 --- a/kernel/gcov/base.c
65667 +++ b/kernel/gcov/base.c
65668 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65669 }
65670
65671 #ifdef CONFIG_MODULES
65672 -static inline int within(void *addr, void *start, unsigned long size)
65673 -{
65674 - return ((addr >= start) && (addr < start + size));
65675 -}
65676 -
65677 /* Update list and generate events when modules are unloaded. */
65678 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65679 void *data)
65680 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65681 prev = NULL;
65682 /* Remove entries located in module from linked list. */
65683 for (info = gcov_info_head; info; info = info->next) {
65684 - if (within(info, mod->module_core, mod->core_size)) {
65685 + if (within_module_core_rw((unsigned long)info, mod)) {
65686 if (prev)
65687 prev->next = info->next;
65688 else
65689 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65690 index ae34bf5..4e2f3d0 100644
65691 --- a/kernel/hrtimer.c
65692 +++ b/kernel/hrtimer.c
65693 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65694 local_irq_restore(flags);
65695 }
65696
65697 -static void run_hrtimer_softirq(struct softirq_action *h)
65698 +static void run_hrtimer_softirq(void)
65699 {
65700 hrtimer_peek_ahead_timers();
65701 }
65702 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65703 index 4304919..408c4c0 100644
65704 --- a/kernel/jump_label.c
65705 +++ b/kernel/jump_label.c
65706 @@ -13,6 +13,7 @@
65707 #include <linux/sort.h>
65708 #include <linux/err.h>
65709 #include <linux/static_key.h>
65710 +#include <linux/mm.h>
65711
65712 #ifdef HAVE_JUMP_LABEL
65713
65714 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65715
65716 size = (((unsigned long)stop - (unsigned long)start)
65717 / sizeof(struct jump_entry));
65718 + pax_open_kernel();
65719 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65720 + pax_close_kernel();
65721 }
65722
65723 static void jump_label_update(struct static_key *key, int enable);
65724 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65725 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65726 struct jump_entry *iter;
65727
65728 + pax_open_kernel();
65729 for (iter = iter_start; iter < iter_stop; iter++) {
65730 if (within_module_init(iter->code, mod))
65731 iter->code = 0;
65732 }
65733 + pax_close_kernel();
65734 }
65735
65736 static int
65737 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65738 index 079f1d3..a407562 100644
65739 --- a/kernel/kallsyms.c
65740 +++ b/kernel/kallsyms.c
65741 @@ -11,6 +11,9 @@
65742 * Changed the compression method from stem compression to "table lookup"
65743 * compression (see scripts/kallsyms.c for a more complete description)
65744 */
65745 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65746 +#define __INCLUDED_BY_HIDESYM 1
65747 +#endif
65748 #include <linux/kallsyms.h>
65749 #include <linux/module.h>
65750 #include <linux/init.h>
65751 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65752
65753 static inline int is_kernel_inittext(unsigned long addr)
65754 {
65755 + if (system_state != SYSTEM_BOOTING)
65756 + return 0;
65757 +
65758 if (addr >= (unsigned long)_sinittext
65759 && addr <= (unsigned long)_einittext)
65760 return 1;
65761 return 0;
65762 }
65763
65764 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65765 +#ifdef CONFIG_MODULES
65766 +static inline int is_module_text(unsigned long addr)
65767 +{
65768 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65769 + return 1;
65770 +
65771 + addr = ktla_ktva(addr);
65772 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65773 +}
65774 +#else
65775 +static inline int is_module_text(unsigned long addr)
65776 +{
65777 + return 0;
65778 +}
65779 +#endif
65780 +#endif
65781 +
65782 static inline int is_kernel_text(unsigned long addr)
65783 {
65784 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65785 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65786
65787 static inline int is_kernel(unsigned long addr)
65788 {
65789 +
65790 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65791 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65792 + return 1;
65793 +
65794 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65795 +#else
65796 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65797 +#endif
65798 +
65799 return 1;
65800 return in_gate_area_no_mm(addr);
65801 }
65802
65803 static int is_ksym_addr(unsigned long addr)
65804 {
65805 +
65806 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65807 + if (is_module_text(addr))
65808 + return 0;
65809 +#endif
65810 +
65811 if (all_var)
65812 return is_kernel(addr);
65813
65814 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65815
65816 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65817 {
65818 - iter->name[0] = '\0';
65819 iter->nameoff = get_symbol_offset(new_pos);
65820 iter->pos = new_pos;
65821 }
65822 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65823 {
65824 struct kallsym_iter *iter = m->private;
65825
65826 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65827 + if (current_uid())
65828 + return 0;
65829 +#endif
65830 +
65831 /* Some debugging symbols have no name. Ignore them. */
65832 if (!iter->name[0])
65833 return 0;
65834 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65835 struct kallsym_iter *iter;
65836 int ret;
65837
65838 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65839 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65840 if (!iter)
65841 return -ENOMEM;
65842 reset_iter(iter, 0);
65843 diff --git a/kernel/kexec.c b/kernel/kexec.c
65844 index 4e2e472..cd0c7ae 100644
65845 --- a/kernel/kexec.c
65846 +++ b/kernel/kexec.c
65847 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65848 unsigned long flags)
65849 {
65850 struct compat_kexec_segment in;
65851 - struct kexec_segment out, __user *ksegments;
65852 + struct kexec_segment out;
65853 + struct kexec_segment __user *ksegments;
65854 unsigned long i, result;
65855
65856 /* Don't allow clients that don't understand the native
65857 diff --git a/kernel/kmod.c b/kernel/kmod.c
65858 index 05698a7..a4c1e3a 100644
65859 --- a/kernel/kmod.c
65860 +++ b/kernel/kmod.c
65861 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
65862 kfree(info->argv);
65863 }
65864
65865 -static int call_modprobe(char *module_name, int wait)
65866 +static int call_modprobe(char *module_name, char *module_param, int wait)
65867 {
65868 static char *envp[] = {
65869 "HOME=/",
65870 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
65871 NULL
65872 };
65873
65874 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
65875 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
65876 if (!argv)
65877 goto out;
65878
65879 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
65880 argv[1] = "-q";
65881 argv[2] = "--";
65882 argv[3] = module_name; /* check free_modprobe_argv() */
65883 - argv[4] = NULL;
65884 + argv[4] = module_param;
65885 + argv[5] = NULL;
65886
65887 return call_usermodehelper_fns(modprobe_path, argv, envp,
65888 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
65889 @@ -112,9 +113,8 @@ out:
65890 * If module auto-loading support is disabled then this function
65891 * becomes a no-operation.
65892 */
65893 -int __request_module(bool wait, const char *fmt, ...)
65894 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65895 {
65896 - va_list args;
65897 char module_name[MODULE_NAME_LEN];
65898 unsigned int max_modprobes;
65899 int ret;
65900 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
65901 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65902 static int kmod_loop_msg;
65903
65904 - va_start(args, fmt);
65905 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65906 - va_end(args);
65907 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65908 if (ret >= MODULE_NAME_LEN)
65909 return -ENAMETOOLONG;
65910
65911 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
65912 if (ret)
65913 return ret;
65914
65915 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65916 + if (!current_uid()) {
65917 + /* hack to workaround consolekit/udisks stupidity */
65918 + read_lock(&tasklist_lock);
65919 + if (!strcmp(current->comm, "mount") &&
65920 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65921 + read_unlock(&tasklist_lock);
65922 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65923 + return -EPERM;
65924 + }
65925 + read_unlock(&tasklist_lock);
65926 + }
65927 +#endif
65928 +
65929 /* If modprobe needs a service that is in a module, we get a recursive
65930 * loop. Limit the number of running kmod threads to max_threads/2 or
65931 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65932 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
65933
65934 trace_module_request(module_name, wait, _RET_IP_);
65935
65936 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
65937 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
65938
65939 atomic_dec(&kmod_concurrent);
65940 return ret;
65941 }
65942 +
65943 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65944 +{
65945 + va_list args;
65946 + int ret;
65947 +
65948 + va_start(args, fmt);
65949 + ret = ____request_module(wait, module_param, fmt, args);
65950 + va_end(args);
65951 +
65952 + return ret;
65953 +}
65954 +
65955 +int __request_module(bool wait, const char *fmt, ...)
65956 +{
65957 + va_list args;
65958 + int ret;
65959 +
65960 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65961 + if (current_uid()) {
65962 + char module_param[MODULE_NAME_LEN];
65963 +
65964 + memset(module_param, 0, sizeof(module_param));
65965 +
65966 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65967 +
65968 + va_start(args, fmt);
65969 + ret = ____request_module(wait, module_param, fmt, args);
65970 + va_end(args);
65971 +
65972 + return ret;
65973 + }
65974 +#endif
65975 +
65976 + va_start(args, fmt);
65977 + ret = ____request_module(wait, NULL, fmt, args);
65978 + va_end(args);
65979 +
65980 + return ret;
65981 +}
65982 +
65983 EXPORT_SYMBOL(__request_module);
65984 #endif /* CONFIG_MODULES */
65985
65986 @@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
65987 *
65988 * Thus the __user pointer cast is valid here.
65989 */
65990 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
65991 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
65992
65993 /*
65994 * If ret is 0, either ____call_usermodehelper failed and the
65995 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
65996 index c62b854..cb67968 100644
65997 --- a/kernel/kprobes.c
65998 +++ b/kernel/kprobes.c
65999 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66000 * kernel image and loaded module images reside. This is required
66001 * so x86_64 can correctly handle the %rip-relative fixups.
66002 */
66003 - kip->insns = module_alloc(PAGE_SIZE);
66004 + kip->insns = module_alloc_exec(PAGE_SIZE);
66005 if (!kip->insns) {
66006 kfree(kip);
66007 return NULL;
66008 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66009 */
66010 if (!list_is_singular(&kip->list)) {
66011 list_del(&kip->list);
66012 - module_free(NULL, kip->insns);
66013 + module_free_exec(NULL, kip->insns);
66014 kfree(kip);
66015 }
66016 return 1;
66017 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66018 {
66019 int i, err = 0;
66020 unsigned long offset = 0, size = 0;
66021 - char *modname, namebuf[128];
66022 + char *modname, namebuf[KSYM_NAME_LEN];
66023 const char *symbol_name;
66024 void *addr;
66025 struct kprobe_blackpoint *kb;
66026 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66027 const char *sym = NULL;
66028 unsigned int i = *(loff_t *) v;
66029 unsigned long offset = 0;
66030 - char *modname, namebuf[128];
66031 + char *modname, namebuf[KSYM_NAME_LEN];
66032
66033 head = &kprobe_table[i];
66034 preempt_disable();
66035 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66036 index 4e316e1..5501eef 100644
66037 --- a/kernel/ksysfs.c
66038 +++ b/kernel/ksysfs.c
66039 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66040 {
66041 if (count+1 > UEVENT_HELPER_PATH_LEN)
66042 return -ENOENT;
66043 + if (!capable(CAP_SYS_ADMIN))
66044 + return -EPERM;
66045 memcpy(uevent_helper, buf, count);
66046 uevent_helper[count] = '\0';
66047 if (count && uevent_helper[count-1] == '\n')
66048 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66049 index ea9ee45..67ebc8f 100644
66050 --- a/kernel/lockdep.c
66051 +++ b/kernel/lockdep.c
66052 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66053 end = (unsigned long) &_end,
66054 addr = (unsigned long) obj;
66055
66056 +#ifdef CONFIG_PAX_KERNEXEC
66057 + start = ktla_ktva(start);
66058 +#endif
66059 +
66060 /*
66061 * static variable?
66062 */
66063 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66064 if (!static_obj(lock->key)) {
66065 debug_locks_off();
66066 printk("INFO: trying to register non-static key.\n");
66067 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66068 printk("the code is fine but needs lockdep annotation.\n");
66069 printk("turning off the locking correctness validator.\n");
66070 dump_stack();
66071 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66072 if (!class)
66073 return 0;
66074 }
66075 - atomic_inc((atomic_t *)&class->ops);
66076 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66077 if (very_verbose(class)) {
66078 printk("\nacquire class [%p] %s", class->key, class->name);
66079 if (class->name_version > 1)
66080 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66081 index 91c32a0..b2c71c5 100644
66082 --- a/kernel/lockdep_proc.c
66083 +++ b/kernel/lockdep_proc.c
66084 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66085
66086 static void print_name(struct seq_file *m, struct lock_class *class)
66087 {
66088 - char str[128];
66089 + char str[KSYM_NAME_LEN];
66090 const char *name = class->name;
66091
66092 if (!name) {
66093 diff --git a/kernel/module.c b/kernel/module.c
66094 index 78ac6ec..e87db0e 100644
66095 --- a/kernel/module.c
66096 +++ b/kernel/module.c
66097 @@ -58,6 +58,7 @@
66098 #include <linux/jump_label.h>
66099 #include <linux/pfn.h>
66100 #include <linux/bsearch.h>
66101 +#include <linux/grsecurity.h>
66102
66103 #define CREATE_TRACE_POINTS
66104 #include <trace/events/module.h>
66105 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66106
66107 /* Bounds of module allocation, for speeding __module_address.
66108 * Protected by module_mutex. */
66109 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66110 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66111 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66112
66113 int register_module_notifier(struct notifier_block * nb)
66114 {
66115 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66116 return true;
66117
66118 list_for_each_entry_rcu(mod, &modules, list) {
66119 - struct symsearch arr[] = {
66120 + struct symsearch modarr[] = {
66121 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66122 NOT_GPL_ONLY, false },
66123 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66124 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66125 #endif
66126 };
66127
66128 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66129 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66130 return true;
66131 }
66132 return false;
66133 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66134 static int percpu_modalloc(struct module *mod,
66135 unsigned long size, unsigned long align)
66136 {
66137 - if (align > PAGE_SIZE) {
66138 + if (align-1 >= PAGE_SIZE) {
66139 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66140 mod->name, align, PAGE_SIZE);
66141 align = PAGE_SIZE;
66142 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66143 static ssize_t show_coresize(struct module_attribute *mattr,
66144 struct module_kobject *mk, char *buffer)
66145 {
66146 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66147 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66148 }
66149
66150 static struct module_attribute modinfo_coresize =
66151 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66152 static ssize_t show_initsize(struct module_attribute *mattr,
66153 struct module_kobject *mk, char *buffer)
66154 {
66155 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66156 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66157 }
66158
66159 static struct module_attribute modinfo_initsize =
66160 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66161 */
66162 #ifdef CONFIG_SYSFS
66163
66164 -#ifdef CONFIG_KALLSYMS
66165 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66166 static inline bool sect_empty(const Elf_Shdr *sect)
66167 {
66168 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66169 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66170
66171 static void unset_module_core_ro_nx(struct module *mod)
66172 {
66173 - set_page_attributes(mod->module_core + mod->core_text_size,
66174 - mod->module_core + mod->core_size,
66175 + set_page_attributes(mod->module_core_rw,
66176 + mod->module_core_rw + mod->core_size_rw,
66177 set_memory_x);
66178 - set_page_attributes(mod->module_core,
66179 - mod->module_core + mod->core_ro_size,
66180 + set_page_attributes(mod->module_core_rx,
66181 + mod->module_core_rx + mod->core_size_rx,
66182 set_memory_rw);
66183 }
66184
66185 static void unset_module_init_ro_nx(struct module *mod)
66186 {
66187 - set_page_attributes(mod->module_init + mod->init_text_size,
66188 - mod->module_init + mod->init_size,
66189 + set_page_attributes(mod->module_init_rw,
66190 + mod->module_init_rw + mod->init_size_rw,
66191 set_memory_x);
66192 - set_page_attributes(mod->module_init,
66193 - mod->module_init + mod->init_ro_size,
66194 + set_page_attributes(mod->module_init_rx,
66195 + mod->module_init_rx + mod->init_size_rx,
66196 set_memory_rw);
66197 }
66198
66199 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66200
66201 mutex_lock(&module_mutex);
66202 list_for_each_entry_rcu(mod, &modules, list) {
66203 - if ((mod->module_core) && (mod->core_text_size)) {
66204 - set_page_attributes(mod->module_core,
66205 - mod->module_core + mod->core_text_size,
66206 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66207 + set_page_attributes(mod->module_core_rx,
66208 + mod->module_core_rx + mod->core_size_rx,
66209 set_memory_rw);
66210 }
66211 - if ((mod->module_init) && (mod->init_text_size)) {
66212 - set_page_attributes(mod->module_init,
66213 - mod->module_init + mod->init_text_size,
66214 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66215 + set_page_attributes(mod->module_init_rx,
66216 + mod->module_init_rx + mod->init_size_rx,
66217 set_memory_rw);
66218 }
66219 }
66220 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66221
66222 mutex_lock(&module_mutex);
66223 list_for_each_entry_rcu(mod, &modules, list) {
66224 - if ((mod->module_core) && (mod->core_text_size)) {
66225 - set_page_attributes(mod->module_core,
66226 - mod->module_core + mod->core_text_size,
66227 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66228 + set_page_attributes(mod->module_core_rx,
66229 + mod->module_core_rx + mod->core_size_rx,
66230 set_memory_ro);
66231 }
66232 - if ((mod->module_init) && (mod->init_text_size)) {
66233 - set_page_attributes(mod->module_init,
66234 - mod->module_init + mod->init_text_size,
66235 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66236 + set_page_attributes(mod->module_init_rx,
66237 + mod->module_init_rx + mod->init_size_rx,
66238 set_memory_ro);
66239 }
66240 }
66241 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66242
66243 /* This may be NULL, but that's OK */
66244 unset_module_init_ro_nx(mod);
66245 - module_free(mod, mod->module_init);
66246 + module_free(mod, mod->module_init_rw);
66247 + module_free_exec(mod, mod->module_init_rx);
66248 kfree(mod->args);
66249 percpu_modfree(mod);
66250
66251 /* Free lock-classes: */
66252 - lockdep_free_key_range(mod->module_core, mod->core_size);
66253 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66254 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66255
66256 /* Finally, free the core (containing the module structure) */
66257 unset_module_core_ro_nx(mod);
66258 - module_free(mod, mod->module_core);
66259 + module_free_exec(mod, mod->module_core_rx);
66260 + module_free(mod, mod->module_core_rw);
66261
66262 #ifdef CONFIG_MPU
66263 update_protections(current->mm);
66264 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66265 int ret = 0;
66266 const struct kernel_symbol *ksym;
66267
66268 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66269 + int is_fs_load = 0;
66270 + int register_filesystem_found = 0;
66271 + char *p;
66272 +
66273 + p = strstr(mod->args, "grsec_modharden_fs");
66274 + if (p) {
66275 + char *endptr = p + strlen("grsec_modharden_fs");
66276 + /* copy \0 as well */
66277 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66278 + is_fs_load = 1;
66279 + }
66280 +#endif
66281 +
66282 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66283 const char *name = info->strtab + sym[i].st_name;
66284
66285 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66286 + /* it's a real shame this will never get ripped and copied
66287 + upstream! ;(
66288 + */
66289 + if (is_fs_load && !strcmp(name, "register_filesystem"))
66290 + register_filesystem_found = 1;
66291 +#endif
66292 +
66293 switch (sym[i].st_shndx) {
66294 case SHN_COMMON:
66295 /* We compiled with -fno-common. These are not
66296 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66297 ksym = resolve_symbol_wait(mod, info, name);
66298 /* Ok if resolved. */
66299 if (ksym && !IS_ERR(ksym)) {
66300 + pax_open_kernel();
66301 sym[i].st_value = ksym->value;
66302 + pax_close_kernel();
66303 break;
66304 }
66305
66306 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66307 secbase = (unsigned long)mod_percpu(mod);
66308 else
66309 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66310 + pax_open_kernel();
66311 sym[i].st_value += secbase;
66312 + pax_close_kernel();
66313 break;
66314 }
66315 }
66316
66317 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66318 + if (is_fs_load && !register_filesystem_found) {
66319 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66320 + ret = -EPERM;
66321 + }
66322 +#endif
66323 +
66324 return ret;
66325 }
66326
66327 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66328 || s->sh_entsize != ~0UL
66329 || strstarts(sname, ".init"))
66330 continue;
66331 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66332 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66333 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66334 + else
66335 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66336 pr_debug("\t%s\n", sname);
66337 }
66338 - switch (m) {
66339 - case 0: /* executable */
66340 - mod->core_size = debug_align(mod->core_size);
66341 - mod->core_text_size = mod->core_size;
66342 - break;
66343 - case 1: /* RO: text and ro-data */
66344 - mod->core_size = debug_align(mod->core_size);
66345 - mod->core_ro_size = mod->core_size;
66346 - break;
66347 - case 3: /* whole core */
66348 - mod->core_size = debug_align(mod->core_size);
66349 - break;
66350 - }
66351 }
66352
66353 pr_debug("Init section allocation order:\n");
66354 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66355 || s->sh_entsize != ~0UL
66356 || !strstarts(sname, ".init"))
66357 continue;
66358 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66359 - | INIT_OFFSET_MASK);
66360 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66361 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66362 + else
66363 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66364 + s->sh_entsize |= INIT_OFFSET_MASK;
66365 pr_debug("\t%s\n", sname);
66366 }
66367 - switch (m) {
66368 - case 0: /* executable */
66369 - mod->init_size = debug_align(mod->init_size);
66370 - mod->init_text_size = mod->init_size;
66371 - break;
66372 - case 1: /* RO: text and ro-data */
66373 - mod->init_size = debug_align(mod->init_size);
66374 - mod->init_ro_size = mod->init_size;
66375 - break;
66376 - case 3: /* whole init */
66377 - mod->init_size = debug_align(mod->init_size);
66378 - break;
66379 - }
66380 }
66381 }
66382
66383 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66384
66385 /* Put symbol section at end of init part of module. */
66386 symsect->sh_flags |= SHF_ALLOC;
66387 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66388 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66389 info->index.sym) | INIT_OFFSET_MASK;
66390 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66391
66392 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66393 }
66394
66395 /* Append room for core symbols at end of core part. */
66396 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66397 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66398 - mod->core_size += strtab_size;
66399 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66400 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66401 + mod->core_size_rx += strtab_size;
66402
66403 /* Put string table section at end of init part of module. */
66404 strsect->sh_flags |= SHF_ALLOC;
66405 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66406 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66407 info->index.str) | INIT_OFFSET_MASK;
66408 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66409 }
66410 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66411 /* Make sure we get permanent strtab: don't use info->strtab. */
66412 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66413
66414 + pax_open_kernel();
66415 +
66416 /* Set types up while we still have access to sections. */
66417 for (i = 0; i < mod->num_symtab; i++)
66418 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66419
66420 - mod->core_symtab = dst = mod->module_core + info->symoffs;
66421 - mod->core_strtab = s = mod->module_core + info->stroffs;
66422 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66423 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66424 src = mod->symtab;
66425 *dst = *src;
66426 *s++ = 0;
66427 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66428 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66429 }
66430 mod->core_num_syms = ndst;
66431 +
66432 + pax_close_kernel();
66433 }
66434 #else
66435 static inline void layout_symtab(struct module *mod, struct load_info *info)
66436 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
66437 return size == 0 ? NULL : vmalloc_exec(size);
66438 }
66439
66440 -static void *module_alloc_update_bounds(unsigned long size)
66441 +static void *module_alloc_update_bounds_rw(unsigned long size)
66442 {
66443 void *ret = module_alloc(size);
66444
66445 if (ret) {
66446 mutex_lock(&module_mutex);
66447 /* Update module bounds. */
66448 - if ((unsigned long)ret < module_addr_min)
66449 - module_addr_min = (unsigned long)ret;
66450 - if ((unsigned long)ret + size > module_addr_max)
66451 - module_addr_max = (unsigned long)ret + size;
66452 + if ((unsigned long)ret < module_addr_min_rw)
66453 + module_addr_min_rw = (unsigned long)ret;
66454 + if ((unsigned long)ret + size > module_addr_max_rw)
66455 + module_addr_max_rw = (unsigned long)ret + size;
66456 + mutex_unlock(&module_mutex);
66457 + }
66458 + return ret;
66459 +}
66460 +
66461 +static void *module_alloc_update_bounds_rx(unsigned long size)
66462 +{
66463 + void *ret = module_alloc_exec(size);
66464 +
66465 + if (ret) {
66466 + mutex_lock(&module_mutex);
66467 + /* Update module bounds. */
66468 + if ((unsigned long)ret < module_addr_min_rx)
66469 + module_addr_min_rx = (unsigned long)ret;
66470 + if ((unsigned long)ret + size > module_addr_max_rx)
66471 + module_addr_max_rx = (unsigned long)ret + size;
66472 mutex_unlock(&module_mutex);
66473 }
66474 return ret;
66475 @@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
66476 static int check_modinfo(struct module *mod, struct load_info *info)
66477 {
66478 const char *modmagic = get_modinfo(info, "vermagic");
66479 + const char *license = get_modinfo(info, "license");
66480 int err;
66481
66482 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66483 + if (!license || !license_is_gpl_compatible(license))
66484 + return -ENOEXEC;
66485 +#endif
66486 +
66487 /* This is allowed: modprobe --force will invalidate it. */
66488 if (!modmagic) {
66489 err = try_to_force_load(mod, "bad vermagic");
66490 @@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66491 }
66492
66493 /* Set up license info based on the info section */
66494 - set_license(mod, get_modinfo(info, "license"));
66495 + set_license(mod, license);
66496
66497 return 0;
66498 }
66499 @@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
66500 void *ptr;
66501
66502 /* Do the allocs. */
66503 - ptr = module_alloc_update_bounds(mod->core_size);
66504 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66505 /*
66506 * The pointer to this block is stored in the module structure
66507 * which is inside the block. Just mark it as not being a
66508 @@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
66509 if (!ptr)
66510 return -ENOMEM;
66511
66512 - memset(ptr, 0, mod->core_size);
66513 - mod->module_core = ptr;
66514 + memset(ptr, 0, mod->core_size_rw);
66515 + mod->module_core_rw = ptr;
66516
66517 - ptr = module_alloc_update_bounds(mod->init_size);
66518 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66519 /*
66520 * The pointer to this block is stored in the module structure
66521 * which is inside the block. This block doesn't need to be
66522 * scanned as it contains data and code that will be freed
66523 * after the module is initialized.
66524 */
66525 - kmemleak_ignore(ptr);
66526 - if (!ptr && mod->init_size) {
66527 - module_free(mod, mod->module_core);
66528 + kmemleak_not_leak(ptr);
66529 + if (!ptr && mod->init_size_rw) {
66530 + module_free(mod, mod->module_core_rw);
66531 return -ENOMEM;
66532 }
66533 - memset(ptr, 0, mod->init_size);
66534 - mod->module_init = ptr;
66535 + memset(ptr, 0, mod->init_size_rw);
66536 + mod->module_init_rw = ptr;
66537 +
66538 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66539 + kmemleak_not_leak(ptr);
66540 + if (!ptr) {
66541 + module_free(mod, mod->module_init_rw);
66542 + module_free(mod, mod->module_core_rw);
66543 + return -ENOMEM;
66544 + }
66545 +
66546 + pax_open_kernel();
66547 + memset(ptr, 0, mod->core_size_rx);
66548 + pax_close_kernel();
66549 + mod->module_core_rx = ptr;
66550 +
66551 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66552 + kmemleak_not_leak(ptr);
66553 + if (!ptr && mod->init_size_rx) {
66554 + module_free_exec(mod, mod->module_core_rx);
66555 + module_free(mod, mod->module_init_rw);
66556 + module_free(mod, mod->module_core_rw);
66557 + return -ENOMEM;
66558 + }
66559 +
66560 + pax_open_kernel();
66561 + memset(ptr, 0, mod->init_size_rx);
66562 + pax_close_kernel();
66563 + mod->module_init_rx = ptr;
66564
66565 /* Transfer each section which specifies SHF_ALLOC */
66566 pr_debug("final section addresses:\n");
66567 @@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
66568 if (!(shdr->sh_flags & SHF_ALLOC))
66569 continue;
66570
66571 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66572 - dest = mod->module_init
66573 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66574 - else
66575 - dest = mod->module_core + shdr->sh_entsize;
66576 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66577 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66578 + dest = mod->module_init_rw
66579 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66580 + else
66581 + dest = mod->module_init_rx
66582 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66583 + } else {
66584 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66585 + dest = mod->module_core_rw + shdr->sh_entsize;
66586 + else
66587 + dest = mod->module_core_rx + shdr->sh_entsize;
66588 + }
66589 +
66590 + if (shdr->sh_type != SHT_NOBITS) {
66591 +
66592 +#ifdef CONFIG_PAX_KERNEXEC
66593 +#ifdef CONFIG_X86_64
66594 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66595 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66596 +#endif
66597 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66598 + pax_open_kernel();
66599 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66600 + pax_close_kernel();
66601 + } else
66602 +#endif
66603
66604 - if (shdr->sh_type != SHT_NOBITS)
66605 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66606 + }
66607 /* Update sh_addr to point to copy in image. */
66608 - shdr->sh_addr = (unsigned long)dest;
66609 +
66610 +#ifdef CONFIG_PAX_KERNEXEC
66611 + if (shdr->sh_flags & SHF_EXECINSTR)
66612 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66613 + else
66614 +#endif
66615 +
66616 + shdr->sh_addr = (unsigned long)dest;
66617 pr_debug("\t0x%lx %s\n",
66618 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66619 }
66620 @@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
66621 * Do it before processing of module parameters, so the module
66622 * can provide parameter accessor functions of its own.
66623 */
66624 - if (mod->module_init)
66625 - flush_icache_range((unsigned long)mod->module_init,
66626 - (unsigned long)mod->module_init
66627 - + mod->init_size);
66628 - flush_icache_range((unsigned long)mod->module_core,
66629 - (unsigned long)mod->module_core + mod->core_size);
66630 + if (mod->module_init_rx)
66631 + flush_icache_range((unsigned long)mod->module_init_rx,
66632 + (unsigned long)mod->module_init_rx
66633 + + mod->init_size_rx);
66634 + flush_icache_range((unsigned long)mod->module_core_rx,
66635 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66636
66637 set_fs(old_fs);
66638 }
66639 @@ -2833,8 +2933,10 @@ out:
66640 static void module_deallocate(struct module *mod, struct load_info *info)
66641 {
66642 percpu_modfree(mod);
66643 - module_free(mod, mod->module_init);
66644 - module_free(mod, mod->module_core);
66645 + module_free_exec(mod, mod->module_init_rx);
66646 + module_free_exec(mod, mod->module_core_rx);
66647 + module_free(mod, mod->module_init_rw);
66648 + module_free(mod, mod->module_core_rw);
66649 }
66650
66651 int __weak module_finalize(const Elf_Ehdr *hdr,
66652 @@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
66653 if (err)
66654 goto free_unload;
66655
66656 + /* Now copy in args */
66657 + mod->args = strndup_user(uargs, ~0UL >> 1);
66658 + if (IS_ERR(mod->args)) {
66659 + err = PTR_ERR(mod->args);
66660 + goto free_unload;
66661 + }
66662 +
66663 /* Set up MODINFO_ATTR fields */
66664 setup_modinfo(mod, &info);
66665
66666 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66667 + {
66668 + char *p, *p2;
66669 +
66670 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66671 + 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);
66672 + err = -EPERM;
66673 + goto free_modinfo;
66674 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66675 + p += strlen("grsec_modharden_normal");
66676 + p2 = strstr(p, "_");
66677 + if (p2) {
66678 + *p2 = '\0';
66679 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66680 + *p2 = '_';
66681 + }
66682 + err = -EPERM;
66683 + goto free_modinfo;
66684 + }
66685 + }
66686 +#endif
66687 +
66688 /* Fix up syms, so that st_value is a pointer to location. */
66689 err = simplify_symbols(mod, &info);
66690 if (err < 0)
66691 @@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
66692
66693 flush_module_icache(mod);
66694
66695 - /* Now copy in args */
66696 - mod->args = strndup_user(uargs, ~0UL >> 1);
66697 - if (IS_ERR(mod->args)) {
66698 - err = PTR_ERR(mod->args);
66699 - goto free_arch_cleanup;
66700 - }
66701 -
66702 /* Mark state as coming so strong_try_module_get() ignores us. */
66703 mod->state = MODULE_STATE_COMING;
66704
66705 @@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
66706 unlock:
66707 mutex_unlock(&module_mutex);
66708 synchronize_sched();
66709 - kfree(mod->args);
66710 - free_arch_cleanup:
66711 module_arch_cleanup(mod);
66712 free_modinfo:
66713 free_modinfo(mod);
66714 + kfree(mod->args);
66715 free_unload:
66716 module_unload_free(mod);
66717 free_module:
66718 @@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66719 MODULE_STATE_COMING, mod);
66720
66721 /* Set RO and NX regions for core */
66722 - set_section_ro_nx(mod->module_core,
66723 - mod->core_text_size,
66724 - mod->core_ro_size,
66725 - mod->core_size);
66726 + set_section_ro_nx(mod->module_core_rx,
66727 + mod->core_size_rx,
66728 + mod->core_size_rx,
66729 + mod->core_size_rx);
66730
66731 /* Set RO and NX regions for init */
66732 - set_section_ro_nx(mod->module_init,
66733 - mod->init_text_size,
66734 - mod->init_ro_size,
66735 - mod->init_size);
66736 + set_section_ro_nx(mod->module_init_rx,
66737 + mod->init_size_rx,
66738 + mod->init_size_rx,
66739 + mod->init_size_rx);
66740
66741 do_mod_ctors(mod);
66742 /* Start the module */
66743 @@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66744 mod->strtab = mod->core_strtab;
66745 #endif
66746 unset_module_init_ro_nx(mod);
66747 - module_free(mod, mod->module_init);
66748 - mod->module_init = NULL;
66749 - mod->init_size = 0;
66750 - mod->init_ro_size = 0;
66751 - mod->init_text_size = 0;
66752 + module_free(mod, mod->module_init_rw);
66753 + module_free_exec(mod, mod->module_init_rx);
66754 + mod->module_init_rw = NULL;
66755 + mod->module_init_rx = NULL;
66756 + mod->init_size_rw = 0;
66757 + mod->init_size_rx = 0;
66758 mutex_unlock(&module_mutex);
66759
66760 return 0;
66761 @@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
66762 unsigned long nextval;
66763
66764 /* At worse, next value is at end of module */
66765 - if (within_module_init(addr, mod))
66766 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66767 + if (within_module_init_rx(addr, mod))
66768 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66769 + else if (within_module_init_rw(addr, mod))
66770 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66771 + else if (within_module_core_rx(addr, mod))
66772 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66773 + else if (within_module_core_rw(addr, mod))
66774 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66775 else
66776 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66777 + return NULL;
66778
66779 /* Scan for closest preceding symbol, and next symbol. (ELF
66780 starts real symbols at 1). */
66781 @@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
66782 char buf[8];
66783
66784 seq_printf(m, "%s %u",
66785 - mod->name, mod->init_size + mod->core_size);
66786 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66787 print_unload_info(m, mod);
66788
66789 /* Informative for users. */
66790 @@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
66791 mod->state == MODULE_STATE_COMING ? "Loading":
66792 "Live");
66793 /* Used by oprofile and other similar tools. */
66794 - seq_printf(m, " 0x%pK", mod->module_core);
66795 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66796
66797 /* Taints info */
66798 if (mod->taints)
66799 @@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
66800
66801 static int __init proc_modules_init(void)
66802 {
66803 +#ifndef CONFIG_GRKERNSEC_HIDESYM
66804 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66805 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66806 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66807 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66808 +#else
66809 proc_create("modules", 0, NULL, &proc_modules_operations);
66810 +#endif
66811 +#else
66812 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66813 +#endif
66814 return 0;
66815 }
66816 module_init(proc_modules_init);
66817 @@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
66818 {
66819 struct module *mod;
66820
66821 - if (addr < module_addr_min || addr > module_addr_max)
66822 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66823 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
66824 return NULL;
66825
66826 list_for_each_entry_rcu(mod, &modules, list)
66827 - if (within_module_core(addr, mod)
66828 - || within_module_init(addr, mod))
66829 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
66830 return mod;
66831 return NULL;
66832 }
66833 @@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
66834 */
66835 struct module *__module_text_address(unsigned long addr)
66836 {
66837 - struct module *mod = __module_address(addr);
66838 + struct module *mod;
66839 +
66840 +#ifdef CONFIG_X86_32
66841 + addr = ktla_ktva(addr);
66842 +#endif
66843 +
66844 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66845 + return NULL;
66846 +
66847 + mod = __module_address(addr);
66848 +
66849 if (mod) {
66850 /* Make sure it's within the text section. */
66851 - if (!within(addr, mod->module_init, mod->init_text_size)
66852 - && !within(addr, mod->module_core, mod->core_text_size))
66853 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66854 mod = NULL;
66855 }
66856 return mod;
66857 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66858 index 7e3443f..b2a1e6b 100644
66859 --- a/kernel/mutex-debug.c
66860 +++ b/kernel/mutex-debug.c
66861 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66862 }
66863
66864 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66865 - struct thread_info *ti)
66866 + struct task_struct *task)
66867 {
66868 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66869
66870 /* Mark the current thread as blocked on the lock: */
66871 - ti->task->blocked_on = waiter;
66872 + task->blocked_on = waiter;
66873 }
66874
66875 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66876 - struct thread_info *ti)
66877 + struct task_struct *task)
66878 {
66879 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66880 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66881 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66882 - ti->task->blocked_on = NULL;
66883 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
66884 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66885 + task->blocked_on = NULL;
66886
66887 list_del_init(&waiter->list);
66888 waiter->task = NULL;
66889 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66890 index 0799fd3..d06ae3b 100644
66891 --- a/kernel/mutex-debug.h
66892 +++ b/kernel/mutex-debug.h
66893 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66894 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66895 extern void debug_mutex_add_waiter(struct mutex *lock,
66896 struct mutex_waiter *waiter,
66897 - struct thread_info *ti);
66898 + struct task_struct *task);
66899 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66900 - struct thread_info *ti);
66901 + struct task_struct *task);
66902 extern void debug_mutex_unlock(struct mutex *lock);
66903 extern void debug_mutex_init(struct mutex *lock, const char *name,
66904 struct lock_class_key *key);
66905 diff --git a/kernel/mutex.c b/kernel/mutex.c
66906 index a307cc9..27fd2e9 100644
66907 --- a/kernel/mutex.c
66908 +++ b/kernel/mutex.c
66909 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66910 spin_lock_mutex(&lock->wait_lock, flags);
66911
66912 debug_mutex_lock_common(lock, &waiter);
66913 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66914 + debug_mutex_add_waiter(lock, &waiter, task);
66915
66916 /* add waiting tasks to the end of the waitqueue (FIFO): */
66917 list_add_tail(&waiter.list, &lock->wait_list);
66918 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66919 * TASK_UNINTERRUPTIBLE case.)
66920 */
66921 if (unlikely(signal_pending_state(state, task))) {
66922 - mutex_remove_waiter(lock, &waiter,
66923 - task_thread_info(task));
66924 + mutex_remove_waiter(lock, &waiter, task);
66925 mutex_release(&lock->dep_map, 1, ip);
66926 spin_unlock_mutex(&lock->wait_lock, flags);
66927
66928 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66929 done:
66930 lock_acquired(&lock->dep_map, ip);
66931 /* got the lock - rejoice! */
66932 - mutex_remove_waiter(lock, &waiter, current_thread_info());
66933 + mutex_remove_waiter(lock, &waiter, task);
66934 mutex_set_owner(lock);
66935
66936 /* set it to 0 if there are no waiters left: */
66937 diff --git a/kernel/panic.c b/kernel/panic.c
66938 index 9ed023b..e49543e 100644
66939 --- a/kernel/panic.c
66940 +++ b/kernel/panic.c
66941 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66942 const char *board;
66943
66944 printk(KERN_WARNING "------------[ cut here ]------------\n");
66945 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66946 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66947 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66948 if (board)
66949 printk(KERN_WARNING "Hardware name: %s\n", board);
66950 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66951 */
66952 void __stack_chk_fail(void)
66953 {
66954 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
66955 + dump_stack();
66956 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66957 __builtin_return_address(0));
66958 }
66959 EXPORT_SYMBOL(__stack_chk_fail);
66960 diff --git a/kernel/pid.c b/kernel/pid.c
66961 index 9f08dfa..6765c40 100644
66962 --- a/kernel/pid.c
66963 +++ b/kernel/pid.c
66964 @@ -33,6 +33,7 @@
66965 #include <linux/rculist.h>
66966 #include <linux/bootmem.h>
66967 #include <linux/hash.h>
66968 +#include <linux/security.h>
66969 #include <linux/pid_namespace.h>
66970 #include <linux/init_task.h>
66971 #include <linux/syscalls.h>
66972 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66973
66974 int pid_max = PID_MAX_DEFAULT;
66975
66976 -#define RESERVED_PIDS 300
66977 +#define RESERVED_PIDS 500
66978
66979 int pid_max_min = RESERVED_PIDS + 1;
66980 int pid_max_max = PID_MAX_LIMIT;
66981 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
66982 */
66983 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
66984 {
66985 + struct task_struct *task;
66986 +
66987 rcu_lockdep_assert(rcu_read_lock_held(),
66988 "find_task_by_pid_ns() needs rcu_read_lock()"
66989 " protection");
66990 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66991 +
66992 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66993 +
66994 + if (gr_pid_is_chrooted(task))
66995 + return NULL;
66996 +
66997 + return task;
66998 }
66999
67000 struct task_struct *find_task_by_vpid(pid_t vnr)
67001 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67002 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67003 }
67004
67005 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67006 +{
67007 + rcu_lockdep_assert(rcu_read_lock_held(),
67008 + "find_task_by_pid_ns() needs rcu_read_lock()"
67009 + " protection");
67010 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67011 +}
67012 +
67013 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67014 {
67015 struct pid *pid;
67016 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67017 index 125cb67..a4d1c30 100644
67018 --- a/kernel/posix-cpu-timers.c
67019 +++ b/kernel/posix-cpu-timers.c
67020 @@ -6,6 +6,7 @@
67021 #include <linux/posix-timers.h>
67022 #include <linux/errno.h>
67023 #include <linux/math64.h>
67024 +#include <linux/security.h>
67025 #include <asm/uaccess.h>
67026 #include <linux/kernel_stat.h>
67027 #include <trace/events/timer.h>
67028 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67029
67030 static __init int init_posix_cpu_timers(void)
67031 {
67032 - struct k_clock process = {
67033 + static struct k_clock process = {
67034 .clock_getres = process_cpu_clock_getres,
67035 .clock_get = process_cpu_clock_get,
67036 .timer_create = process_cpu_timer_create,
67037 .nsleep = process_cpu_nsleep,
67038 .nsleep_restart = process_cpu_nsleep_restart,
67039 };
67040 - struct k_clock thread = {
67041 + static struct k_clock thread = {
67042 .clock_getres = thread_cpu_clock_getres,
67043 .clock_get = thread_cpu_clock_get,
67044 .timer_create = thread_cpu_timer_create,
67045 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67046 index 69185ae..cc2847a 100644
67047 --- a/kernel/posix-timers.c
67048 +++ b/kernel/posix-timers.c
67049 @@ -43,6 +43,7 @@
67050 #include <linux/idr.h>
67051 #include <linux/posix-clock.h>
67052 #include <linux/posix-timers.h>
67053 +#include <linux/grsecurity.h>
67054 #include <linux/syscalls.h>
67055 #include <linux/wait.h>
67056 #include <linux/workqueue.h>
67057 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67058 * which we beg off on and pass to do_sys_settimeofday().
67059 */
67060
67061 -static struct k_clock posix_clocks[MAX_CLOCKS];
67062 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67063
67064 /*
67065 * These ones are defined below.
67066 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67067 */
67068 static __init int init_posix_timers(void)
67069 {
67070 - struct k_clock clock_realtime = {
67071 + static struct k_clock clock_realtime = {
67072 .clock_getres = hrtimer_get_res,
67073 .clock_get = posix_clock_realtime_get,
67074 .clock_set = posix_clock_realtime_set,
67075 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67076 .timer_get = common_timer_get,
67077 .timer_del = common_timer_del,
67078 };
67079 - struct k_clock clock_monotonic = {
67080 + static struct k_clock clock_monotonic = {
67081 .clock_getres = hrtimer_get_res,
67082 .clock_get = posix_ktime_get_ts,
67083 .nsleep = common_nsleep,
67084 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67085 .timer_get = common_timer_get,
67086 .timer_del = common_timer_del,
67087 };
67088 - struct k_clock clock_monotonic_raw = {
67089 + static struct k_clock clock_monotonic_raw = {
67090 .clock_getres = hrtimer_get_res,
67091 .clock_get = posix_get_monotonic_raw,
67092 };
67093 - struct k_clock clock_realtime_coarse = {
67094 + static struct k_clock clock_realtime_coarse = {
67095 .clock_getres = posix_get_coarse_res,
67096 .clock_get = posix_get_realtime_coarse,
67097 };
67098 - struct k_clock clock_monotonic_coarse = {
67099 + static struct k_clock clock_monotonic_coarse = {
67100 .clock_getres = posix_get_coarse_res,
67101 .clock_get = posix_get_monotonic_coarse,
67102 };
67103 - struct k_clock clock_boottime = {
67104 + static struct k_clock clock_boottime = {
67105 .clock_getres = hrtimer_get_res,
67106 .clock_get = posix_get_boottime,
67107 .nsleep = common_nsleep,
67108 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67109 return;
67110 }
67111
67112 - posix_clocks[clock_id] = *new_clock;
67113 + posix_clocks[clock_id] = new_clock;
67114 }
67115 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67116
67117 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67118 return (id & CLOCKFD_MASK) == CLOCKFD ?
67119 &clock_posix_dynamic : &clock_posix_cpu;
67120
67121 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67122 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67123 return NULL;
67124 - return &posix_clocks[id];
67125 + return posix_clocks[id];
67126 }
67127
67128 static int common_timer_create(struct k_itimer *new_timer)
67129 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67130 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67131 return -EFAULT;
67132
67133 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67134 + have their clock_set fptr set to a nosettime dummy function
67135 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67136 + call common_clock_set, which calls do_sys_settimeofday, which
67137 + we hook
67138 + */
67139 +
67140 return kc->clock_set(which_clock, &new_tp);
67141 }
67142
67143 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67144 index d523593..68197a4 100644
67145 --- a/kernel/power/poweroff.c
67146 +++ b/kernel/power/poweroff.c
67147 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67148 .enable_mask = SYSRQ_ENABLE_BOOT,
67149 };
67150
67151 -static int pm_sysrq_init(void)
67152 +static int __init pm_sysrq_init(void)
67153 {
67154 register_sysrq_key('o', &sysrq_poweroff_op);
67155 return 0;
67156 diff --git a/kernel/power/process.c b/kernel/power/process.c
67157 index 19db29f..33b52b6 100644
67158 --- a/kernel/power/process.c
67159 +++ b/kernel/power/process.c
67160 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67161 u64 elapsed_csecs64;
67162 unsigned int elapsed_csecs;
67163 bool wakeup = false;
67164 + bool timedout = false;
67165
67166 do_gettimeofday(&start);
67167
67168 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67169
67170 while (true) {
67171 todo = 0;
67172 + if (time_after(jiffies, end_time))
67173 + timedout = true;
67174 read_lock(&tasklist_lock);
67175 do_each_thread(g, p) {
67176 if (p == current || !freeze_task(p))
67177 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67178 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67179 * transition can't race with task state testing here.
67180 */
67181 - if (!task_is_stopped_or_traced(p) &&
67182 - !freezer_should_skip(p))
67183 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67184 todo++;
67185 + if (timedout) {
67186 + printk(KERN_ERR "Task refusing to freeze:\n");
67187 + sched_show_task(p);
67188 + }
67189 + }
67190 } while_each_thread(g, p);
67191 read_unlock(&tasklist_lock);
67192
67193 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67194 todo += wq_busy;
67195 }
67196
67197 - if (!todo || time_after(jiffies, end_time))
67198 + if (!todo || timedout)
67199 break;
67200
67201 if (pm_wakeup_pending()) {
67202 diff --git a/kernel/printk.c b/kernel/printk.c
67203 index b663c2c..1d6ba7a 100644
67204 --- a/kernel/printk.c
67205 +++ b/kernel/printk.c
67206 @@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67207 if (from_file && type != SYSLOG_ACTION_OPEN)
67208 return 0;
67209
67210 +#ifdef CONFIG_GRKERNSEC_DMESG
67211 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67212 + return -EPERM;
67213 +#endif
67214 +
67215 if (syslog_action_restricted(type)) {
67216 if (capable(CAP_SYSLOG))
67217 return 0;
67218 diff --git a/kernel/profile.c b/kernel/profile.c
67219 index 76b8e77..a2930e8 100644
67220 --- a/kernel/profile.c
67221 +++ b/kernel/profile.c
67222 @@ -39,7 +39,7 @@ struct profile_hit {
67223 /* Oprofile timer tick hook */
67224 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67225
67226 -static atomic_t *prof_buffer;
67227 +static atomic_unchecked_t *prof_buffer;
67228 static unsigned long prof_len, prof_shift;
67229
67230 int prof_on __read_mostly;
67231 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67232 hits[i].pc = 0;
67233 continue;
67234 }
67235 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67236 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67237 hits[i].hits = hits[i].pc = 0;
67238 }
67239 }
67240 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67241 * Add the current hit(s) and flush the write-queue out
67242 * to the global buffer:
67243 */
67244 - atomic_add(nr_hits, &prof_buffer[pc]);
67245 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67246 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67247 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67248 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67249 hits[i].pc = hits[i].hits = 0;
67250 }
67251 out:
67252 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67253 {
67254 unsigned long pc;
67255 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67256 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67257 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67258 }
67259 #endif /* !CONFIG_SMP */
67260
67261 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67262 return -EFAULT;
67263 buf++; p++; count--; read++;
67264 }
67265 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67266 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67267 if (copy_to_user(buf, (void *)pnt, count))
67268 return -EFAULT;
67269 read += count;
67270 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67271 }
67272 #endif
67273 profile_discard_flip_buffers();
67274 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67275 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67276 return count;
67277 }
67278
67279 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67280 index ee8d49b..bd3d790 100644
67281 --- a/kernel/ptrace.c
67282 +++ b/kernel/ptrace.c
67283 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67284
67285 if (seize)
67286 flags |= PT_SEIZED;
67287 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67288 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67289 flags |= PT_PTRACE_CAP;
67290 task->ptrace = flags;
67291
67292 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67293 break;
67294 return -EIO;
67295 }
67296 - if (copy_to_user(dst, buf, retval))
67297 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67298 return -EFAULT;
67299 copied += retval;
67300 src += retval;
67301 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
67302 bool seized = child->ptrace & PT_SEIZED;
67303 int ret = -EIO;
67304 siginfo_t siginfo, *si;
67305 - void __user *datavp = (void __user *) data;
67306 + void __user *datavp = (__force void __user *) data;
67307 unsigned long __user *datalp = datavp;
67308 unsigned long flags;
67309
67310 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67311 goto out;
67312 }
67313
67314 + if (gr_handle_ptrace(child, request)) {
67315 + ret = -EPERM;
67316 + goto out_put_task_struct;
67317 + }
67318 +
67319 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67320 ret = ptrace_attach(child, request, addr, data);
67321 /*
67322 * Some architectures need to do book-keeping after
67323 * a ptrace attach.
67324 */
67325 - if (!ret)
67326 + if (!ret) {
67327 arch_ptrace_attach(child);
67328 + gr_audit_ptrace(child);
67329 + }
67330 goto out_put_task_struct;
67331 }
67332
67333 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67334 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67335 if (copied != sizeof(tmp))
67336 return -EIO;
67337 - return put_user(tmp, (unsigned long __user *)data);
67338 + return put_user(tmp, (__force unsigned long __user *)data);
67339 }
67340
67341 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67342 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67343 goto out;
67344 }
67345
67346 + if (gr_handle_ptrace(child, request)) {
67347 + ret = -EPERM;
67348 + goto out_put_task_struct;
67349 + }
67350 +
67351 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67352 ret = ptrace_attach(child, request, addr, data);
67353 /*
67354 * Some architectures need to do book-keeping after
67355 * a ptrace attach.
67356 */
67357 - if (!ret)
67358 + if (!ret) {
67359 arch_ptrace_attach(child);
67360 + gr_audit_ptrace(child);
67361 + }
67362 goto out_put_task_struct;
67363 }
67364
67365 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67366 index 37a5444..eec170a 100644
67367 --- a/kernel/rcutiny.c
67368 +++ b/kernel/rcutiny.c
67369 @@ -46,7 +46,7 @@
67370 struct rcu_ctrlblk;
67371 static void invoke_rcu_callbacks(void);
67372 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67373 -static void rcu_process_callbacks(struct softirq_action *unused);
67374 +static void rcu_process_callbacks(void);
67375 static void __call_rcu(struct rcu_head *head,
67376 void (*func)(struct rcu_head *rcu),
67377 struct rcu_ctrlblk *rcp);
67378 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67379 rcu_is_callbacks_kthread()));
67380 }
67381
67382 -static void rcu_process_callbacks(struct softirq_action *unused)
67383 +static void rcu_process_callbacks(void)
67384 {
67385 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67386 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67387 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67388 index 22ecea0..3789898 100644
67389 --- a/kernel/rcutiny_plugin.h
67390 +++ b/kernel/rcutiny_plugin.h
67391 @@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
67392 have_rcu_kthread_work = morework;
67393 local_irq_restore(flags);
67394 if (work)
67395 - rcu_process_callbacks(NULL);
67396 + rcu_process_callbacks();
67397 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67398 }
67399
67400 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67401 index a89b381..efdcad8 100644
67402 --- a/kernel/rcutorture.c
67403 +++ b/kernel/rcutorture.c
67404 @@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67405 { 0 };
67406 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67407 { 0 };
67408 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67409 -static atomic_t n_rcu_torture_alloc;
67410 -static atomic_t n_rcu_torture_alloc_fail;
67411 -static atomic_t n_rcu_torture_free;
67412 -static atomic_t n_rcu_torture_mberror;
67413 -static atomic_t n_rcu_torture_error;
67414 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67415 +static atomic_unchecked_t n_rcu_torture_alloc;
67416 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
67417 +static atomic_unchecked_t n_rcu_torture_free;
67418 +static atomic_unchecked_t n_rcu_torture_mberror;
67419 +static atomic_unchecked_t n_rcu_torture_error;
67420 static long n_rcu_torture_boost_ktrerror;
67421 static long n_rcu_torture_boost_rterror;
67422 static long n_rcu_torture_boost_failure;
67423 @@ -253,11 +253,11 @@ rcu_torture_alloc(void)
67424
67425 spin_lock_bh(&rcu_torture_lock);
67426 if (list_empty(&rcu_torture_freelist)) {
67427 - atomic_inc(&n_rcu_torture_alloc_fail);
67428 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67429 spin_unlock_bh(&rcu_torture_lock);
67430 return NULL;
67431 }
67432 - atomic_inc(&n_rcu_torture_alloc);
67433 + atomic_inc_unchecked(&n_rcu_torture_alloc);
67434 p = rcu_torture_freelist.next;
67435 list_del_init(p);
67436 spin_unlock_bh(&rcu_torture_lock);
67437 @@ -270,7 +270,7 @@ rcu_torture_alloc(void)
67438 static void
67439 rcu_torture_free(struct rcu_torture *p)
67440 {
67441 - atomic_inc(&n_rcu_torture_free);
67442 + atomic_inc_unchecked(&n_rcu_torture_free);
67443 spin_lock_bh(&rcu_torture_lock);
67444 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67445 spin_unlock_bh(&rcu_torture_lock);
67446 @@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
67447 i = rp->rtort_pipe_count;
67448 if (i > RCU_TORTURE_PIPE_LEN)
67449 i = RCU_TORTURE_PIPE_LEN;
67450 - atomic_inc(&rcu_torture_wcount[i]);
67451 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67452 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67453 rp->rtort_mbtest = 0;
67454 rcu_torture_free(rp);
67455 @@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67456 i = rp->rtort_pipe_count;
67457 if (i > RCU_TORTURE_PIPE_LEN)
67458 i = RCU_TORTURE_PIPE_LEN;
67459 - atomic_inc(&rcu_torture_wcount[i]);
67460 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67461 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67462 rp->rtort_mbtest = 0;
67463 list_del(&rp->rtort_free);
67464 @@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
67465 i = old_rp->rtort_pipe_count;
67466 if (i > RCU_TORTURE_PIPE_LEN)
67467 i = RCU_TORTURE_PIPE_LEN;
67468 - atomic_inc(&rcu_torture_wcount[i]);
67469 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67470 old_rp->rtort_pipe_count++;
67471 cur_ops->deferred_free(old_rp);
67472 }
67473 @@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
67474 }
67475 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67476 if (p->rtort_mbtest == 0)
67477 - atomic_inc(&n_rcu_torture_mberror);
67478 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67479 spin_lock(&rand_lock);
67480 cur_ops->read_delay(&rand);
67481 n_rcu_torture_timers++;
67482 @@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
67483 }
67484 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67485 if (p->rtort_mbtest == 0)
67486 - atomic_inc(&n_rcu_torture_mberror);
67487 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67488 cur_ops->read_delay(&rand);
67489 preempt_disable();
67490 pipe_count = p->rtort_pipe_count;
67491 @@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
67492 rcu_torture_current,
67493 rcu_torture_current_version,
67494 list_empty(&rcu_torture_freelist),
67495 - atomic_read(&n_rcu_torture_alloc),
67496 - atomic_read(&n_rcu_torture_alloc_fail),
67497 - atomic_read(&n_rcu_torture_free),
67498 - atomic_read(&n_rcu_torture_mberror),
67499 + atomic_read_unchecked(&n_rcu_torture_alloc),
67500 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67501 + atomic_read_unchecked(&n_rcu_torture_free),
67502 + atomic_read_unchecked(&n_rcu_torture_mberror),
67503 n_rcu_torture_boost_ktrerror,
67504 n_rcu_torture_boost_rterror,
67505 n_rcu_torture_boost_failure,
67506 @@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
67507 n_online_attempts,
67508 n_offline_successes,
67509 n_offline_attempts);
67510 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67511 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67512 n_rcu_torture_boost_ktrerror != 0 ||
67513 n_rcu_torture_boost_rterror != 0 ||
67514 n_rcu_torture_boost_failure != 0)
67515 @@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
67516 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67517 if (i > 1) {
67518 cnt += sprintf(&page[cnt], "!!! ");
67519 - atomic_inc(&n_rcu_torture_error);
67520 + atomic_inc_unchecked(&n_rcu_torture_error);
67521 WARN_ON_ONCE(1);
67522 }
67523 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67524 @@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
67525 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67526 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67527 cnt += sprintf(&page[cnt], " %d",
67528 - atomic_read(&rcu_torture_wcount[i]));
67529 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67530 }
67531 cnt += sprintf(&page[cnt], "\n");
67532 if (cur_ops->stats)
67533 @@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
67534
67535 if (cur_ops->cleanup)
67536 cur_ops->cleanup();
67537 - if (atomic_read(&n_rcu_torture_error))
67538 + if (atomic_read_unchecked(&n_rcu_torture_error))
67539 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67540 else if (n_online_successes != n_online_attempts ||
67541 n_offline_successes != n_offline_attempts)
67542 @@ -1744,17 +1744,17 @@ rcu_torture_init(void)
67543
67544 rcu_torture_current = NULL;
67545 rcu_torture_current_version = 0;
67546 - atomic_set(&n_rcu_torture_alloc, 0);
67547 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67548 - atomic_set(&n_rcu_torture_free, 0);
67549 - atomic_set(&n_rcu_torture_mberror, 0);
67550 - atomic_set(&n_rcu_torture_error, 0);
67551 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67552 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67553 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67554 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67555 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67556 n_rcu_torture_boost_ktrerror = 0;
67557 n_rcu_torture_boost_rterror = 0;
67558 n_rcu_torture_boost_failure = 0;
67559 n_rcu_torture_boosts = 0;
67560 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67561 - atomic_set(&rcu_torture_wcount[i], 0);
67562 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67563 for_each_possible_cpu(cpu) {
67564 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67565 per_cpu(rcu_torture_count, cpu)[i] = 0;
67566 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67567 index d0c5baf..109b2e7 100644
67568 --- a/kernel/rcutree.c
67569 +++ b/kernel/rcutree.c
67570 @@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67571 rcu_prepare_for_idle(smp_processor_id());
67572 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67573 smp_mb__before_atomic_inc(); /* See above. */
67574 - atomic_inc(&rdtp->dynticks);
67575 + atomic_inc_unchecked(&rdtp->dynticks);
67576 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67577 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67578 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67579
67580 /*
67581 * The idle task is not permitted to enter the idle loop while
67582 @@ -448,10 +448,10 @@ void rcu_irq_exit(void)
67583 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67584 {
67585 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67586 - atomic_inc(&rdtp->dynticks);
67587 + atomic_inc_unchecked(&rdtp->dynticks);
67588 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67589 smp_mb__after_atomic_inc(); /* See above. */
67590 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67591 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67592 rcu_cleanup_after_idle(smp_processor_id());
67593 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67594 if (!is_idle_task(current)) {
67595 @@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
67596 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67597
67598 if (rdtp->dynticks_nmi_nesting == 0 &&
67599 - (atomic_read(&rdtp->dynticks) & 0x1))
67600 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67601 return;
67602 rdtp->dynticks_nmi_nesting++;
67603 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67604 - atomic_inc(&rdtp->dynticks);
67605 + atomic_inc_unchecked(&rdtp->dynticks);
67606 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67607 smp_mb__after_atomic_inc(); /* See above. */
67608 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67609 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67610 }
67611
67612 /**
67613 @@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
67614 return;
67615 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67616 smp_mb__before_atomic_inc(); /* See above. */
67617 - atomic_inc(&rdtp->dynticks);
67618 + atomic_inc_unchecked(&rdtp->dynticks);
67619 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67620 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67621 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67622 }
67623
67624 #ifdef CONFIG_PROVE_RCU
67625 @@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
67626 int ret;
67627
67628 preempt_disable();
67629 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67630 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67631 preempt_enable();
67632 return ret;
67633 }
67634 @@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67635 */
67636 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67637 {
67638 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67639 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67640 return (rdp->dynticks_snap & 0x1) == 0;
67641 }
67642
67643 @@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67644 unsigned int curr;
67645 unsigned int snap;
67646
67647 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67648 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67649 snap = (unsigned int)rdp->dynticks_snap;
67650
67651 /*
67652 @@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
67653 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
67654 */
67655 if (till_stall_check < 3) {
67656 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
67657 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
67658 till_stall_check = 3;
67659 } else if (till_stall_check > 300) {
67660 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
67661 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
67662 till_stall_check = 300;
67663 }
67664 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
67665 @@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67666 /*
67667 * Do RCU core processing for the current CPU.
67668 */
67669 -static void rcu_process_callbacks(struct softirq_action *unused)
67670 +static void rcu_process_callbacks(void)
67671 {
67672 trace_rcu_utilization("Start RCU core");
67673 __rcu_process_callbacks(&rcu_sched_state,
67674 @@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
67675 }
67676 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
67677
67678 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67679 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67680 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67681 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67682
67683 static int synchronize_sched_expedited_cpu_stop(void *data)
67684 {
67685 @@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
67686 int firstsnap, s, snap, trycount = 0;
67687
67688 /* Note that atomic_inc_return() implies full memory barrier. */
67689 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67690 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67691 get_online_cpus();
67692 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
67693
67694 @@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
67695 }
67696
67697 /* Check to see if someone else did our work for us. */
67698 - s = atomic_read(&sync_sched_expedited_done);
67699 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67700 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67701 smp_mb(); /* ensure test happens before caller kfree */
67702 return;
67703 @@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
67704 * grace period works for us.
67705 */
67706 get_online_cpus();
67707 - snap = atomic_read(&sync_sched_expedited_started);
67708 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
67709 smp_mb(); /* ensure read is before try_stop_cpus(). */
67710 }
67711
67712 @@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
67713 * than we did beat us to the punch.
67714 */
67715 do {
67716 - s = atomic_read(&sync_sched_expedited_done);
67717 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67718 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67719 smp_mb(); /* ensure test happens before caller kfree */
67720 break;
67721 }
67722 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67723 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67724
67725 put_online_cpus();
67726 }
67727 @@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67728 rdp->qlen = 0;
67729 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67730 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
67731 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67732 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67733 rdp->cpu = cpu;
67734 rdp->rsp = rsp;
67735 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67736 @@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67737 rdp->n_force_qs_snap = rsp->n_force_qs;
67738 rdp->blimit = blimit;
67739 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
67740 - atomic_set(&rdp->dynticks->dynticks,
67741 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67742 + atomic_set_unchecked(&rdp->dynticks->dynticks,
67743 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67744 rcu_prepare_for_idle_init(cpu);
67745 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67746
67747 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67748 index cdd1be0..5b2efb4 100644
67749 --- a/kernel/rcutree.h
67750 +++ b/kernel/rcutree.h
67751 @@ -87,7 +87,7 @@ struct rcu_dynticks {
67752 long long dynticks_nesting; /* Track irq/process nesting level. */
67753 /* Process level is worth LLONG_MAX/2. */
67754 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67755 - atomic_t dynticks; /* Even value for idle, else odd. */
67756 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67757 };
67758
67759 /* RCU's kthread states for tracing. */
67760 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67761 index c023464..7f57225 100644
67762 --- a/kernel/rcutree_plugin.h
67763 +++ b/kernel/rcutree_plugin.h
67764 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
67765
67766 /* Clean up and exit. */
67767 smp_mb(); /* ensure expedited GP seen before counter increment. */
67768 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67769 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67770 unlock_mb_ret:
67771 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67772 mb_ret:
67773 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67774 index ed459ed..a03c3fa 100644
67775 --- a/kernel/rcutree_trace.c
67776 +++ b/kernel/rcutree_trace.c
67777 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67778 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67779 rdp->qs_pending);
67780 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67781 - atomic_read(&rdp->dynticks->dynticks),
67782 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67783 rdp->dynticks->dynticks_nesting,
67784 rdp->dynticks->dynticks_nmi_nesting,
67785 rdp->dynticks_fqs);
67786 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67787 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67788 rdp->qs_pending);
67789 seq_printf(m, ",%d,%llx,%d,%lu",
67790 - atomic_read(&rdp->dynticks->dynticks),
67791 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67792 rdp->dynticks->dynticks_nesting,
67793 rdp->dynticks->dynticks_nmi_nesting,
67794 rdp->dynticks_fqs);
67795 diff --git a/kernel/resource.c b/kernel/resource.c
67796 index 7e8ea66..1efd11f 100644
67797 --- a/kernel/resource.c
67798 +++ b/kernel/resource.c
67799 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67800
67801 static int __init ioresources_init(void)
67802 {
67803 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67804 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67805 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67806 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67807 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67808 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67809 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67810 +#endif
67811 +#else
67812 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67813 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67814 +#endif
67815 return 0;
67816 }
67817 __initcall(ioresources_init);
67818 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67819 index 98ec494..4241d6d 100644
67820 --- a/kernel/rtmutex-tester.c
67821 +++ b/kernel/rtmutex-tester.c
67822 @@ -20,7 +20,7 @@
67823 #define MAX_RT_TEST_MUTEXES 8
67824
67825 static spinlock_t rttest_lock;
67826 -static atomic_t rttest_event;
67827 +static atomic_unchecked_t rttest_event;
67828
67829 struct test_thread_data {
67830 int opcode;
67831 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67832
67833 case RTTEST_LOCKCONT:
67834 td->mutexes[td->opdata] = 1;
67835 - td->event = atomic_add_return(1, &rttest_event);
67836 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67837 return 0;
67838
67839 case RTTEST_RESET:
67840 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67841 return 0;
67842
67843 case RTTEST_RESETEVENT:
67844 - atomic_set(&rttest_event, 0);
67845 + atomic_set_unchecked(&rttest_event, 0);
67846 return 0;
67847
67848 default:
67849 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67850 return ret;
67851
67852 td->mutexes[id] = 1;
67853 - td->event = atomic_add_return(1, &rttest_event);
67854 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67855 rt_mutex_lock(&mutexes[id]);
67856 - td->event = atomic_add_return(1, &rttest_event);
67857 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67858 td->mutexes[id] = 4;
67859 return 0;
67860
67861 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67862 return ret;
67863
67864 td->mutexes[id] = 1;
67865 - td->event = atomic_add_return(1, &rttest_event);
67866 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67867 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67868 - td->event = atomic_add_return(1, &rttest_event);
67869 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67870 td->mutexes[id] = ret ? 0 : 4;
67871 return ret ? -EINTR : 0;
67872
67873 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67874 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67875 return ret;
67876
67877 - td->event = atomic_add_return(1, &rttest_event);
67878 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67879 rt_mutex_unlock(&mutexes[id]);
67880 - td->event = atomic_add_return(1, &rttest_event);
67881 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67882 td->mutexes[id] = 0;
67883 return 0;
67884
67885 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67886 break;
67887
67888 td->mutexes[dat] = 2;
67889 - td->event = atomic_add_return(1, &rttest_event);
67890 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67891 break;
67892
67893 default:
67894 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67895 return;
67896
67897 td->mutexes[dat] = 3;
67898 - td->event = atomic_add_return(1, &rttest_event);
67899 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67900 break;
67901
67902 case RTTEST_LOCKNOWAIT:
67903 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67904 return;
67905
67906 td->mutexes[dat] = 1;
67907 - td->event = atomic_add_return(1, &rttest_event);
67908 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67909 return;
67910
67911 default:
67912 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67913 index 0984a21..939f183 100644
67914 --- a/kernel/sched/auto_group.c
67915 +++ b/kernel/sched/auto_group.c
67916 @@ -11,7 +11,7 @@
67917
67918 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67919 static struct autogroup autogroup_default;
67920 -static atomic_t autogroup_seq_nr;
67921 +static atomic_unchecked_t autogroup_seq_nr;
67922
67923 void __init autogroup_init(struct task_struct *init_task)
67924 {
67925 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67926
67927 kref_init(&ag->kref);
67928 init_rwsem(&ag->lock);
67929 - ag->id = atomic_inc_return(&autogroup_seq_nr);
67930 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67931 ag->tg = tg;
67932 #ifdef CONFIG_RT_GROUP_SCHED
67933 /*
67934 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
67935 index 2000e06..79cf3d8 100644
67936 --- a/kernel/sched/core.c
67937 +++ b/kernel/sched/core.c
67938 @@ -3907,6 +3907,8 @@ int can_nice(const struct task_struct *p, const int nice)
67939 /* convert nice value [19,-20] to rlimit style value [1,40] */
67940 int nice_rlim = 20 - nice;
67941
67942 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67943 +
67944 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67945 capable(CAP_SYS_NICE));
67946 }
67947 @@ -3940,7 +3942,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67948 if (nice > 19)
67949 nice = 19;
67950
67951 - if (increment < 0 && !can_nice(current, nice))
67952 + if (increment < 0 && (!can_nice(current, nice) ||
67953 + gr_handle_chroot_nice()))
67954 return -EPERM;
67955
67956 retval = security_task_setnice(current, nice);
67957 @@ -4097,6 +4100,7 @@ recheck:
67958 unsigned long rlim_rtprio =
67959 task_rlimit(p, RLIMIT_RTPRIO);
67960
67961 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67962 /* can't set/change the rt policy */
67963 if (policy != p->policy && !rlim_rtprio)
67964 return -EPERM;
67965 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
67966 index e955364..eacd2a4 100644
67967 --- a/kernel/sched/fair.c
67968 +++ b/kernel/sched/fair.c
67969 @@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67970 * run_rebalance_domains is triggered when needed from the scheduler tick.
67971 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67972 */
67973 -static void run_rebalance_domains(struct softirq_action *h)
67974 +static void run_rebalance_domains(void)
67975 {
67976 int this_cpu = smp_processor_id();
67977 struct rq *this_rq = cpu_rq(this_cpu);
67978 diff --git a/kernel/signal.c b/kernel/signal.c
67979 index 17afcaf..4500b05 100644
67980 --- a/kernel/signal.c
67981 +++ b/kernel/signal.c
67982 @@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
67983
67984 int print_fatal_signals __read_mostly;
67985
67986 -static void __user *sig_handler(struct task_struct *t, int sig)
67987 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
67988 {
67989 return t->sighand->action[sig - 1].sa.sa_handler;
67990 }
67991
67992 -static int sig_handler_ignored(void __user *handler, int sig)
67993 +static int sig_handler_ignored(__sighandler_t handler, int sig)
67994 {
67995 /* Is it explicitly or implicitly ignored? */
67996 return handler == SIG_IGN ||
67997 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
67998
67999 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68000 {
68001 - void __user *handler;
68002 + __sighandler_t handler;
68003
68004 handler = sig_handler(t, sig);
68005
68006 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68007 atomic_inc(&user->sigpending);
68008 rcu_read_unlock();
68009
68010 + if (!override_rlimit)
68011 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68012 +
68013 if (override_rlimit ||
68014 atomic_read(&user->sigpending) <=
68015 task_rlimit(t, RLIMIT_SIGPENDING)) {
68016 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68017
68018 int unhandled_signal(struct task_struct *tsk, int sig)
68019 {
68020 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68021 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68022 if (is_global_init(tsk))
68023 return 1;
68024 if (handler != SIG_IGN && handler != SIG_DFL)
68025 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68026 }
68027 }
68028
68029 + /* allow glibc communication via tgkill to other threads in our
68030 + thread group */
68031 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68032 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68033 + && gr_handle_signal(t, sig))
68034 + return -EPERM;
68035 +
68036 return security_task_kill(t, info, sig, 0);
68037 }
68038
68039 @@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68040 return send_signal(sig, info, p, 1);
68041 }
68042
68043 -static int
68044 +int
68045 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68046 {
68047 return send_signal(sig, info, t, 0);
68048 @@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68049 unsigned long int flags;
68050 int ret, blocked, ignored;
68051 struct k_sigaction *action;
68052 + int is_unhandled = 0;
68053
68054 spin_lock_irqsave(&t->sighand->siglock, flags);
68055 action = &t->sighand->action[sig-1];
68056 @@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68057 }
68058 if (action->sa.sa_handler == SIG_DFL)
68059 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68060 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68061 + is_unhandled = 1;
68062 ret = specific_send_sig_info(sig, info, t);
68063 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68064
68065 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68066 + normal operation */
68067 + if (is_unhandled) {
68068 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68069 + gr_handle_crash(t, sig);
68070 + }
68071 +
68072 return ret;
68073 }
68074
68075 @@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68076 ret = check_kill_permission(sig, info, p);
68077 rcu_read_unlock();
68078
68079 - if (!ret && sig)
68080 + if (!ret && sig) {
68081 ret = do_send_sig_info(sig, info, p, true);
68082 + if (!ret)
68083 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68084 + }
68085
68086 return ret;
68087 }
68088 @@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68089 int error = -ESRCH;
68090
68091 rcu_read_lock();
68092 - p = find_task_by_vpid(pid);
68093 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68094 + /* allow glibc communication via tgkill to other threads in our
68095 + thread group */
68096 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68097 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68098 + p = find_task_by_vpid_unrestricted(pid);
68099 + else
68100 +#endif
68101 + p = find_task_by_vpid(pid);
68102 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68103 error = check_kill_permission(sig, info, p);
68104 /*
68105 diff --git a/kernel/smp.c b/kernel/smp.c
68106 index 2f8b10e..a41bc14 100644
68107 --- a/kernel/smp.c
68108 +++ b/kernel/smp.c
68109 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68110 }
68111 EXPORT_SYMBOL(smp_call_function);
68112
68113 -void ipi_call_lock(void)
68114 +void ipi_call_lock(void) __acquires(call_function.lock)
68115 {
68116 raw_spin_lock(&call_function.lock);
68117 }
68118
68119 -void ipi_call_unlock(void)
68120 +void ipi_call_unlock(void) __releases(call_function.lock)
68121 {
68122 raw_spin_unlock(&call_function.lock);
68123 }
68124
68125 -void ipi_call_lock_irq(void)
68126 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68127 {
68128 raw_spin_lock_irq(&call_function.lock);
68129 }
68130
68131 -void ipi_call_unlock_irq(void)
68132 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68133 {
68134 raw_spin_unlock_irq(&call_function.lock);
68135 }
68136 diff --git a/kernel/softirq.c b/kernel/softirq.c
68137 index 671f959..91c51cb 100644
68138 --- a/kernel/softirq.c
68139 +++ b/kernel/softirq.c
68140 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68141
68142 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68143
68144 -char *softirq_to_name[NR_SOFTIRQS] = {
68145 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68146 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68147 "TASKLET", "SCHED", "HRTIMER", "RCU"
68148 };
68149 @@ -235,7 +235,7 @@ restart:
68150 kstat_incr_softirqs_this_cpu(vec_nr);
68151
68152 trace_softirq_entry(vec_nr);
68153 - h->action(h);
68154 + h->action();
68155 trace_softirq_exit(vec_nr);
68156 if (unlikely(prev_count != preempt_count())) {
68157 printk(KERN_ERR "huh, entered softirq %u %s %p"
68158 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68159 or_softirq_pending(1UL << nr);
68160 }
68161
68162 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68163 +void open_softirq(int nr, void (*action)(void))
68164 {
68165 - softirq_vec[nr].action = action;
68166 + pax_open_kernel();
68167 + *(void **)&softirq_vec[nr].action = action;
68168 + pax_close_kernel();
68169 }
68170
68171 /*
68172 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68173
68174 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68175
68176 -static void tasklet_action(struct softirq_action *a)
68177 +static void tasklet_action(void)
68178 {
68179 struct tasklet_struct *list;
68180
68181 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68182 }
68183 }
68184
68185 -static void tasklet_hi_action(struct softirq_action *a)
68186 +static void tasklet_hi_action(void)
68187 {
68188 struct tasklet_struct *list;
68189
68190 diff --git a/kernel/sys.c b/kernel/sys.c
68191 index e7006eb..8fb7c51 100644
68192 --- a/kernel/sys.c
68193 +++ b/kernel/sys.c
68194 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68195 error = -EACCES;
68196 goto out;
68197 }
68198 +
68199 + if (gr_handle_chroot_setpriority(p, niceval)) {
68200 + error = -EACCES;
68201 + goto out;
68202 + }
68203 +
68204 no_nice = security_task_setnice(p, niceval);
68205 if (no_nice) {
68206 error = no_nice;
68207 @@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68208 goto error;
68209 }
68210
68211 + if (gr_check_group_change(new->gid, new->egid, -1))
68212 + goto error;
68213 +
68214 if (rgid != (gid_t) -1 ||
68215 (egid != (gid_t) -1 && egid != old->gid))
68216 new->sgid = new->egid;
68217 @@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68218 old = current_cred();
68219
68220 retval = -EPERM;
68221 +
68222 + if (gr_check_group_change(gid, gid, gid))
68223 + goto error;
68224 +
68225 if (nsown_capable(CAP_SETGID))
68226 new->gid = new->egid = new->sgid = new->fsgid = gid;
68227 else if (gid == old->gid || gid == old->sgid)
68228 @@ -627,7 +640,7 @@ error:
68229 /*
68230 * change the user struct in a credentials set to match the new UID
68231 */
68232 -static int set_user(struct cred *new)
68233 +int set_user(struct cred *new)
68234 {
68235 struct user_struct *new_user;
68236
68237 @@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68238 goto error;
68239 }
68240
68241 + if (gr_check_user_change(new->uid, new->euid, -1))
68242 + goto error;
68243 +
68244 if (new->uid != old->uid) {
68245 retval = set_user(new);
68246 if (retval < 0)
68247 @@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68248 old = current_cred();
68249
68250 retval = -EPERM;
68251 +
68252 + if (gr_check_crash_uid(uid))
68253 + goto error;
68254 + if (gr_check_user_change(uid, uid, uid))
68255 + goto error;
68256 +
68257 if (nsown_capable(CAP_SETUID)) {
68258 new->suid = new->uid = uid;
68259 if (uid != old->uid) {
68260 @@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68261 goto error;
68262 }
68263
68264 + if (gr_check_user_change(ruid, euid, -1))
68265 + goto error;
68266 +
68267 if (ruid != (uid_t) -1) {
68268 new->uid = ruid;
68269 if (ruid != old->uid) {
68270 @@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68271 goto error;
68272 }
68273
68274 + if (gr_check_group_change(rgid, egid, -1))
68275 + goto error;
68276 +
68277 if (rgid != (gid_t) -1)
68278 new->gid = rgid;
68279 if (egid != (gid_t) -1)
68280 @@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68281 old = current_cred();
68282 old_fsuid = old->fsuid;
68283
68284 + if (gr_check_user_change(-1, -1, uid))
68285 + goto error;
68286 +
68287 if (uid == old->uid || uid == old->euid ||
68288 uid == old->suid || uid == old->fsuid ||
68289 nsown_capable(CAP_SETUID)) {
68290 @@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68291 }
68292 }
68293
68294 +error:
68295 abort_creds(new);
68296 return old_fsuid;
68297
68298 @@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68299 if (gid == old->gid || gid == old->egid ||
68300 gid == old->sgid || gid == old->fsgid ||
68301 nsown_capable(CAP_SETGID)) {
68302 + if (gr_check_group_change(-1, -1, gid))
68303 + goto error;
68304 +
68305 if (gid != old_fsgid) {
68306 new->fsgid = gid;
68307 goto change_okay;
68308 }
68309 }
68310
68311 +error:
68312 abort_creds(new);
68313 return old_fsgid;
68314
68315 @@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
68316 }
68317 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68318 snprintf(buf, len, "2.6.%u%s", v, rest);
68319 - ret = copy_to_user(release, buf, len);
68320 + if (len > sizeof(buf))
68321 + ret = -EFAULT;
68322 + else
68323 + ret = copy_to_user(release, buf, len);
68324 }
68325 return ret;
68326 }
68327 @@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68328 return -EFAULT;
68329
68330 down_read(&uts_sem);
68331 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
68332 + error = __copy_to_user(name->sysname, &utsname()->sysname,
68333 __OLD_UTS_LEN);
68334 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68335 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68336 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
68337 __OLD_UTS_LEN);
68338 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68339 - error |= __copy_to_user(&name->release, &utsname()->release,
68340 + error |= __copy_to_user(name->release, &utsname()->release,
68341 __OLD_UTS_LEN);
68342 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68343 - error |= __copy_to_user(&name->version, &utsname()->version,
68344 + error |= __copy_to_user(name->version, &utsname()->version,
68345 __OLD_UTS_LEN);
68346 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68347 - error |= __copy_to_user(&name->machine, &utsname()->machine,
68348 + error |= __copy_to_user(name->machine, &utsname()->machine,
68349 __OLD_UTS_LEN);
68350 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68351 up_read(&uts_sem);
68352 @@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68353 error = get_dumpable(me->mm);
68354 break;
68355 case PR_SET_DUMPABLE:
68356 - if (arg2 < 0 || arg2 > 1) {
68357 + if (arg2 > 1) {
68358 error = -EINVAL;
68359 break;
68360 }
68361 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68362 index 4ab1187..0b75ced 100644
68363 --- a/kernel/sysctl.c
68364 +++ b/kernel/sysctl.c
68365 @@ -91,7 +91,6 @@
68366
68367
68368 #if defined(CONFIG_SYSCTL)
68369 -
68370 /* External variables not in a header file. */
68371 extern int sysctl_overcommit_memory;
68372 extern int sysctl_overcommit_ratio;
68373 @@ -169,10 +168,8 @@ static int proc_taint(struct ctl_table *table, int write,
68374 void __user *buffer, size_t *lenp, loff_t *ppos);
68375 #endif
68376
68377 -#ifdef CONFIG_PRINTK
68378 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68379 void __user *buffer, size_t *lenp, loff_t *ppos);
68380 -#endif
68381
68382 #ifdef CONFIG_MAGIC_SYSRQ
68383 /* Note: sysrq code uses it's own private copy */
68384 @@ -196,6 +193,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68385
68386 #endif
68387
68388 +extern struct ctl_table grsecurity_table[];
68389 +
68390 static struct ctl_table kern_table[];
68391 static struct ctl_table vm_table[];
68392 static struct ctl_table fs_table[];
68393 @@ -210,6 +209,20 @@ extern struct ctl_table epoll_table[];
68394 int sysctl_legacy_va_layout;
68395 #endif
68396
68397 +#ifdef CONFIG_PAX_SOFTMODE
68398 +static ctl_table pax_table[] = {
68399 + {
68400 + .procname = "softmode",
68401 + .data = &pax_softmode,
68402 + .maxlen = sizeof(unsigned int),
68403 + .mode = 0600,
68404 + .proc_handler = &proc_dointvec,
68405 + },
68406 +
68407 + { }
68408 +};
68409 +#endif
68410 +
68411 /* The default sysctl tables: */
68412
68413 static struct ctl_table sysctl_base_table[] = {
68414 @@ -256,6 +269,22 @@ static int max_extfrag_threshold = 1000;
68415 #endif
68416
68417 static struct ctl_table kern_table[] = {
68418 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68419 + {
68420 + .procname = "grsecurity",
68421 + .mode = 0500,
68422 + .child = grsecurity_table,
68423 + },
68424 +#endif
68425 +
68426 +#ifdef CONFIG_PAX_SOFTMODE
68427 + {
68428 + .procname = "pax",
68429 + .mode = 0500,
68430 + .child = pax_table,
68431 + },
68432 +#endif
68433 +
68434 {
68435 .procname = "sched_child_runs_first",
68436 .data = &sysctl_sched_child_runs_first,
68437 @@ -540,7 +569,7 @@ static struct ctl_table kern_table[] = {
68438 .data = &modprobe_path,
68439 .maxlen = KMOD_PATH_LEN,
68440 .mode = 0644,
68441 - .proc_handler = proc_dostring,
68442 + .proc_handler = proc_dostring_modpriv,
68443 },
68444 {
68445 .procname = "modules_disabled",
68446 @@ -707,16 +736,20 @@ static struct ctl_table kern_table[] = {
68447 .extra1 = &zero,
68448 .extra2 = &one,
68449 },
68450 +#endif
68451 {
68452 .procname = "kptr_restrict",
68453 .data = &kptr_restrict,
68454 .maxlen = sizeof(int),
68455 .mode = 0644,
68456 .proc_handler = proc_dointvec_minmax_sysadmin,
68457 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68458 + .extra1 = &two,
68459 +#else
68460 .extra1 = &zero,
68461 +#endif
68462 .extra2 = &two,
68463 },
68464 -#endif
68465 {
68466 .procname = "ngroups_max",
68467 .data = &ngroups_max,
68468 @@ -1215,6 +1248,13 @@ static struct ctl_table vm_table[] = {
68469 .proc_handler = proc_dointvec_minmax,
68470 .extra1 = &zero,
68471 },
68472 + {
68473 + .procname = "heap_stack_gap",
68474 + .data = &sysctl_heap_stack_gap,
68475 + .maxlen = sizeof(sysctl_heap_stack_gap),
68476 + .mode = 0644,
68477 + .proc_handler = proc_doulongvec_minmax,
68478 + },
68479 #else
68480 {
68481 .procname = "nr_trim_pages",
68482 @@ -1645,6 +1685,16 @@ int proc_dostring(struct ctl_table *table, int write,
68483 buffer, lenp, ppos);
68484 }
68485
68486 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68487 + void __user *buffer, size_t *lenp, loff_t *ppos)
68488 +{
68489 + if (write && !capable(CAP_SYS_MODULE))
68490 + return -EPERM;
68491 +
68492 + return _proc_do_string(table->data, table->maxlen, write,
68493 + buffer, lenp, ppos);
68494 +}
68495 +
68496 static size_t proc_skip_spaces(char **buf)
68497 {
68498 size_t ret;
68499 @@ -1750,6 +1800,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68500 len = strlen(tmp);
68501 if (len > *size)
68502 len = *size;
68503 + if (len > sizeof(tmp))
68504 + len = sizeof(tmp);
68505 if (copy_to_user(*buf, tmp, len))
68506 return -EFAULT;
68507 *size -= len;
68508 @@ -1942,7 +1994,6 @@ static int proc_taint(struct ctl_table *table, int write,
68509 return err;
68510 }
68511
68512 -#ifdef CONFIG_PRINTK
68513 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68514 void __user *buffer, size_t *lenp, loff_t *ppos)
68515 {
68516 @@ -1951,7 +2002,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68517
68518 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
68519 }
68520 -#endif
68521
68522 struct do_proc_dointvec_minmax_conv_param {
68523 int *min;
68524 @@ -2066,8 +2116,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68525 *i = val;
68526 } else {
68527 val = convdiv * (*i) / convmul;
68528 - if (!first)
68529 + if (!first) {
68530 err = proc_put_char(&buffer, &left, '\t');
68531 + if (err)
68532 + break;
68533 + }
68534 err = proc_put_long(&buffer, &left, val, false);
68535 if (err)
68536 break;
68537 @@ -2459,6 +2512,12 @@ int proc_dostring(struct ctl_table *table, int write,
68538 return -ENOSYS;
68539 }
68540
68541 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68542 + void __user *buffer, size_t *lenp, loff_t *ppos)
68543 +{
68544 + return -ENOSYS;
68545 +}
68546 +
68547 int proc_dointvec(struct ctl_table *table, int write,
68548 void __user *buffer, size_t *lenp, loff_t *ppos)
68549 {
68550 @@ -2515,5 +2574,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68551 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68552 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68553 EXPORT_SYMBOL(proc_dostring);
68554 +EXPORT_SYMBOL(proc_dostring_modpriv);
68555 EXPORT_SYMBOL(proc_doulongvec_minmax);
68556 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68557 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68558 index a650694..aaeeb20 100644
68559 --- a/kernel/sysctl_binary.c
68560 +++ b/kernel/sysctl_binary.c
68561 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68562 int i;
68563
68564 set_fs(KERNEL_DS);
68565 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68566 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68567 set_fs(old_fs);
68568 if (result < 0)
68569 goto out_kfree;
68570 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68571 }
68572
68573 set_fs(KERNEL_DS);
68574 - result = vfs_write(file, buffer, str - buffer, &pos);
68575 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68576 set_fs(old_fs);
68577 if (result < 0)
68578 goto out_kfree;
68579 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68580 int i;
68581
68582 set_fs(KERNEL_DS);
68583 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68584 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68585 set_fs(old_fs);
68586 if (result < 0)
68587 goto out_kfree;
68588 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68589 }
68590
68591 set_fs(KERNEL_DS);
68592 - result = vfs_write(file, buffer, str - buffer, &pos);
68593 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68594 set_fs(old_fs);
68595 if (result < 0)
68596 goto out_kfree;
68597 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68598 int i;
68599
68600 set_fs(KERNEL_DS);
68601 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68602 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68603 set_fs(old_fs);
68604 if (result < 0)
68605 goto out;
68606 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68607 __le16 dnaddr;
68608
68609 set_fs(KERNEL_DS);
68610 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68611 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68612 set_fs(old_fs);
68613 if (result < 0)
68614 goto out;
68615 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68616 le16_to_cpu(dnaddr) & 0x3ff);
68617
68618 set_fs(KERNEL_DS);
68619 - result = vfs_write(file, buf, len, &pos);
68620 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68621 set_fs(old_fs);
68622 if (result < 0)
68623 goto out;
68624 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68625 index e660464..c8b9e67 100644
68626 --- a/kernel/taskstats.c
68627 +++ b/kernel/taskstats.c
68628 @@ -27,9 +27,12 @@
68629 #include <linux/cgroup.h>
68630 #include <linux/fs.h>
68631 #include <linux/file.h>
68632 +#include <linux/grsecurity.h>
68633 #include <net/genetlink.h>
68634 #include <linux/atomic.h>
68635
68636 +extern int gr_is_taskstats_denied(int pid);
68637 +
68638 /*
68639 * Maximum length of a cpumask that can be specified in
68640 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68641 @@ -556,6 +559,9 @@ err:
68642
68643 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68644 {
68645 + if (gr_is_taskstats_denied(current->pid))
68646 + return -EACCES;
68647 +
68648 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68649 return cmd_attr_register_cpumask(info);
68650 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68651 diff --git a/kernel/time.c b/kernel/time.c
68652 index ba744cf..267b7c5 100644
68653 --- a/kernel/time.c
68654 +++ b/kernel/time.c
68655 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68656 return error;
68657
68658 if (tz) {
68659 + /* we log in do_settimeofday called below, so don't log twice
68660 + */
68661 + if (!tv)
68662 + gr_log_timechange();
68663 +
68664 sys_tz = *tz;
68665 update_vsyscall_tz();
68666 if (firsttime) {
68667 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68668 index 8a538c5..def79d4 100644
68669 --- a/kernel/time/alarmtimer.c
68670 +++ b/kernel/time/alarmtimer.c
68671 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
68672 struct platform_device *pdev;
68673 int error = 0;
68674 int i;
68675 - struct k_clock alarm_clock = {
68676 + static struct k_clock alarm_clock = {
68677 .clock_getres = alarm_clock_getres,
68678 .clock_get = alarm_clock_get,
68679 .timer_create = alarm_timer_create,
68680 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68681 index f113755..ec24223 100644
68682 --- a/kernel/time/tick-broadcast.c
68683 +++ b/kernel/time/tick-broadcast.c
68684 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68685 * then clear the broadcast bit.
68686 */
68687 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68688 - int cpu = smp_processor_id();
68689 + cpu = smp_processor_id();
68690
68691 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68692 tick_broadcast_clear_oneshot(cpu);
68693 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68694 index d42574df..247414c 100644
68695 --- a/kernel/time/timekeeping.c
68696 +++ b/kernel/time/timekeeping.c
68697 @@ -14,6 +14,7 @@
68698 #include <linux/init.h>
68699 #include <linux/mm.h>
68700 #include <linux/sched.h>
68701 +#include <linux/grsecurity.h>
68702 #include <linux/syscore_ops.h>
68703 #include <linux/clocksource.h>
68704 #include <linux/jiffies.h>
68705 @@ -373,6 +374,8 @@ int do_settimeofday(const struct timespec *tv)
68706 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68707 return -EINVAL;
68708
68709 + gr_log_timechange();
68710 +
68711 write_seqlock_irqsave(&timekeeper.lock, flags);
68712
68713 timekeeping_forward_now();
68714 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68715 index 3258455..f35227d 100644
68716 --- a/kernel/time/timer_list.c
68717 +++ b/kernel/time/timer_list.c
68718 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68719
68720 static void print_name_offset(struct seq_file *m, void *sym)
68721 {
68722 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68723 + SEQ_printf(m, "<%p>", NULL);
68724 +#else
68725 char symname[KSYM_NAME_LEN];
68726
68727 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68728 SEQ_printf(m, "<%pK>", sym);
68729 else
68730 SEQ_printf(m, "%s", symname);
68731 +#endif
68732 }
68733
68734 static void
68735 @@ -112,7 +116,11 @@ next_one:
68736 static void
68737 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68738 {
68739 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68740 + SEQ_printf(m, " .base: %p\n", NULL);
68741 +#else
68742 SEQ_printf(m, " .base: %pK\n", base);
68743 +#endif
68744 SEQ_printf(m, " .index: %d\n",
68745 base->index);
68746 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68747 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68748 {
68749 struct proc_dir_entry *pe;
68750
68751 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68752 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68753 +#else
68754 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68755 +#endif
68756 if (!pe)
68757 return -ENOMEM;
68758 return 0;
68759 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68760 index 0b537f2..9e71eca 100644
68761 --- a/kernel/time/timer_stats.c
68762 +++ b/kernel/time/timer_stats.c
68763 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68764 static unsigned long nr_entries;
68765 static struct entry entries[MAX_ENTRIES];
68766
68767 -static atomic_t overflow_count;
68768 +static atomic_unchecked_t overflow_count;
68769
68770 /*
68771 * The entries are in a hash-table, for fast lookup:
68772 @@ -140,7 +140,7 @@ static void reset_entries(void)
68773 nr_entries = 0;
68774 memset(entries, 0, sizeof(entries));
68775 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68776 - atomic_set(&overflow_count, 0);
68777 + atomic_set_unchecked(&overflow_count, 0);
68778 }
68779
68780 static struct entry *alloc_entry(void)
68781 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68782 if (likely(entry))
68783 entry->count++;
68784 else
68785 - atomic_inc(&overflow_count);
68786 + atomic_inc_unchecked(&overflow_count);
68787
68788 out_unlock:
68789 raw_spin_unlock_irqrestore(lock, flags);
68790 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68791
68792 static void print_name_offset(struct seq_file *m, unsigned long addr)
68793 {
68794 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68795 + seq_printf(m, "<%p>", NULL);
68796 +#else
68797 char symname[KSYM_NAME_LEN];
68798
68799 if (lookup_symbol_name(addr, symname) < 0)
68800 seq_printf(m, "<%p>", (void *)addr);
68801 else
68802 seq_printf(m, "%s", symname);
68803 +#endif
68804 }
68805
68806 static int tstats_show(struct seq_file *m, void *v)
68807 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68808
68809 seq_puts(m, "Timer Stats Version: v0.2\n");
68810 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68811 - if (atomic_read(&overflow_count))
68812 + if (atomic_read_unchecked(&overflow_count))
68813 seq_printf(m, "Overflow: %d entries\n",
68814 - atomic_read(&overflow_count));
68815 + atomic_read_unchecked(&overflow_count));
68816
68817 for (i = 0; i < nr_entries; i++) {
68818 entry = entries + i;
68819 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68820 {
68821 struct proc_dir_entry *pe;
68822
68823 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68824 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68825 +#else
68826 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68827 +#endif
68828 if (!pe)
68829 return -ENOMEM;
68830 return 0;
68831 diff --git a/kernel/timer.c b/kernel/timer.c
68832 index a297ffc..5e16b0b 100644
68833 --- a/kernel/timer.c
68834 +++ b/kernel/timer.c
68835 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68836 /*
68837 * This function runs timers and the timer-tq in bottom half context.
68838 */
68839 -static void run_timer_softirq(struct softirq_action *h)
68840 +static void run_timer_softirq(void)
68841 {
68842 struct tvec_base *base = __this_cpu_read(tvec_bases);
68843
68844 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68845 index c0bd030..62a1927 100644
68846 --- a/kernel/trace/blktrace.c
68847 +++ b/kernel/trace/blktrace.c
68848 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68849 struct blk_trace *bt = filp->private_data;
68850 char buf[16];
68851
68852 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68853 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68854
68855 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68856 }
68857 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68858 return 1;
68859
68860 bt = buf->chan->private_data;
68861 - atomic_inc(&bt->dropped);
68862 + atomic_inc_unchecked(&bt->dropped);
68863 return 0;
68864 }
68865
68866 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68867
68868 bt->dir = dir;
68869 bt->dev = dev;
68870 - atomic_set(&bt->dropped, 0);
68871 + atomic_set_unchecked(&bt->dropped, 0);
68872
68873 ret = -EIO;
68874 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68875 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68876 index 0fa92f6..89950b2 100644
68877 --- a/kernel/trace/ftrace.c
68878 +++ b/kernel/trace/ftrace.c
68879 @@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68880 if (unlikely(ftrace_disabled))
68881 return 0;
68882
68883 + ret = ftrace_arch_code_modify_prepare();
68884 + FTRACE_WARN_ON(ret);
68885 + if (ret)
68886 + return 0;
68887 +
68888 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68889 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68890 if (ret) {
68891 ftrace_bug(ret, ip);
68892 - return 0;
68893 }
68894 - return 1;
68895 + return ret ? 0 : 1;
68896 }
68897
68898 /*
68899 @@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68900
68901 int
68902 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68903 - void *data)
68904 + void *data)
68905 {
68906 struct ftrace_func_probe *entry;
68907 struct ftrace_page *pg;
68908 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68909 index 55e4d4c..8c915ec 100644
68910 --- a/kernel/trace/trace.c
68911 +++ b/kernel/trace/trace.c
68912 @@ -4316,10 +4316,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68913 };
68914 #endif
68915
68916 -static struct dentry *d_tracer;
68917 -
68918 struct dentry *tracing_init_dentry(void)
68919 {
68920 + static struct dentry *d_tracer;
68921 static int once;
68922
68923 if (d_tracer)
68924 @@ -4339,10 +4338,9 @@ struct dentry *tracing_init_dentry(void)
68925 return d_tracer;
68926 }
68927
68928 -static struct dentry *d_percpu;
68929 -
68930 struct dentry *tracing_dentry_percpu(void)
68931 {
68932 + static struct dentry *d_percpu;
68933 static int once;
68934 struct dentry *d_tracer;
68935
68936 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68937 index 29111da..d190fe2 100644
68938 --- a/kernel/trace/trace_events.c
68939 +++ b/kernel/trace/trace_events.c
68940 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
68941 struct ftrace_module_file_ops {
68942 struct list_head list;
68943 struct module *mod;
68944 - struct file_operations id;
68945 - struct file_operations enable;
68946 - struct file_operations format;
68947 - struct file_operations filter;
68948 };
68949
68950 static struct ftrace_module_file_ops *
68951 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
68952
68953 file_ops->mod = mod;
68954
68955 - file_ops->id = ftrace_event_id_fops;
68956 - file_ops->id.owner = mod;
68957 -
68958 - file_ops->enable = ftrace_enable_fops;
68959 - file_ops->enable.owner = mod;
68960 -
68961 - file_ops->filter = ftrace_event_filter_fops;
68962 - file_ops->filter.owner = mod;
68963 -
68964 - file_ops->format = ftrace_event_format_fops;
68965 - file_ops->format.owner = mod;
68966 + pax_open_kernel();
68967 + *(void **)&mod->trace_id.owner = mod;
68968 + *(void **)&mod->trace_enable.owner = mod;
68969 + *(void **)&mod->trace_filter.owner = mod;
68970 + *(void **)&mod->trace_format.owner = mod;
68971 + pax_close_kernel();
68972
68973 list_add(&file_ops->list, &ftrace_module_file_list);
68974
68975 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
68976
68977 for_each_event(call, start, end) {
68978 __trace_add_event_call(*call, mod,
68979 - &file_ops->id, &file_ops->enable,
68980 - &file_ops->filter, &file_ops->format);
68981 + &mod->trace_id, &mod->trace_enable,
68982 + &mod->trace_filter, &mod->trace_format);
68983 }
68984 }
68985
68986 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
68987 index 580a05e..9b31acb 100644
68988 --- a/kernel/trace/trace_kprobe.c
68989 +++ b/kernel/trace/trace_kprobe.c
68990 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68991 long ret;
68992 int maxlen = get_rloc_len(*(u32 *)dest);
68993 u8 *dst = get_rloc_data(dest);
68994 - u8 *src = addr;
68995 + const u8 __user *src = (const u8 __force_user *)addr;
68996 mm_segment_t old_fs = get_fs();
68997 if (!maxlen)
68998 return;
68999 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69000 pagefault_disable();
69001 do
69002 ret = __copy_from_user_inatomic(dst++, src++, 1);
69003 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69004 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69005 dst[-1] = '\0';
69006 pagefault_enable();
69007 set_fs(old_fs);
69008 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69009 ((u8 *)get_rloc_data(dest))[0] = '\0';
69010 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69011 } else
69012 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69013 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69014 get_rloc_offs(*(u32 *)dest));
69015 }
69016 /* Return the length of string -- including null terminal byte */
69017 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69018 set_fs(KERNEL_DS);
69019 pagefault_disable();
69020 do {
69021 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69022 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69023 len++;
69024 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69025 pagefault_enable();
69026 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69027 index fd3c8aa..5f324a6 100644
69028 --- a/kernel/trace/trace_mmiotrace.c
69029 +++ b/kernel/trace/trace_mmiotrace.c
69030 @@ -24,7 +24,7 @@ struct header_iter {
69031 static struct trace_array *mmio_trace_array;
69032 static bool overrun_detected;
69033 static unsigned long prev_overruns;
69034 -static atomic_t dropped_count;
69035 +static atomic_unchecked_t dropped_count;
69036
69037 static void mmio_reset_data(struct trace_array *tr)
69038 {
69039 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69040
69041 static unsigned long count_overruns(struct trace_iterator *iter)
69042 {
69043 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69044 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69045 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69046
69047 if (over > prev_overruns)
69048 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69049 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69050 sizeof(*entry), 0, pc);
69051 if (!event) {
69052 - atomic_inc(&dropped_count);
69053 + atomic_inc_unchecked(&dropped_count);
69054 return;
69055 }
69056 entry = ring_buffer_event_data(event);
69057 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69058 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69059 sizeof(*entry), 0, pc);
69060 if (!event) {
69061 - atomic_inc(&dropped_count);
69062 + atomic_inc_unchecked(&dropped_count);
69063 return;
69064 }
69065 entry = ring_buffer_event_data(event);
69066 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69067 index df611a0..10d8b32 100644
69068 --- a/kernel/trace/trace_output.c
69069 +++ b/kernel/trace/trace_output.c
69070 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69071
69072 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69073 if (!IS_ERR(p)) {
69074 - p = mangle_path(s->buffer + s->len, p, "\n");
69075 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69076 if (p) {
69077 s->len = p - s->buffer;
69078 return 1;
69079 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69080 index d4545f4..a9010a1 100644
69081 --- a/kernel/trace/trace_stack.c
69082 +++ b/kernel/trace/trace_stack.c
69083 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69084 return;
69085
69086 /* we do not handle interrupt stacks yet */
69087 - if (!object_is_on_stack(&this_size))
69088 + if (!object_starts_on_stack(&this_size))
69089 return;
69090
69091 local_irq_save(flags);
69092 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69093 index 209b379..7f76423 100644
69094 --- a/kernel/trace/trace_workqueue.c
69095 +++ b/kernel/trace/trace_workqueue.c
69096 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69097 int cpu;
69098 pid_t pid;
69099 /* Can be inserted from interrupt or user context, need to be atomic */
69100 - atomic_t inserted;
69101 + atomic_unchecked_t inserted;
69102 /*
69103 * Don't need to be atomic, works are serialized in a single workqueue thread
69104 * on a single CPU.
69105 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69106 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69107 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69108 if (node->pid == wq_thread->pid) {
69109 - atomic_inc(&node->inserted);
69110 + atomic_inc_unchecked(&node->inserted);
69111 goto found;
69112 }
69113 }
69114 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69115 tsk = get_pid_task(pid, PIDTYPE_PID);
69116 if (tsk) {
69117 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69118 - atomic_read(&cws->inserted), cws->executed,
69119 + atomic_read_unchecked(&cws->inserted), cws->executed,
69120 tsk->comm);
69121 put_task_struct(tsk);
69122 }
69123 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69124 index 6777153..8519f60 100644
69125 --- a/lib/Kconfig.debug
69126 +++ b/lib/Kconfig.debug
69127 @@ -1132,6 +1132,7 @@ config LATENCYTOP
69128 depends on DEBUG_KERNEL
69129 depends on STACKTRACE_SUPPORT
69130 depends on PROC_FS
69131 + depends on !GRKERNSEC_HIDESYM
69132 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69133 select KALLSYMS
69134 select KALLSYMS_ALL
69135 diff --git a/lib/bitmap.c b/lib/bitmap.c
69136 index b5a8b6a..a69623c 100644
69137 --- a/lib/bitmap.c
69138 +++ b/lib/bitmap.c
69139 @@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69140 {
69141 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69142 u32 chunk;
69143 - const char __user __force *ubuf = (const char __user __force *)buf;
69144 + const char __user *ubuf = (const char __force_user *)buf;
69145
69146 bitmap_zero(maskp, nmaskbits);
69147
69148 @@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69149 {
69150 if (!access_ok(VERIFY_READ, ubuf, ulen))
69151 return -EFAULT;
69152 - return __bitmap_parse((const char __force *)ubuf,
69153 + return __bitmap_parse((const char __force_kernel *)ubuf,
69154 ulen, 1, maskp, nmaskbits);
69155
69156 }
69157 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69158 {
69159 unsigned a, b;
69160 int c, old_c, totaldigits;
69161 - const char __user __force *ubuf = (const char __user __force *)buf;
69162 + const char __user *ubuf = (const char __force_user *)buf;
69163 int exp_digit, in_range;
69164
69165 totaldigits = c = 0;
69166 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69167 {
69168 if (!access_ok(VERIFY_READ, ubuf, ulen))
69169 return -EFAULT;
69170 - return __bitmap_parselist((const char __force *)ubuf,
69171 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69172 ulen, 1, maskp, nmaskbits);
69173 }
69174 EXPORT_SYMBOL(bitmap_parselist_user);
69175 diff --git a/lib/bug.c b/lib/bug.c
69176 index a28c141..2bd3d95 100644
69177 --- a/lib/bug.c
69178 +++ b/lib/bug.c
69179 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69180 return BUG_TRAP_TYPE_NONE;
69181
69182 bug = find_bug(bugaddr);
69183 + if (!bug)
69184 + return BUG_TRAP_TYPE_NONE;
69185
69186 file = NULL;
69187 line = 0;
69188 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69189 index 0ab9ae8..f01ceca 100644
69190 --- a/lib/debugobjects.c
69191 +++ b/lib/debugobjects.c
69192 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69193 if (limit > 4)
69194 return;
69195
69196 - is_on_stack = object_is_on_stack(addr);
69197 + is_on_stack = object_starts_on_stack(addr);
69198 if (is_on_stack == onstack)
69199 return;
69200
69201 diff --git a/lib/devres.c b/lib/devres.c
69202 index 80b9c76..9e32279 100644
69203 --- a/lib/devres.c
69204 +++ b/lib/devres.c
69205 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69206 void devm_iounmap(struct device *dev, void __iomem *addr)
69207 {
69208 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69209 - (void *)addr));
69210 + (void __force *)addr));
69211 iounmap(addr);
69212 }
69213 EXPORT_SYMBOL(devm_iounmap);
69214 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69215 {
69216 ioport_unmap(addr);
69217 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69218 - devm_ioport_map_match, (void *)addr));
69219 + devm_ioport_map_match, (void __force *)addr));
69220 }
69221 EXPORT_SYMBOL(devm_ioport_unmap);
69222
69223 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69224 index 13ef233..5241683 100644
69225 --- a/lib/dma-debug.c
69226 +++ b/lib/dma-debug.c
69227 @@ -924,7 +924,7 @@ out:
69228
69229 static void check_for_stack(struct device *dev, void *addr)
69230 {
69231 - if (object_is_on_stack(addr))
69232 + if (object_starts_on_stack(addr))
69233 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69234 "stack [addr=%p]\n", addr);
69235 }
69236 diff --git a/lib/extable.c b/lib/extable.c
69237 index 4cac81e..63e9b8f 100644
69238 --- a/lib/extable.c
69239 +++ b/lib/extable.c
69240 @@ -13,6 +13,7 @@
69241 #include <linux/init.h>
69242 #include <linux/sort.h>
69243 #include <asm/uaccess.h>
69244 +#include <asm/pgtable.h>
69245
69246 #ifndef ARCH_HAS_SORT_EXTABLE
69247 /*
69248 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69249 void sort_extable(struct exception_table_entry *start,
69250 struct exception_table_entry *finish)
69251 {
69252 + pax_open_kernel();
69253 sort(start, finish - start, sizeof(struct exception_table_entry),
69254 cmp_ex, NULL);
69255 + pax_close_kernel();
69256 }
69257
69258 #ifdef CONFIG_MODULES
69259 diff --git a/lib/inflate.c b/lib/inflate.c
69260 index 013a761..c28f3fc 100644
69261 --- a/lib/inflate.c
69262 +++ b/lib/inflate.c
69263 @@ -269,7 +269,7 @@ static void free(void *where)
69264 malloc_ptr = free_mem_ptr;
69265 }
69266 #else
69267 -#define malloc(a) kmalloc(a, GFP_KERNEL)
69268 +#define malloc(a) kmalloc((a), GFP_KERNEL)
69269 #define free(a) kfree(a)
69270 #endif
69271
69272 diff --git a/lib/ioremap.c b/lib/ioremap.c
69273 index 0c9216c..863bd89 100644
69274 --- a/lib/ioremap.c
69275 +++ b/lib/ioremap.c
69276 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69277 unsigned long next;
69278
69279 phys_addr -= addr;
69280 - pmd = pmd_alloc(&init_mm, pud, addr);
69281 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69282 if (!pmd)
69283 return -ENOMEM;
69284 do {
69285 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69286 unsigned long next;
69287
69288 phys_addr -= addr;
69289 - pud = pud_alloc(&init_mm, pgd, addr);
69290 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
69291 if (!pud)
69292 return -ENOMEM;
69293 do {
69294 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69295 index bd2bea9..6b3c95e 100644
69296 --- a/lib/is_single_threaded.c
69297 +++ b/lib/is_single_threaded.c
69298 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69299 struct task_struct *p, *t;
69300 bool ret;
69301
69302 + if (!mm)
69303 + return true;
69304 +
69305 if (atomic_read(&task->signal->live) != 1)
69306 return false;
69307
69308 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69309 index 3ac50dc..240bb7e 100644
69310 --- a/lib/radix-tree.c
69311 +++ b/lib/radix-tree.c
69312 @@ -79,7 +79,7 @@ struct radix_tree_preload {
69313 int nr;
69314 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69315 };
69316 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69317 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69318
69319 static inline void *ptr_to_indirect(void *ptr)
69320 {
69321 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69322 index abbabec..362988d 100644
69323 --- a/lib/vsprintf.c
69324 +++ b/lib/vsprintf.c
69325 @@ -16,6 +16,9 @@
69326 * - scnprintf and vscnprintf
69327 */
69328
69329 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69330 +#define __INCLUDED_BY_HIDESYM 1
69331 +#endif
69332 #include <stdarg.h>
69333 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
69334 #include <linux/types.h>
69335 @@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69336 char sym[KSYM_SYMBOL_LEN];
69337 if (ext == 'B')
69338 sprint_backtrace(sym, value);
69339 - else if (ext != 'f' && ext != 's')
69340 + else if (ext != 'f' && ext != 's' && ext != 'a')
69341 sprint_symbol(sym, value);
69342 else
69343 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69344 @@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69345 return number(buf, end, *(const netdev_features_t *)addr, spec);
69346 }
69347
69348 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69349 +int kptr_restrict __read_mostly = 2;
69350 +#else
69351 int kptr_restrict __read_mostly;
69352 +#endif
69353
69354 /*
69355 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69356 @@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
69357 * - 'S' For symbolic direct pointers with offset
69358 * - 's' For symbolic direct pointers without offset
69359 * - 'B' For backtraced symbolic direct pointers with offset
69360 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69361 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69362 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69363 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69364 * - 'M' For a 6-byte MAC address, it prints the address in the
69365 @@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69366 {
69367 if (!ptr && *fmt != 'K') {
69368 /*
69369 - * Print (null) with the same width as a pointer so it makes
69370 + * Print (nil) with the same width as a pointer so it makes
69371 * tabular output look nice.
69372 */
69373 if (spec.field_width == -1)
69374 spec.field_width = 2 * sizeof(void *);
69375 - return string(buf, end, "(null)", spec);
69376 + return string(buf, end, "(nil)", spec);
69377 }
69378
69379 switch (*fmt) {
69380 @@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69381 /* Fallthrough */
69382 case 'S':
69383 case 's':
69384 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69385 + break;
69386 +#else
69387 + return symbol_string(buf, end, ptr, spec, *fmt);
69388 +#endif
69389 + case 'A':
69390 + case 'a':
69391 case 'B':
69392 return symbol_string(buf, end, ptr, spec, *fmt);
69393 case 'R':
69394 @@ -1653,11 +1669,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69395 typeof(type) value; \
69396 if (sizeof(type) == 8) { \
69397 args = PTR_ALIGN(args, sizeof(u32)); \
69398 - *(u32 *)&value = *(u32 *)args; \
69399 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69400 + *(u32 *)&value = *(const u32 *)args; \
69401 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69402 } else { \
69403 args = PTR_ALIGN(args, sizeof(type)); \
69404 - value = *(typeof(type) *)args; \
69405 + value = *(const typeof(type) *)args; \
69406 } \
69407 args += sizeof(type); \
69408 value; \
69409 @@ -1720,7 +1736,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69410 case FORMAT_TYPE_STR: {
69411 const char *str_arg = args;
69412 args += strlen(str_arg) + 1;
69413 - str = string(str, end, (char *)str_arg, spec);
69414 + str = string(str, end, str_arg, spec);
69415 break;
69416 }
69417
69418 diff --git a/localversion-grsec b/localversion-grsec
69419 new file mode 100644
69420 index 0000000..7cd6065
69421 --- /dev/null
69422 +++ b/localversion-grsec
69423 @@ -0,0 +1 @@
69424 +-grsec
69425 diff --git a/mm/Kconfig b/mm/Kconfig
69426 index e338407..4210331 100644
69427 --- a/mm/Kconfig
69428 +++ b/mm/Kconfig
69429 @@ -247,10 +247,10 @@ config KSM
69430 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69431
69432 config DEFAULT_MMAP_MIN_ADDR
69433 - int "Low address space to protect from user allocation"
69434 + int "Low address space to protect from user allocation"
69435 depends on MMU
69436 - default 4096
69437 - help
69438 + default 65536
69439 + help
69440 This is the portion of low virtual memory which should be protected
69441 from userspace allocation. Keeping a user from writing to low pages
69442 can help reduce the impact of kernel NULL pointer bugs.
69443 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
69444
69445 config HWPOISON_INJECT
69446 tristate "HWPoison pages injector"
69447 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
69448 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
69449 select PROC_PAGE_MONITOR
69450
69451 config NOMMU_INITIAL_TRIM_EXCESS
69452 diff --git a/mm/filemap.c b/mm/filemap.c
69453 index 79c4b2b..596b417 100644
69454 --- a/mm/filemap.c
69455 +++ b/mm/filemap.c
69456 @@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69457 struct address_space *mapping = file->f_mapping;
69458
69459 if (!mapping->a_ops->readpage)
69460 - return -ENOEXEC;
69461 + return -ENODEV;
69462 file_accessed(file);
69463 vma->vm_ops = &generic_file_vm_ops;
69464 vma->vm_flags |= VM_CAN_NONLINEAR;
69465 @@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69466 *pos = i_size_read(inode);
69467
69468 if (limit != RLIM_INFINITY) {
69469 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69470 if (*pos >= limit) {
69471 send_sig(SIGXFSZ, current, 0);
69472 return -EFBIG;
69473 diff --git a/mm/fremap.c b/mm/fremap.c
69474 index 9ed4fd4..c42648d 100644
69475 --- a/mm/fremap.c
69476 +++ b/mm/fremap.c
69477 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69478 retry:
69479 vma = find_vma(mm, start);
69480
69481 +#ifdef CONFIG_PAX_SEGMEXEC
69482 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69483 + goto out;
69484 +#endif
69485 +
69486 /*
69487 * Make sure the vma is shared, that it supports prefaulting,
69488 * and that the remapped range is valid and fully within
69489 diff --git a/mm/highmem.c b/mm/highmem.c
69490 index 57d82c6..e9e0552 100644
69491 --- a/mm/highmem.c
69492 +++ b/mm/highmem.c
69493 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69494 * So no dangers, even with speculative execution.
69495 */
69496 page = pte_page(pkmap_page_table[i]);
69497 + pax_open_kernel();
69498 pte_clear(&init_mm, (unsigned long)page_address(page),
69499 &pkmap_page_table[i]);
69500 -
69501 + pax_close_kernel();
69502 set_page_address(page, NULL);
69503 need_flush = 1;
69504 }
69505 @@ -186,9 +187,11 @@ start:
69506 }
69507 }
69508 vaddr = PKMAP_ADDR(last_pkmap_nr);
69509 +
69510 + pax_open_kernel();
69511 set_pte_at(&init_mm, vaddr,
69512 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69513 -
69514 + pax_close_kernel();
69515 pkmap_count[last_pkmap_nr] = 1;
69516 set_page_address(page, (void *)vaddr);
69517
69518 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69519 index f0e5306..cb9398e 100644
69520 --- a/mm/huge_memory.c
69521 +++ b/mm/huge_memory.c
69522 @@ -733,7 +733,7 @@ out:
69523 * run pte_offset_map on the pmd, if an huge pmd could
69524 * materialize from under us from a different thread.
69525 */
69526 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69527 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69528 return VM_FAULT_OOM;
69529 /* if an huge pmd materialized from under us just retry later */
69530 if (unlikely(pmd_trans_huge(*pmd)))
69531 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69532 index 263e177..3f36aec 100644
69533 --- a/mm/hugetlb.c
69534 +++ b/mm/hugetlb.c
69535 @@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69536 return 1;
69537 }
69538
69539 +#ifdef CONFIG_PAX_SEGMEXEC
69540 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69541 +{
69542 + struct mm_struct *mm = vma->vm_mm;
69543 + struct vm_area_struct *vma_m;
69544 + unsigned long address_m;
69545 + pte_t *ptep_m;
69546 +
69547 + vma_m = pax_find_mirror_vma(vma);
69548 + if (!vma_m)
69549 + return;
69550 +
69551 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69552 + address_m = address + SEGMEXEC_TASK_SIZE;
69553 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69554 + get_page(page_m);
69555 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69556 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69557 +}
69558 +#endif
69559 +
69560 /*
69561 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69562 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69563 @@ -2558,6 +2579,11 @@ retry_avoidcopy:
69564 make_huge_pte(vma, new_page, 1));
69565 page_remove_rmap(old_page);
69566 hugepage_add_new_anon_rmap(new_page, vma, address);
69567 +
69568 +#ifdef CONFIG_PAX_SEGMEXEC
69569 + pax_mirror_huge_pte(vma, address, new_page);
69570 +#endif
69571 +
69572 /* Make the old page be freed below */
69573 new_page = old_page;
69574 mmu_notifier_invalidate_range_end(mm,
69575 @@ -2712,6 +2738,10 @@ retry:
69576 && (vma->vm_flags & VM_SHARED)));
69577 set_huge_pte_at(mm, address, ptep, new_pte);
69578
69579 +#ifdef CONFIG_PAX_SEGMEXEC
69580 + pax_mirror_huge_pte(vma, address, page);
69581 +#endif
69582 +
69583 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69584 /* Optimization, do the COW without a second fault */
69585 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69586 @@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69587 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69588 struct hstate *h = hstate_vma(vma);
69589
69590 +#ifdef CONFIG_PAX_SEGMEXEC
69591 + struct vm_area_struct *vma_m;
69592 +#endif
69593 +
69594 address &= huge_page_mask(h);
69595
69596 ptep = huge_pte_offset(mm, address);
69597 @@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69598 VM_FAULT_SET_HINDEX(h - hstates);
69599 }
69600
69601 +#ifdef CONFIG_PAX_SEGMEXEC
69602 + vma_m = pax_find_mirror_vma(vma);
69603 + if (vma_m) {
69604 + unsigned long address_m;
69605 +
69606 + if (vma->vm_start > vma_m->vm_start) {
69607 + address_m = address;
69608 + address -= SEGMEXEC_TASK_SIZE;
69609 + vma = vma_m;
69610 + h = hstate_vma(vma);
69611 + } else
69612 + address_m = address + SEGMEXEC_TASK_SIZE;
69613 +
69614 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69615 + return VM_FAULT_OOM;
69616 + address_m &= HPAGE_MASK;
69617 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69618 + }
69619 +#endif
69620 +
69621 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69622 if (!ptep)
69623 return VM_FAULT_OOM;
69624 diff --git a/mm/internal.h b/mm/internal.h
69625 index 2189af4..f2ca332 100644
69626 --- a/mm/internal.h
69627 +++ b/mm/internal.h
69628 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69629 * in mm/page_alloc.c
69630 */
69631 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69632 +extern void free_compound_page(struct page *page);
69633 extern void prep_compound_page(struct page *page, unsigned long order);
69634 #ifdef CONFIG_MEMORY_FAILURE
69635 extern bool is_free_buddy_page(struct page *page);
69636 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69637 index 45eb621..6ccd8ea 100644
69638 --- a/mm/kmemleak.c
69639 +++ b/mm/kmemleak.c
69640 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69641
69642 for (i = 0; i < object->trace_len; i++) {
69643 void *ptr = (void *)object->trace[i];
69644 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69645 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69646 }
69647 }
69648
69649 diff --git a/mm/maccess.c b/mm/maccess.c
69650 index d53adf9..03a24bf 100644
69651 --- a/mm/maccess.c
69652 +++ b/mm/maccess.c
69653 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69654 set_fs(KERNEL_DS);
69655 pagefault_disable();
69656 ret = __copy_from_user_inatomic(dst,
69657 - (__force const void __user *)src, size);
69658 + (const void __force_user *)src, size);
69659 pagefault_enable();
69660 set_fs(old_fs);
69661
69662 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69663
69664 set_fs(KERNEL_DS);
69665 pagefault_disable();
69666 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69667 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69668 pagefault_enable();
69669 set_fs(old_fs);
69670
69671 diff --git a/mm/madvise.c b/mm/madvise.c
69672 index 55f645c..4f3fd75 100644
69673 --- a/mm/madvise.c
69674 +++ b/mm/madvise.c
69675 @@ -46,6 +46,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69676 pgoff_t pgoff;
69677 unsigned long new_flags = vma->vm_flags;
69678
69679 +#ifdef CONFIG_PAX_SEGMEXEC
69680 + struct vm_area_struct *vma_m;
69681 +#endif
69682 +
69683 switch (behavior) {
69684 case MADV_NORMAL:
69685 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69686 @@ -117,6 +121,13 @@ success:
69687 /*
69688 * vm_flags is protected by the mmap_sem held in write mode.
69689 */
69690 +
69691 +#ifdef CONFIG_PAX_SEGMEXEC
69692 + vma_m = pax_find_mirror_vma(vma);
69693 + if (vma_m)
69694 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69695 +#endif
69696 +
69697 vma->vm_flags = new_flags;
69698
69699 out:
69700 @@ -175,6 +186,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69701 struct vm_area_struct ** prev,
69702 unsigned long start, unsigned long end)
69703 {
69704 +
69705 +#ifdef CONFIG_PAX_SEGMEXEC
69706 + struct vm_area_struct *vma_m;
69707 +#endif
69708 +
69709 *prev = vma;
69710 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69711 return -EINVAL;
69712 @@ -187,6 +203,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69713 zap_page_range(vma, start, end - start, &details);
69714 } else
69715 zap_page_range(vma, start, end - start, NULL);
69716 +
69717 +#ifdef CONFIG_PAX_SEGMEXEC
69718 + vma_m = pax_find_mirror_vma(vma);
69719 + if (vma_m) {
69720 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69721 + struct zap_details details = {
69722 + .nonlinear_vma = vma_m,
69723 + .last_index = ULONG_MAX,
69724 + };
69725 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69726 + } else
69727 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69728 + }
69729 +#endif
69730 +
69731 return 0;
69732 }
69733
69734 @@ -238,6 +269,7 @@ static long madvise_remove(struct vm_area_struct *vma,
69735 error = vmtruncate_range(mapping->host, offset, endoff);
69736 fput(f);
69737 down_read(&current->mm->mmap_sem);
69738 + fput(f);
69739 return error;
69740 }
69741
69742 @@ -394,6 +426,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69743 if (end < start)
69744 goto out;
69745
69746 +#ifdef CONFIG_PAX_SEGMEXEC
69747 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69748 + if (end > SEGMEXEC_TASK_SIZE)
69749 + goto out;
69750 + } else
69751 +#endif
69752 +
69753 + if (end > TASK_SIZE)
69754 + goto out;
69755 +
69756 error = 0;
69757 if (end == start)
69758 goto out;
69759 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69760 index 97cc273..6ed703f 100644
69761 --- a/mm/memory-failure.c
69762 +++ b/mm/memory-failure.c
69763 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69764
69765 int sysctl_memory_failure_recovery __read_mostly = 1;
69766
69767 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69768 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69769
69770 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69771
69772 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
69773 pfn, t->comm, t->pid);
69774 si.si_signo = SIGBUS;
69775 si.si_errno = 0;
69776 - si.si_addr = (void *)addr;
69777 + si.si_addr = (void __user *)addr;
69778 #ifdef __ARCH_SI_TRAPNO
69779 si.si_trapno = trapno;
69780 #endif
69781 @@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69782 }
69783
69784 nr_pages = 1 << compound_trans_order(hpage);
69785 - atomic_long_add(nr_pages, &mce_bad_pages);
69786 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69787
69788 /*
69789 * We need/can do nothing about count=0 pages.
69790 @@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69791 if (!PageHWPoison(hpage)
69792 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69793 || (p != hpage && TestSetPageHWPoison(hpage))) {
69794 - atomic_long_sub(nr_pages, &mce_bad_pages);
69795 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69796 return 0;
69797 }
69798 set_page_hwpoison_huge_page(hpage);
69799 @@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69800 }
69801 if (hwpoison_filter(p)) {
69802 if (TestClearPageHWPoison(p))
69803 - atomic_long_sub(nr_pages, &mce_bad_pages);
69804 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69805 unlock_page(hpage);
69806 put_page(hpage);
69807 return 0;
69808 @@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
69809 return 0;
69810 }
69811 if (TestClearPageHWPoison(p))
69812 - atomic_long_sub(nr_pages, &mce_bad_pages);
69813 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69814 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69815 return 0;
69816 }
69817 @@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
69818 */
69819 if (TestClearPageHWPoison(page)) {
69820 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69821 - atomic_long_sub(nr_pages, &mce_bad_pages);
69822 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69823 freeit = 1;
69824 if (PageHuge(page))
69825 clear_page_hwpoison_huge_page(page);
69826 @@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69827 }
69828 done:
69829 if (!PageHWPoison(hpage))
69830 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69831 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69832 set_page_hwpoison_huge_page(hpage);
69833 dequeue_hwpoisoned_huge_page(hpage);
69834 /* keep elevated page count for bad page */
69835 @@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
69836 return ret;
69837
69838 done:
69839 - atomic_long_add(1, &mce_bad_pages);
69840 + atomic_long_add_unchecked(1, &mce_bad_pages);
69841 SetPageHWPoison(page);
69842 /* keep elevated page count for bad page */
69843 return ret;
69844 diff --git a/mm/memory.c b/mm/memory.c
69845 index 6105f47..3363489 100644
69846 --- a/mm/memory.c
69847 +++ b/mm/memory.c
69848 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69849 return;
69850
69851 pmd = pmd_offset(pud, start);
69852 +
69853 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69854 pud_clear(pud);
69855 pmd_free_tlb(tlb, pmd, start);
69856 +#endif
69857 +
69858 }
69859
69860 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69861 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69862 if (end - 1 > ceiling - 1)
69863 return;
69864
69865 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69866 pud = pud_offset(pgd, start);
69867 pgd_clear(pgd);
69868 pud_free_tlb(tlb, pud, start);
69869 +#endif
69870 +
69871 }
69872
69873 /*
69874 @@ -1597,12 +1604,6 @@ no_page_table:
69875 return page;
69876 }
69877
69878 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69879 -{
69880 - return stack_guard_page_start(vma, addr) ||
69881 - stack_guard_page_end(vma, addr+PAGE_SIZE);
69882 -}
69883 -
69884 /**
69885 * __get_user_pages() - pin user pages in memory
69886 * @tsk: task_struct of target task
69887 @@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69888 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69889 i = 0;
69890
69891 - do {
69892 + while (nr_pages) {
69893 struct vm_area_struct *vma;
69894
69895 - vma = find_extend_vma(mm, start);
69896 + vma = find_vma(mm, start);
69897 if (!vma && in_gate_area(mm, start)) {
69898 unsigned long pg = start & PAGE_MASK;
69899 pgd_t *pgd;
69900 @@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69901 goto next_page;
69902 }
69903
69904 - if (!vma ||
69905 + if (!vma || start < vma->vm_start ||
69906 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69907 !(vm_flags & vma->vm_flags))
69908 return i ? : -EFAULT;
69909 @@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69910 int ret;
69911 unsigned int fault_flags = 0;
69912
69913 - /* For mlock, just skip the stack guard page. */
69914 - if (foll_flags & FOLL_MLOCK) {
69915 - if (stack_guard_page(vma, start))
69916 - goto next_page;
69917 - }
69918 if (foll_flags & FOLL_WRITE)
69919 fault_flags |= FAULT_FLAG_WRITE;
69920 if (nonblocking)
69921 @@ -1831,7 +1827,7 @@ next_page:
69922 start += PAGE_SIZE;
69923 nr_pages--;
69924 } while (nr_pages && start < vma->vm_end);
69925 - } while (nr_pages);
69926 + }
69927 return i;
69928 }
69929 EXPORT_SYMBOL(__get_user_pages);
69930 @@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69931 page_add_file_rmap(page);
69932 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69933
69934 +#ifdef CONFIG_PAX_SEGMEXEC
69935 + pax_mirror_file_pte(vma, addr, page, ptl);
69936 +#endif
69937 +
69938 retval = 0;
69939 pte_unmap_unlock(pte, ptl);
69940 return retval;
69941 @@ -2072,10 +2072,22 @@ out:
69942 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
69943 struct page *page)
69944 {
69945 +
69946 +#ifdef CONFIG_PAX_SEGMEXEC
69947 + struct vm_area_struct *vma_m;
69948 +#endif
69949 +
69950 if (addr < vma->vm_start || addr >= vma->vm_end)
69951 return -EFAULT;
69952 if (!page_count(page))
69953 return -EINVAL;
69954 +
69955 +#ifdef CONFIG_PAX_SEGMEXEC
69956 + vma_m = pax_find_mirror_vma(vma);
69957 + if (vma_m)
69958 + vma_m->vm_flags |= VM_INSERTPAGE;
69959 +#endif
69960 +
69961 vma->vm_flags |= VM_INSERTPAGE;
69962 return insert_page(vma, addr, page, vma->vm_page_prot);
69963 }
69964 @@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
69965 unsigned long pfn)
69966 {
69967 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
69968 + BUG_ON(vma->vm_mirror);
69969
69970 if (addr < vma->vm_start || addr >= vma->vm_end)
69971 return -EFAULT;
69972 @@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
69973
69974 BUG_ON(pud_huge(*pud));
69975
69976 - pmd = pmd_alloc(mm, pud, addr);
69977 + pmd = (mm == &init_mm) ?
69978 + pmd_alloc_kernel(mm, pud, addr) :
69979 + pmd_alloc(mm, pud, addr);
69980 if (!pmd)
69981 return -ENOMEM;
69982 do {
69983 @@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
69984 unsigned long next;
69985 int err;
69986
69987 - pud = pud_alloc(mm, pgd, addr);
69988 + pud = (mm == &init_mm) ?
69989 + pud_alloc_kernel(mm, pgd, addr) :
69990 + pud_alloc(mm, pgd, addr);
69991 if (!pud)
69992 return -ENOMEM;
69993 do {
69994 @@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
69995 copy_user_highpage(dst, src, va, vma);
69996 }
69997
69998 +#ifdef CONFIG_PAX_SEGMEXEC
69999 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70000 +{
70001 + struct mm_struct *mm = vma->vm_mm;
70002 + spinlock_t *ptl;
70003 + pte_t *pte, entry;
70004 +
70005 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70006 + entry = *pte;
70007 + if (!pte_present(entry)) {
70008 + if (!pte_none(entry)) {
70009 + BUG_ON(pte_file(entry));
70010 + free_swap_and_cache(pte_to_swp_entry(entry));
70011 + pte_clear_not_present_full(mm, address, pte, 0);
70012 + }
70013 + } else {
70014 + struct page *page;
70015 +
70016 + flush_cache_page(vma, address, pte_pfn(entry));
70017 + entry = ptep_clear_flush(vma, address, pte);
70018 + BUG_ON(pte_dirty(entry));
70019 + page = vm_normal_page(vma, address, entry);
70020 + if (page) {
70021 + update_hiwater_rss(mm);
70022 + if (PageAnon(page))
70023 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70024 + else
70025 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70026 + page_remove_rmap(page);
70027 + page_cache_release(page);
70028 + }
70029 + }
70030 + pte_unmap_unlock(pte, ptl);
70031 +}
70032 +
70033 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70034 + *
70035 + * the ptl of the lower mapped page is held on entry and is not released on exit
70036 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70037 + */
70038 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70039 +{
70040 + struct mm_struct *mm = vma->vm_mm;
70041 + unsigned long address_m;
70042 + spinlock_t *ptl_m;
70043 + struct vm_area_struct *vma_m;
70044 + pmd_t *pmd_m;
70045 + pte_t *pte_m, entry_m;
70046 +
70047 + BUG_ON(!page_m || !PageAnon(page_m));
70048 +
70049 + vma_m = pax_find_mirror_vma(vma);
70050 + if (!vma_m)
70051 + return;
70052 +
70053 + BUG_ON(!PageLocked(page_m));
70054 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70055 + address_m = address + SEGMEXEC_TASK_SIZE;
70056 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70057 + pte_m = pte_offset_map(pmd_m, address_m);
70058 + ptl_m = pte_lockptr(mm, pmd_m);
70059 + if (ptl != ptl_m) {
70060 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70061 + if (!pte_none(*pte_m))
70062 + goto out;
70063 + }
70064 +
70065 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70066 + page_cache_get(page_m);
70067 + page_add_anon_rmap(page_m, vma_m, address_m);
70068 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70069 + set_pte_at(mm, address_m, pte_m, entry_m);
70070 + update_mmu_cache(vma_m, address_m, entry_m);
70071 +out:
70072 + if (ptl != ptl_m)
70073 + spin_unlock(ptl_m);
70074 + pte_unmap(pte_m);
70075 + unlock_page(page_m);
70076 +}
70077 +
70078 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70079 +{
70080 + struct mm_struct *mm = vma->vm_mm;
70081 + unsigned long address_m;
70082 + spinlock_t *ptl_m;
70083 + struct vm_area_struct *vma_m;
70084 + pmd_t *pmd_m;
70085 + pte_t *pte_m, entry_m;
70086 +
70087 + BUG_ON(!page_m || PageAnon(page_m));
70088 +
70089 + vma_m = pax_find_mirror_vma(vma);
70090 + if (!vma_m)
70091 + return;
70092 +
70093 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70094 + address_m = address + SEGMEXEC_TASK_SIZE;
70095 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70096 + pte_m = pte_offset_map(pmd_m, address_m);
70097 + ptl_m = pte_lockptr(mm, pmd_m);
70098 + if (ptl != ptl_m) {
70099 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70100 + if (!pte_none(*pte_m))
70101 + goto out;
70102 + }
70103 +
70104 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70105 + page_cache_get(page_m);
70106 + page_add_file_rmap(page_m);
70107 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70108 + set_pte_at(mm, address_m, pte_m, entry_m);
70109 + update_mmu_cache(vma_m, address_m, entry_m);
70110 +out:
70111 + if (ptl != ptl_m)
70112 + spin_unlock(ptl_m);
70113 + pte_unmap(pte_m);
70114 +}
70115 +
70116 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70117 +{
70118 + struct mm_struct *mm = vma->vm_mm;
70119 + unsigned long address_m;
70120 + spinlock_t *ptl_m;
70121 + struct vm_area_struct *vma_m;
70122 + pmd_t *pmd_m;
70123 + pte_t *pte_m, entry_m;
70124 +
70125 + vma_m = pax_find_mirror_vma(vma);
70126 + if (!vma_m)
70127 + return;
70128 +
70129 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70130 + address_m = address + SEGMEXEC_TASK_SIZE;
70131 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70132 + pte_m = pte_offset_map(pmd_m, address_m);
70133 + ptl_m = pte_lockptr(mm, pmd_m);
70134 + if (ptl != ptl_m) {
70135 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70136 + if (!pte_none(*pte_m))
70137 + goto out;
70138 + }
70139 +
70140 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70141 + set_pte_at(mm, address_m, pte_m, entry_m);
70142 +out:
70143 + if (ptl != ptl_m)
70144 + spin_unlock(ptl_m);
70145 + pte_unmap(pte_m);
70146 +}
70147 +
70148 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70149 +{
70150 + struct page *page_m;
70151 + pte_t entry;
70152 +
70153 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70154 + goto out;
70155 +
70156 + entry = *pte;
70157 + page_m = vm_normal_page(vma, address, entry);
70158 + if (!page_m)
70159 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70160 + else if (PageAnon(page_m)) {
70161 + if (pax_find_mirror_vma(vma)) {
70162 + pte_unmap_unlock(pte, ptl);
70163 + lock_page(page_m);
70164 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70165 + if (pte_same(entry, *pte))
70166 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70167 + else
70168 + unlock_page(page_m);
70169 + }
70170 + } else
70171 + pax_mirror_file_pte(vma, address, page_m, ptl);
70172 +
70173 +out:
70174 + pte_unmap_unlock(pte, ptl);
70175 +}
70176 +#endif
70177 +
70178 /*
70179 * This routine handles present pages, when users try to write
70180 * to a shared page. It is done by copying the page to a new address
70181 @@ -2687,6 +2884,12 @@ gotten:
70182 */
70183 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70184 if (likely(pte_same(*page_table, orig_pte))) {
70185 +
70186 +#ifdef CONFIG_PAX_SEGMEXEC
70187 + if (pax_find_mirror_vma(vma))
70188 + BUG_ON(!trylock_page(new_page));
70189 +#endif
70190 +
70191 if (old_page) {
70192 if (!PageAnon(old_page)) {
70193 dec_mm_counter_fast(mm, MM_FILEPAGES);
70194 @@ -2738,6 +2941,10 @@ gotten:
70195 page_remove_rmap(old_page);
70196 }
70197
70198 +#ifdef CONFIG_PAX_SEGMEXEC
70199 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70200 +#endif
70201 +
70202 /* Free the old page.. */
70203 new_page = old_page;
70204 ret |= VM_FAULT_WRITE;
70205 @@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70206 swap_free(entry);
70207 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70208 try_to_free_swap(page);
70209 +
70210 +#ifdef CONFIG_PAX_SEGMEXEC
70211 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70212 +#endif
70213 +
70214 unlock_page(page);
70215 if (swapcache) {
70216 /*
70217 @@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70218
70219 /* No need to invalidate - it was non-present before */
70220 update_mmu_cache(vma, address, page_table);
70221 +
70222 +#ifdef CONFIG_PAX_SEGMEXEC
70223 + pax_mirror_anon_pte(vma, address, page, ptl);
70224 +#endif
70225 +
70226 unlock:
70227 pte_unmap_unlock(page_table, ptl);
70228 out:
70229 @@ -3059,40 +3276,6 @@ out_release:
70230 }
70231
70232 /*
70233 - * This is like a special single-page "expand_{down|up}wards()",
70234 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70235 - * doesn't hit another vma.
70236 - */
70237 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70238 -{
70239 - address &= PAGE_MASK;
70240 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70241 - struct vm_area_struct *prev = vma->vm_prev;
70242 -
70243 - /*
70244 - * Is there a mapping abutting this one below?
70245 - *
70246 - * That's only ok if it's the same stack mapping
70247 - * that has gotten split..
70248 - */
70249 - if (prev && prev->vm_end == address)
70250 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70251 -
70252 - expand_downwards(vma, address - PAGE_SIZE);
70253 - }
70254 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70255 - struct vm_area_struct *next = vma->vm_next;
70256 -
70257 - /* As VM_GROWSDOWN but s/below/above/ */
70258 - if (next && next->vm_start == address + PAGE_SIZE)
70259 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70260 -
70261 - expand_upwards(vma, address + PAGE_SIZE);
70262 - }
70263 - return 0;
70264 -}
70265 -
70266 -/*
70267 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70268 * but allow concurrent faults), and pte mapped but not yet locked.
70269 * We return with mmap_sem still held, but pte unmapped and unlocked.
70270 @@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70271 unsigned long address, pte_t *page_table, pmd_t *pmd,
70272 unsigned int flags)
70273 {
70274 - struct page *page;
70275 + struct page *page = NULL;
70276 spinlock_t *ptl;
70277 pte_t entry;
70278
70279 - pte_unmap(page_table);
70280 -
70281 - /* Check if we need to add a guard page to the stack */
70282 - if (check_stack_guard_page(vma, address) < 0)
70283 - return VM_FAULT_SIGBUS;
70284 -
70285 - /* Use the zero-page for reads */
70286 if (!(flags & FAULT_FLAG_WRITE)) {
70287 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70288 vma->vm_page_prot));
70289 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70290 + ptl = pte_lockptr(mm, pmd);
70291 + spin_lock(ptl);
70292 if (!pte_none(*page_table))
70293 goto unlock;
70294 goto setpte;
70295 }
70296
70297 /* Allocate our own private page. */
70298 + pte_unmap(page_table);
70299 +
70300 if (unlikely(anon_vma_prepare(vma)))
70301 goto oom;
70302 page = alloc_zeroed_user_highpage_movable(vma, address);
70303 @@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70304 if (!pte_none(*page_table))
70305 goto release;
70306
70307 +#ifdef CONFIG_PAX_SEGMEXEC
70308 + if (pax_find_mirror_vma(vma))
70309 + BUG_ON(!trylock_page(page));
70310 +#endif
70311 +
70312 inc_mm_counter_fast(mm, MM_ANONPAGES);
70313 page_add_new_anon_rmap(page, vma, address);
70314 setpte:
70315 @@ -3147,6 +3331,12 @@ setpte:
70316
70317 /* No need to invalidate - it was non-present before */
70318 update_mmu_cache(vma, address, page_table);
70319 +
70320 +#ifdef CONFIG_PAX_SEGMEXEC
70321 + if (page)
70322 + pax_mirror_anon_pte(vma, address, page, ptl);
70323 +#endif
70324 +
70325 unlock:
70326 pte_unmap_unlock(page_table, ptl);
70327 return 0;
70328 @@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70329 */
70330 /* Only go through if we didn't race with anybody else... */
70331 if (likely(pte_same(*page_table, orig_pte))) {
70332 +
70333 +#ifdef CONFIG_PAX_SEGMEXEC
70334 + if (anon && pax_find_mirror_vma(vma))
70335 + BUG_ON(!trylock_page(page));
70336 +#endif
70337 +
70338 flush_icache_page(vma, page);
70339 entry = mk_pte(page, vma->vm_page_prot);
70340 if (flags & FAULT_FLAG_WRITE)
70341 @@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70342
70343 /* no need to invalidate: a not-present page won't be cached */
70344 update_mmu_cache(vma, address, page_table);
70345 +
70346 +#ifdef CONFIG_PAX_SEGMEXEC
70347 + if (anon)
70348 + pax_mirror_anon_pte(vma, address, page, ptl);
70349 + else
70350 + pax_mirror_file_pte(vma, address, page, ptl);
70351 +#endif
70352 +
70353 } else {
70354 if (cow_page)
70355 mem_cgroup_uncharge_page(cow_page);
70356 @@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
70357 if (flags & FAULT_FLAG_WRITE)
70358 flush_tlb_fix_spurious_fault(vma, address);
70359 }
70360 +
70361 +#ifdef CONFIG_PAX_SEGMEXEC
70362 + pax_mirror_pte(vma, address, pte, pmd, ptl);
70363 + return 0;
70364 +#endif
70365 +
70366 unlock:
70367 pte_unmap_unlock(pte, ptl);
70368 return 0;
70369 @@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70370 pmd_t *pmd;
70371 pte_t *pte;
70372
70373 +#ifdef CONFIG_PAX_SEGMEXEC
70374 + struct vm_area_struct *vma_m;
70375 +#endif
70376 +
70377 __set_current_state(TASK_RUNNING);
70378
70379 count_vm_event(PGFAULT);
70380 @@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70381 if (unlikely(is_vm_hugetlb_page(vma)))
70382 return hugetlb_fault(mm, vma, address, flags);
70383
70384 +#ifdef CONFIG_PAX_SEGMEXEC
70385 + vma_m = pax_find_mirror_vma(vma);
70386 + if (vma_m) {
70387 + unsigned long address_m;
70388 + pgd_t *pgd_m;
70389 + pud_t *pud_m;
70390 + pmd_t *pmd_m;
70391 +
70392 + if (vma->vm_start > vma_m->vm_start) {
70393 + address_m = address;
70394 + address -= SEGMEXEC_TASK_SIZE;
70395 + vma = vma_m;
70396 + } else
70397 + address_m = address + SEGMEXEC_TASK_SIZE;
70398 +
70399 + pgd_m = pgd_offset(mm, address_m);
70400 + pud_m = pud_alloc(mm, pgd_m, address_m);
70401 + if (!pud_m)
70402 + return VM_FAULT_OOM;
70403 + pmd_m = pmd_alloc(mm, pud_m, address_m);
70404 + if (!pmd_m)
70405 + return VM_FAULT_OOM;
70406 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70407 + return VM_FAULT_OOM;
70408 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70409 + }
70410 +#endif
70411 +
70412 pgd = pgd_offset(mm, address);
70413 pud = pud_alloc(mm, pgd, address);
70414 if (!pud)
70415 @@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70416 * run pte_offset_map on the pmd, if an huge pmd could
70417 * materialize from under us from a different thread.
70418 */
70419 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70420 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70421 return VM_FAULT_OOM;
70422 /* if an huge pmd materialized from under us just retry later */
70423 if (unlikely(pmd_trans_huge(*pmd)))
70424 @@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70425 spin_unlock(&mm->page_table_lock);
70426 return 0;
70427 }
70428 +
70429 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70430 +{
70431 + pud_t *new = pud_alloc_one(mm, address);
70432 + if (!new)
70433 + return -ENOMEM;
70434 +
70435 + smp_wmb(); /* See comment in __pte_alloc */
70436 +
70437 + spin_lock(&mm->page_table_lock);
70438 + if (pgd_present(*pgd)) /* Another has populated it */
70439 + pud_free(mm, new);
70440 + else
70441 + pgd_populate_kernel(mm, pgd, new);
70442 + spin_unlock(&mm->page_table_lock);
70443 + return 0;
70444 +}
70445 #endif /* __PAGETABLE_PUD_FOLDED */
70446
70447 #ifndef __PAGETABLE_PMD_FOLDED
70448 @@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70449 spin_unlock(&mm->page_table_lock);
70450 return 0;
70451 }
70452 +
70453 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70454 +{
70455 + pmd_t *new = pmd_alloc_one(mm, address);
70456 + if (!new)
70457 + return -ENOMEM;
70458 +
70459 + smp_wmb(); /* See comment in __pte_alloc */
70460 +
70461 + spin_lock(&mm->page_table_lock);
70462 +#ifndef __ARCH_HAS_4LEVEL_HACK
70463 + if (pud_present(*pud)) /* Another has populated it */
70464 + pmd_free(mm, new);
70465 + else
70466 + pud_populate_kernel(mm, pud, new);
70467 +#else
70468 + if (pgd_present(*pud)) /* Another has populated it */
70469 + pmd_free(mm, new);
70470 + else
70471 + pgd_populate_kernel(mm, pud, new);
70472 +#endif /* __ARCH_HAS_4LEVEL_HACK */
70473 + spin_unlock(&mm->page_table_lock);
70474 + return 0;
70475 +}
70476 #endif /* __PAGETABLE_PMD_FOLDED */
70477
70478 int make_pages_present(unsigned long addr, unsigned long end)
70479 @@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
70480 gate_vma.vm_start = FIXADDR_USER_START;
70481 gate_vma.vm_end = FIXADDR_USER_END;
70482 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70483 - gate_vma.vm_page_prot = __P101;
70484 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70485
70486 return 0;
70487 }
70488 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70489 index bf5b485..e44c2cb 100644
70490 --- a/mm/mempolicy.c
70491 +++ b/mm/mempolicy.c
70492 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70493 unsigned long vmstart;
70494 unsigned long vmend;
70495
70496 +#ifdef CONFIG_PAX_SEGMEXEC
70497 + struct vm_area_struct *vma_m;
70498 +#endif
70499 +
70500 vma = find_vma(mm, start);
70501 if (!vma || vma->vm_start > start)
70502 return -EFAULT;
70503 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70504 if (err)
70505 goto out;
70506 }
70507 +
70508 +#ifdef CONFIG_PAX_SEGMEXEC
70509 + vma_m = pax_find_mirror_vma(vma);
70510 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
70511 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
70512 + if (err)
70513 + goto out;
70514 + }
70515 +#endif
70516 +
70517 }
70518
70519 out:
70520 @@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70521
70522 if (end < start)
70523 return -EINVAL;
70524 +
70525 +#ifdef CONFIG_PAX_SEGMEXEC
70526 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70527 + if (end > SEGMEXEC_TASK_SIZE)
70528 + return -EINVAL;
70529 + } else
70530 +#endif
70531 +
70532 + if (end > TASK_SIZE)
70533 + return -EINVAL;
70534 +
70535 if (end == start)
70536 return 0;
70537
70538 @@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70539 */
70540 tcred = __task_cred(task);
70541 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70542 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70543 - !capable(CAP_SYS_NICE)) {
70544 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70545 rcu_read_unlock();
70546 err = -EPERM;
70547 goto out_put;
70548 @@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70549 goto out;
70550 }
70551
70552 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70553 + if (mm != current->mm &&
70554 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70555 + mmput(mm);
70556 + err = -EPERM;
70557 + goto out;
70558 + }
70559 +#endif
70560 +
70561 err = do_migrate_pages(mm, old, new,
70562 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
70563
70564 diff --git a/mm/mlock.c b/mm/mlock.c
70565 index ef726e8..13e0901 100644
70566 --- a/mm/mlock.c
70567 +++ b/mm/mlock.c
70568 @@ -13,6 +13,7 @@
70569 #include <linux/pagemap.h>
70570 #include <linux/mempolicy.h>
70571 #include <linux/syscalls.h>
70572 +#include <linux/security.h>
70573 #include <linux/sched.h>
70574 #include <linux/export.h>
70575 #include <linux/rmap.h>
70576 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70577 return -EINVAL;
70578 if (end == start)
70579 return 0;
70580 + if (end > TASK_SIZE)
70581 + return -EINVAL;
70582 +
70583 vma = find_vma(current->mm, start);
70584 if (!vma || vma->vm_start > start)
70585 return -ENOMEM;
70586 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70587 for (nstart = start ; ; ) {
70588 vm_flags_t newflags;
70589
70590 +#ifdef CONFIG_PAX_SEGMEXEC
70591 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70592 + break;
70593 +#endif
70594 +
70595 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70596
70597 newflags = vma->vm_flags | VM_LOCKED;
70598 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70599 lock_limit >>= PAGE_SHIFT;
70600
70601 /* check against resource limits */
70602 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70603 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70604 error = do_mlock(start, len, 1);
70605 up_write(&current->mm->mmap_sem);
70606 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70607 static int do_mlockall(int flags)
70608 {
70609 struct vm_area_struct * vma, * prev = NULL;
70610 - unsigned int def_flags = 0;
70611
70612 if (flags & MCL_FUTURE)
70613 - def_flags = VM_LOCKED;
70614 - current->mm->def_flags = def_flags;
70615 + current->mm->def_flags |= VM_LOCKED;
70616 + else
70617 + current->mm->def_flags &= ~VM_LOCKED;
70618 if (flags == MCL_FUTURE)
70619 goto out;
70620
70621 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70622 vm_flags_t newflags;
70623
70624 +#ifdef CONFIG_PAX_SEGMEXEC
70625 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70626 + break;
70627 +#endif
70628 +
70629 + BUG_ON(vma->vm_end > TASK_SIZE);
70630 newflags = vma->vm_flags | VM_LOCKED;
70631 if (!(flags & MCL_CURRENT))
70632 newflags &= ~VM_LOCKED;
70633 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70634 lock_limit >>= PAGE_SHIFT;
70635
70636 ret = -ENOMEM;
70637 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70638 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70639 capable(CAP_IPC_LOCK))
70640 ret = do_mlockall(flags);
70641 diff --git a/mm/mmap.c b/mm/mmap.c
70642 index 848ef52..d2b586c 100644
70643 --- a/mm/mmap.c
70644 +++ b/mm/mmap.c
70645 @@ -46,6 +46,16 @@
70646 #define arch_rebalance_pgtables(addr, len) (addr)
70647 #endif
70648
70649 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70650 +{
70651 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70652 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70653 + up_read(&mm->mmap_sem);
70654 + BUG();
70655 + }
70656 +#endif
70657 +}
70658 +
70659 static void unmap_region(struct mm_struct *mm,
70660 struct vm_area_struct *vma, struct vm_area_struct *prev,
70661 unsigned long start, unsigned long end);
70662 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70663 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70664 *
70665 */
70666 -pgprot_t protection_map[16] = {
70667 +pgprot_t protection_map[16] __read_only = {
70668 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70669 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70670 };
70671
70672 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70673 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70674 {
70675 - return __pgprot(pgprot_val(protection_map[vm_flags &
70676 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70677 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70678 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70679 +
70680 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70681 + if (!(__supported_pte_mask & _PAGE_NX) &&
70682 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70683 + (vm_flags & (VM_READ | VM_WRITE)))
70684 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70685 +#endif
70686 +
70687 + return prot;
70688 }
70689 EXPORT_SYMBOL(vm_get_page_prot);
70690
70691 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70692 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70693 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70694 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70695 /*
70696 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70697 * other variables. It can be updated by several CPUs frequently.
70698 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70699 struct vm_area_struct *next = vma->vm_next;
70700
70701 might_sleep();
70702 + BUG_ON(vma->vm_mirror);
70703 if (vma->vm_ops && vma->vm_ops->close)
70704 vma->vm_ops->close(vma);
70705 if (vma->vm_file) {
70706 @@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70707 * not page aligned -Ram Gupta
70708 */
70709 rlim = rlimit(RLIMIT_DATA);
70710 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70711 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70712 (mm->end_data - mm->start_data) > rlim)
70713 goto out;
70714 @@ -690,6 +712,12 @@ static int
70715 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70716 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70717 {
70718 +
70719 +#ifdef CONFIG_PAX_SEGMEXEC
70720 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70721 + return 0;
70722 +#endif
70723 +
70724 if (is_mergeable_vma(vma, file, vm_flags) &&
70725 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70726 if (vma->vm_pgoff == vm_pgoff)
70727 @@ -709,6 +737,12 @@ static int
70728 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70729 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70730 {
70731 +
70732 +#ifdef CONFIG_PAX_SEGMEXEC
70733 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70734 + return 0;
70735 +#endif
70736 +
70737 if (is_mergeable_vma(vma, file, vm_flags) &&
70738 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70739 pgoff_t vm_pglen;
70740 @@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70741 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70742 struct vm_area_struct *prev, unsigned long addr,
70743 unsigned long end, unsigned long vm_flags,
70744 - struct anon_vma *anon_vma, struct file *file,
70745 + struct anon_vma *anon_vma, struct file *file,
70746 pgoff_t pgoff, struct mempolicy *policy)
70747 {
70748 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70749 struct vm_area_struct *area, *next;
70750 int err;
70751
70752 +#ifdef CONFIG_PAX_SEGMEXEC
70753 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70754 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70755 +
70756 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70757 +#endif
70758 +
70759 /*
70760 * We later require that vma->vm_flags == vm_flags,
70761 * so this tests vma->vm_flags & VM_SPECIAL, too.
70762 @@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70763 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70764 next = next->vm_next;
70765
70766 +#ifdef CONFIG_PAX_SEGMEXEC
70767 + if (prev)
70768 + prev_m = pax_find_mirror_vma(prev);
70769 + if (area)
70770 + area_m = pax_find_mirror_vma(area);
70771 + if (next)
70772 + next_m = pax_find_mirror_vma(next);
70773 +#endif
70774 +
70775 /*
70776 * Can it merge with the predecessor?
70777 */
70778 @@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70779 /* cases 1, 6 */
70780 err = vma_adjust(prev, prev->vm_start,
70781 next->vm_end, prev->vm_pgoff, NULL);
70782 - } else /* cases 2, 5, 7 */
70783 +
70784 +#ifdef CONFIG_PAX_SEGMEXEC
70785 + if (!err && prev_m)
70786 + err = vma_adjust(prev_m, prev_m->vm_start,
70787 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70788 +#endif
70789 +
70790 + } else { /* cases 2, 5, 7 */
70791 err = vma_adjust(prev, prev->vm_start,
70792 end, prev->vm_pgoff, NULL);
70793 +
70794 +#ifdef CONFIG_PAX_SEGMEXEC
70795 + if (!err && prev_m)
70796 + err = vma_adjust(prev_m, prev_m->vm_start,
70797 + end_m, prev_m->vm_pgoff, NULL);
70798 +#endif
70799 +
70800 + }
70801 if (err)
70802 return NULL;
70803 khugepaged_enter_vma_merge(prev);
70804 @@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70805 mpol_equal(policy, vma_policy(next)) &&
70806 can_vma_merge_before(next, vm_flags,
70807 anon_vma, file, pgoff+pglen)) {
70808 - if (prev && addr < prev->vm_end) /* case 4 */
70809 + if (prev && addr < prev->vm_end) { /* case 4 */
70810 err = vma_adjust(prev, prev->vm_start,
70811 addr, prev->vm_pgoff, NULL);
70812 - else /* cases 3, 8 */
70813 +
70814 +#ifdef CONFIG_PAX_SEGMEXEC
70815 + if (!err && prev_m)
70816 + err = vma_adjust(prev_m, prev_m->vm_start,
70817 + addr_m, prev_m->vm_pgoff, NULL);
70818 +#endif
70819 +
70820 + } else { /* cases 3, 8 */
70821 err = vma_adjust(area, addr, next->vm_end,
70822 next->vm_pgoff - pglen, NULL);
70823 +
70824 +#ifdef CONFIG_PAX_SEGMEXEC
70825 + if (!err && area_m)
70826 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
70827 + next_m->vm_pgoff - pglen, NULL);
70828 +#endif
70829 +
70830 + }
70831 if (err)
70832 return NULL;
70833 khugepaged_enter_vma_merge(area);
70834 @@ -922,14 +1002,11 @@ none:
70835 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70836 struct file *file, long pages)
70837 {
70838 - const unsigned long stack_flags
70839 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70840 -
70841 if (file) {
70842 mm->shared_vm += pages;
70843 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70844 mm->exec_vm += pages;
70845 - } else if (flags & stack_flags)
70846 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70847 mm->stack_vm += pages;
70848 if (flags & (VM_RESERVED|VM_IO))
70849 mm->reserved_vm += pages;
70850 @@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70851 * (the exception is when the underlying filesystem is noexec
70852 * mounted, in which case we dont add PROT_EXEC.)
70853 */
70854 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70855 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70856 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70857 prot |= PROT_EXEC;
70858
70859 @@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70860 /* Obtain the address to map to. we verify (or select) it and ensure
70861 * that it represents a valid section of the address space.
70862 */
70863 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
70864 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70865 if (addr & ~PAGE_MASK)
70866 return addr;
70867
70868 @@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70869 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70870 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70871
70872 +#ifdef CONFIG_PAX_MPROTECT
70873 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70874 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70875 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70876 + gr_log_rwxmmap(file);
70877 +
70878 +#ifdef CONFIG_PAX_EMUPLT
70879 + vm_flags &= ~VM_EXEC;
70880 +#else
70881 + return -EPERM;
70882 +#endif
70883 +
70884 + }
70885 +
70886 + if (!(vm_flags & VM_EXEC))
70887 + vm_flags &= ~VM_MAYEXEC;
70888 +#else
70889 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70890 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70891 +#endif
70892 + else
70893 + vm_flags &= ~VM_MAYWRITE;
70894 + }
70895 +#endif
70896 +
70897 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70898 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70899 + vm_flags &= ~VM_PAGEEXEC;
70900 +#endif
70901 +
70902 if (flags & MAP_LOCKED)
70903 if (!can_do_mlock())
70904 return -EPERM;
70905 @@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70906 locked += mm->locked_vm;
70907 lock_limit = rlimit(RLIMIT_MEMLOCK);
70908 lock_limit >>= PAGE_SHIFT;
70909 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70910 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70911 return -EAGAIN;
70912 }
70913 @@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70914 if (error)
70915 return error;
70916
70917 + if (!gr_acl_handle_mmap(file, prot))
70918 + return -EACCES;
70919 +
70920 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70921 }
70922
70923 @@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70924 vm_flags_t vm_flags = vma->vm_flags;
70925
70926 /* If it was private or non-writable, the write bit is already clear */
70927 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70928 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70929 return 0;
70930
70931 /* The backer wishes to know when pages are first written to? */
70932 @@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70933 unsigned long charged = 0;
70934 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70935
70936 +#ifdef CONFIG_PAX_SEGMEXEC
70937 + struct vm_area_struct *vma_m = NULL;
70938 +#endif
70939 +
70940 + /*
70941 + * mm->mmap_sem is required to protect against another thread
70942 + * changing the mappings in case we sleep.
70943 + */
70944 + verify_mm_writelocked(mm);
70945 +
70946 /* Clear old maps */
70947 error = -ENOMEM;
70948 -munmap_back:
70949 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70950 if (vma && vma->vm_start < addr + len) {
70951 if (do_munmap(mm, addr, len))
70952 return -ENOMEM;
70953 - goto munmap_back;
70954 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70955 + BUG_ON(vma && vma->vm_start < addr + len);
70956 }
70957
70958 /* Check against address space limit. */
70959 @@ -1297,6 +1418,16 @@ munmap_back:
70960 goto unacct_error;
70961 }
70962
70963 +#ifdef CONFIG_PAX_SEGMEXEC
70964 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
70965 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70966 + if (!vma_m) {
70967 + error = -ENOMEM;
70968 + goto free_vma;
70969 + }
70970 + }
70971 +#endif
70972 +
70973 vma->vm_mm = mm;
70974 vma->vm_start = addr;
70975 vma->vm_end = addr + len;
70976 @@ -1321,6 +1452,19 @@ munmap_back:
70977 error = file->f_op->mmap(file, vma);
70978 if (error)
70979 goto unmap_and_free_vma;
70980 +
70981 +#ifdef CONFIG_PAX_SEGMEXEC
70982 + if (vma_m && (vm_flags & VM_EXECUTABLE))
70983 + added_exe_file_vma(mm);
70984 +#endif
70985 +
70986 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70987 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
70988 + vma->vm_flags |= VM_PAGEEXEC;
70989 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70990 + }
70991 +#endif
70992 +
70993 if (vm_flags & VM_EXECUTABLE)
70994 added_exe_file_vma(mm);
70995
70996 @@ -1358,6 +1502,11 @@ munmap_back:
70997 vma_link(mm, vma, prev, rb_link, rb_parent);
70998 file = vma->vm_file;
70999
71000 +#ifdef CONFIG_PAX_SEGMEXEC
71001 + if (vma_m)
71002 + BUG_ON(pax_mirror_vma(vma_m, vma));
71003 +#endif
71004 +
71005 /* Once vma denies write, undo our temporary denial count */
71006 if (correct_wcount)
71007 atomic_inc(&inode->i_writecount);
71008 @@ -1366,6 +1515,7 @@ out:
71009
71010 mm->total_vm += len >> PAGE_SHIFT;
71011 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71012 + track_exec_limit(mm, addr, addr + len, vm_flags);
71013 if (vm_flags & VM_LOCKED) {
71014 if (!mlock_vma_pages_range(vma, addr, addr + len))
71015 mm->locked_vm += (len >> PAGE_SHIFT);
71016 @@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71017 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71018 charged = 0;
71019 free_vma:
71020 +
71021 +#ifdef CONFIG_PAX_SEGMEXEC
71022 + if (vma_m)
71023 + kmem_cache_free(vm_area_cachep, vma_m);
71024 +#endif
71025 +
71026 kmem_cache_free(vm_area_cachep, vma);
71027 unacct_error:
71028 if (charged)
71029 @@ -1390,6 +1546,44 @@ unacct_error:
71030 return error;
71031 }
71032
71033 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71034 +{
71035 + if (!vma) {
71036 +#ifdef CONFIG_STACK_GROWSUP
71037 + if (addr > sysctl_heap_stack_gap)
71038 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71039 + else
71040 + vma = find_vma(current->mm, 0);
71041 + if (vma && (vma->vm_flags & VM_GROWSUP))
71042 + return false;
71043 +#endif
71044 + return true;
71045 + }
71046 +
71047 + if (addr + len > vma->vm_start)
71048 + return false;
71049 +
71050 + if (vma->vm_flags & VM_GROWSDOWN)
71051 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71052 +#ifdef CONFIG_STACK_GROWSUP
71053 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71054 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71055 +#endif
71056 +
71057 + return true;
71058 +}
71059 +
71060 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71061 +{
71062 + if (vma->vm_start < len)
71063 + return -ENOMEM;
71064 + if (!(vma->vm_flags & VM_GROWSDOWN))
71065 + return vma->vm_start - len;
71066 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71067 + return vma->vm_start - len - sysctl_heap_stack_gap;
71068 + return -ENOMEM;
71069 +}
71070 +
71071 /* Get an address range which is currently unmapped.
71072 * For shmat() with addr=0.
71073 *
71074 @@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71075 if (flags & MAP_FIXED)
71076 return addr;
71077
71078 +#ifdef CONFIG_PAX_RANDMMAP
71079 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71080 +#endif
71081 +
71082 if (addr) {
71083 addr = PAGE_ALIGN(addr);
71084 - vma = find_vma(mm, addr);
71085 - if (TASK_SIZE - len >= addr &&
71086 - (!vma || addr + len <= vma->vm_start))
71087 - return addr;
71088 + if (TASK_SIZE - len >= addr) {
71089 + vma = find_vma(mm, addr);
71090 + if (check_heap_stack_gap(vma, addr, len))
71091 + return addr;
71092 + }
71093 }
71094 if (len > mm->cached_hole_size) {
71095 - start_addr = addr = mm->free_area_cache;
71096 + start_addr = addr = mm->free_area_cache;
71097 } else {
71098 - start_addr = addr = TASK_UNMAPPED_BASE;
71099 - mm->cached_hole_size = 0;
71100 + start_addr = addr = mm->mmap_base;
71101 + mm->cached_hole_size = 0;
71102 }
71103
71104 full_search:
71105 @@ -1438,34 +1637,40 @@ full_search:
71106 * Start a new search - just in case we missed
71107 * some holes.
71108 */
71109 - if (start_addr != TASK_UNMAPPED_BASE) {
71110 - addr = TASK_UNMAPPED_BASE;
71111 - start_addr = addr;
71112 + if (start_addr != mm->mmap_base) {
71113 + start_addr = addr = mm->mmap_base;
71114 mm->cached_hole_size = 0;
71115 goto full_search;
71116 }
71117 return -ENOMEM;
71118 }
71119 - if (!vma || addr + len <= vma->vm_start) {
71120 - /*
71121 - * Remember the place where we stopped the search:
71122 - */
71123 - mm->free_area_cache = addr + len;
71124 - return addr;
71125 - }
71126 + if (check_heap_stack_gap(vma, addr, len))
71127 + break;
71128 if (addr + mm->cached_hole_size < vma->vm_start)
71129 mm->cached_hole_size = vma->vm_start - addr;
71130 addr = vma->vm_end;
71131 }
71132 +
71133 + /*
71134 + * Remember the place where we stopped the search:
71135 + */
71136 + mm->free_area_cache = addr + len;
71137 + return addr;
71138 }
71139 #endif
71140
71141 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71142 {
71143 +
71144 +#ifdef CONFIG_PAX_SEGMEXEC
71145 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71146 + return;
71147 +#endif
71148 +
71149 /*
71150 * Is this a new hole at the lowest possible address?
71151 */
71152 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71153 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71154 mm->free_area_cache = addr;
71155 }
71156
71157 @@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71158 {
71159 struct vm_area_struct *vma;
71160 struct mm_struct *mm = current->mm;
71161 - unsigned long addr = addr0, start_addr;
71162 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71163
71164 /* requested length too big for entire address space */
71165 if (len > TASK_SIZE)
71166 @@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71167 if (flags & MAP_FIXED)
71168 return addr;
71169
71170 +#ifdef CONFIG_PAX_RANDMMAP
71171 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71172 +#endif
71173 +
71174 /* requesting a specific address */
71175 if (addr) {
71176 addr = PAGE_ALIGN(addr);
71177 - vma = find_vma(mm, addr);
71178 - if (TASK_SIZE - len >= addr &&
71179 - (!vma || addr + len <= vma->vm_start))
71180 - return addr;
71181 + if (TASK_SIZE - len >= addr) {
71182 + vma = find_vma(mm, addr);
71183 + if (check_heap_stack_gap(vma, addr, len))
71184 + return addr;
71185 + }
71186 }
71187
71188 /* check if free_area_cache is useful for us */
71189 @@ -1520,7 +1730,7 @@ try_again:
71190 * return with success:
71191 */
71192 vma = find_vma(mm, addr);
71193 - if (!vma || addr+len <= vma->vm_start)
71194 + if (check_heap_stack_gap(vma, addr, len))
71195 /* remember the address as a hint for next time */
71196 return (mm->free_area_cache = addr);
71197
71198 @@ -1529,8 +1739,8 @@ try_again:
71199 mm->cached_hole_size = vma->vm_start - addr;
71200
71201 /* try just below the current vma->vm_start */
71202 - addr = vma->vm_start-len;
71203 - } while (len < vma->vm_start);
71204 + addr = skip_heap_stack_gap(vma, len);
71205 + } while (!IS_ERR_VALUE(addr));
71206
71207 fail:
71208 /*
71209 @@ -1553,13 +1763,21 @@ fail:
71210 * can happen with large stack limits and large mmap()
71211 * allocations.
71212 */
71213 + mm->mmap_base = TASK_UNMAPPED_BASE;
71214 +
71215 +#ifdef CONFIG_PAX_RANDMMAP
71216 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71217 + mm->mmap_base += mm->delta_mmap;
71218 +#endif
71219 +
71220 + mm->free_area_cache = mm->mmap_base;
71221 mm->cached_hole_size = ~0UL;
71222 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71223 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71224 /*
71225 * Restore the topdown base:
71226 */
71227 - mm->free_area_cache = mm->mmap_base;
71228 + mm->mmap_base = base;
71229 + mm->free_area_cache = base;
71230 mm->cached_hole_size = ~0UL;
71231
71232 return addr;
71233 @@ -1568,6 +1786,12 @@ fail:
71234
71235 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71236 {
71237 +
71238 +#ifdef CONFIG_PAX_SEGMEXEC
71239 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71240 + return;
71241 +#endif
71242 +
71243 /*
71244 * Is this a new hole at the highest possible address?
71245 */
71246 @@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71247 mm->free_area_cache = addr;
71248
71249 /* dont allow allocations above current base */
71250 - if (mm->free_area_cache > mm->mmap_base)
71251 + if (mm->free_area_cache > mm->mmap_base) {
71252 mm->free_area_cache = mm->mmap_base;
71253 + mm->cached_hole_size = ~0UL;
71254 + }
71255 }
71256
71257 unsigned long
71258 @@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71259 return vma;
71260 }
71261
71262 +#ifdef CONFIG_PAX_SEGMEXEC
71263 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71264 +{
71265 + struct vm_area_struct *vma_m;
71266 +
71267 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71268 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71269 + BUG_ON(vma->vm_mirror);
71270 + return NULL;
71271 + }
71272 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71273 + vma_m = vma->vm_mirror;
71274 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71275 + BUG_ON(vma->vm_file != vma_m->vm_file);
71276 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71277 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71278 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71279 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71280 + return vma_m;
71281 +}
71282 +#endif
71283 +
71284 /*
71285 * Verify that the stack growth is acceptable and
71286 * update accounting. This is shared with both the
71287 @@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71288 return -ENOMEM;
71289
71290 /* Stack limit test */
71291 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71292 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71293 return -ENOMEM;
71294
71295 @@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71296 locked = mm->locked_vm + grow;
71297 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71298 limit >>= PAGE_SHIFT;
71299 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71300 if (locked > limit && !capable(CAP_IPC_LOCK))
71301 return -ENOMEM;
71302 }
71303 @@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71304 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71305 * vma is the last one with address > vma->vm_end. Have to extend vma.
71306 */
71307 +#ifndef CONFIG_IA64
71308 +static
71309 +#endif
71310 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71311 {
71312 int error;
71313 + bool locknext;
71314
71315 if (!(vma->vm_flags & VM_GROWSUP))
71316 return -EFAULT;
71317
71318 + /* Also guard against wrapping around to address 0. */
71319 + if (address < PAGE_ALIGN(address+1))
71320 + address = PAGE_ALIGN(address+1);
71321 + else
71322 + return -ENOMEM;
71323 +
71324 /*
71325 * We must make sure the anon_vma is allocated
71326 * so that the anon_vma locking is not a noop.
71327 */
71328 if (unlikely(anon_vma_prepare(vma)))
71329 return -ENOMEM;
71330 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71331 + if (locknext && anon_vma_prepare(vma->vm_next))
71332 + return -ENOMEM;
71333 vma_lock_anon_vma(vma);
71334 + if (locknext)
71335 + vma_lock_anon_vma(vma->vm_next);
71336
71337 /*
71338 * vma->vm_start/vm_end cannot change under us because the caller
71339 * is required to hold the mmap_sem in read mode. We need the
71340 - * anon_vma lock to serialize against concurrent expand_stacks.
71341 - * Also guard against wrapping around to address 0.
71342 + * anon_vma locks to serialize against concurrent expand_stacks
71343 + * and expand_upwards.
71344 */
71345 - if (address < PAGE_ALIGN(address+4))
71346 - address = PAGE_ALIGN(address+4);
71347 - else {
71348 - vma_unlock_anon_vma(vma);
71349 - return -ENOMEM;
71350 - }
71351 error = 0;
71352
71353 /* Somebody else might have raced and expanded it already */
71354 - if (address > vma->vm_end) {
71355 + 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)
71356 + error = -ENOMEM;
71357 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71358 unsigned long size, grow;
71359
71360 size = address - vma->vm_start;
71361 @@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71362 }
71363 }
71364 }
71365 + if (locknext)
71366 + vma_unlock_anon_vma(vma->vm_next);
71367 vma_unlock_anon_vma(vma);
71368 khugepaged_enter_vma_merge(vma);
71369 return error;
71370 @@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
71371 unsigned long address)
71372 {
71373 int error;
71374 + bool lockprev = false;
71375 + struct vm_area_struct *prev;
71376
71377 /*
71378 * We must make sure the anon_vma is allocated
71379 @@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
71380 if (error)
71381 return error;
71382
71383 + prev = vma->vm_prev;
71384 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71385 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71386 +#endif
71387 + if (lockprev && anon_vma_prepare(prev))
71388 + return -ENOMEM;
71389 + if (lockprev)
71390 + vma_lock_anon_vma(prev);
71391 +
71392 vma_lock_anon_vma(vma);
71393
71394 /*
71395 @@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
71396 */
71397
71398 /* Somebody else might have raced and expanded it already */
71399 - if (address < vma->vm_start) {
71400 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71401 + error = -ENOMEM;
71402 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71403 unsigned long size, grow;
71404
71405 +#ifdef CONFIG_PAX_SEGMEXEC
71406 + struct vm_area_struct *vma_m;
71407 +
71408 + vma_m = pax_find_mirror_vma(vma);
71409 +#endif
71410 +
71411 size = vma->vm_end - address;
71412 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71413
71414 @@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
71415 if (!error) {
71416 vma->vm_start = address;
71417 vma->vm_pgoff -= grow;
71418 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71419 +
71420 +#ifdef CONFIG_PAX_SEGMEXEC
71421 + if (vma_m) {
71422 + vma_m->vm_start -= grow << PAGE_SHIFT;
71423 + vma_m->vm_pgoff -= grow;
71424 + }
71425 +#endif
71426 +
71427 perf_event_mmap(vma);
71428 }
71429 }
71430 }
71431 vma_unlock_anon_vma(vma);
71432 + if (lockprev)
71433 + vma_unlock_anon_vma(prev);
71434 khugepaged_enter_vma_merge(vma);
71435 return error;
71436 }
71437 @@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71438 do {
71439 long nrpages = vma_pages(vma);
71440
71441 +#ifdef CONFIG_PAX_SEGMEXEC
71442 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71443 + vma = remove_vma(vma);
71444 + continue;
71445 + }
71446 +#endif
71447 +
71448 mm->total_vm -= nrpages;
71449 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71450 vma = remove_vma(vma);
71451 @@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71452 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71453 vma->vm_prev = NULL;
71454 do {
71455 +
71456 +#ifdef CONFIG_PAX_SEGMEXEC
71457 + if (vma->vm_mirror) {
71458 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71459 + vma->vm_mirror->vm_mirror = NULL;
71460 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
71461 + vma->vm_mirror = NULL;
71462 + }
71463 +#endif
71464 +
71465 rb_erase(&vma->vm_rb, &mm->mm_rb);
71466 mm->map_count--;
71467 tail_vma = vma;
71468 @@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71469 struct vm_area_struct *new;
71470 int err = -ENOMEM;
71471
71472 +#ifdef CONFIG_PAX_SEGMEXEC
71473 + struct vm_area_struct *vma_m, *new_m = NULL;
71474 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71475 +#endif
71476 +
71477 if (is_vm_hugetlb_page(vma) && (addr &
71478 ~(huge_page_mask(hstate_vma(vma)))))
71479 return -EINVAL;
71480
71481 +#ifdef CONFIG_PAX_SEGMEXEC
71482 + vma_m = pax_find_mirror_vma(vma);
71483 +#endif
71484 +
71485 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71486 if (!new)
71487 goto out_err;
71488
71489 +#ifdef CONFIG_PAX_SEGMEXEC
71490 + if (vma_m) {
71491 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71492 + if (!new_m) {
71493 + kmem_cache_free(vm_area_cachep, new);
71494 + goto out_err;
71495 + }
71496 + }
71497 +#endif
71498 +
71499 /* most fields are the same, copy all, and then fixup */
71500 *new = *vma;
71501
71502 @@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71503 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71504 }
71505
71506 +#ifdef CONFIG_PAX_SEGMEXEC
71507 + if (vma_m) {
71508 + *new_m = *vma_m;
71509 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71510 + new_m->vm_mirror = new;
71511 + new->vm_mirror = new_m;
71512 +
71513 + if (new_below)
71514 + new_m->vm_end = addr_m;
71515 + else {
71516 + new_m->vm_start = addr_m;
71517 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71518 + }
71519 + }
71520 +#endif
71521 +
71522 pol = mpol_dup(vma_policy(vma));
71523 if (IS_ERR(pol)) {
71524 err = PTR_ERR(pol);
71525 @@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71526 else
71527 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71528
71529 +#ifdef CONFIG_PAX_SEGMEXEC
71530 + if (!err && vma_m) {
71531 + if (anon_vma_clone(new_m, vma_m))
71532 + goto out_free_mpol;
71533 +
71534 + mpol_get(pol);
71535 + vma_set_policy(new_m, pol);
71536 +
71537 + if (new_m->vm_file) {
71538 + get_file(new_m->vm_file);
71539 + if (vma_m->vm_flags & VM_EXECUTABLE)
71540 + added_exe_file_vma(mm);
71541 + }
71542 +
71543 + if (new_m->vm_ops && new_m->vm_ops->open)
71544 + new_m->vm_ops->open(new_m);
71545 +
71546 + if (new_below)
71547 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71548 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71549 + else
71550 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71551 +
71552 + if (err) {
71553 + if (new_m->vm_ops && new_m->vm_ops->close)
71554 + new_m->vm_ops->close(new_m);
71555 + if (new_m->vm_file) {
71556 + if (vma_m->vm_flags & VM_EXECUTABLE)
71557 + removed_exe_file_vma(mm);
71558 + fput(new_m->vm_file);
71559 + }
71560 + mpol_put(pol);
71561 + }
71562 + }
71563 +#endif
71564 +
71565 /* Success. */
71566 if (!err)
71567 return 0;
71568 @@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71569 removed_exe_file_vma(mm);
71570 fput(new->vm_file);
71571 }
71572 - unlink_anon_vmas(new);
71573 out_free_mpol:
71574 mpol_put(pol);
71575 out_free_vma:
71576 +
71577 +#ifdef CONFIG_PAX_SEGMEXEC
71578 + if (new_m) {
71579 + unlink_anon_vmas(new_m);
71580 + kmem_cache_free(vm_area_cachep, new_m);
71581 + }
71582 +#endif
71583 +
71584 + unlink_anon_vmas(new);
71585 kmem_cache_free(vm_area_cachep, new);
71586 out_err:
71587 return err;
71588 @@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71589 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71590 unsigned long addr, int new_below)
71591 {
71592 +
71593 +#ifdef CONFIG_PAX_SEGMEXEC
71594 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71595 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71596 + if (mm->map_count >= sysctl_max_map_count-1)
71597 + return -ENOMEM;
71598 + } else
71599 +#endif
71600 +
71601 if (mm->map_count >= sysctl_max_map_count)
71602 return -ENOMEM;
71603
71604 @@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71605 * work. This now handles partial unmappings.
71606 * Jeremy Fitzhardinge <jeremy@goop.org>
71607 */
71608 +#ifdef CONFIG_PAX_SEGMEXEC
71609 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71610 {
71611 + int ret = __do_munmap(mm, start, len);
71612 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71613 + return ret;
71614 +
71615 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71616 +}
71617 +
71618 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71619 +#else
71620 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71621 +#endif
71622 +{
71623 unsigned long end;
71624 struct vm_area_struct *vma, *prev, *last;
71625
71626 + /*
71627 + * mm->mmap_sem is required to protect against another thread
71628 + * changing the mappings in case we sleep.
71629 + */
71630 + verify_mm_writelocked(mm);
71631 +
71632 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71633 return -EINVAL;
71634
71635 @@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71636 /* Fix up all other VM information */
71637 remove_vma_list(mm, vma);
71638
71639 + track_exec_limit(mm, start, end, 0UL);
71640 +
71641 return 0;
71642 }
71643 EXPORT_SYMBOL(do_munmap);
71644 @@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
71645 int ret;
71646 struct mm_struct *mm = current->mm;
71647
71648 +
71649 +#ifdef CONFIG_PAX_SEGMEXEC
71650 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71651 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
71652 + return -EINVAL;
71653 +#endif
71654 +
71655 down_write(&mm->mmap_sem);
71656 ret = do_munmap(mm, start, len);
71657 up_write(&mm->mmap_sem);
71658 @@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71659 return vm_munmap(addr, len);
71660 }
71661
71662 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71663 -{
71664 -#ifdef CONFIG_DEBUG_VM
71665 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71666 - WARN_ON(1);
71667 - up_read(&mm->mmap_sem);
71668 - }
71669 -#endif
71670 -}
71671 -
71672 /*
71673 * this is really a simplified "do_mmap". it only handles
71674 * anonymous maps. eventually we may be able to do some
71675 @@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71676 struct rb_node ** rb_link, * rb_parent;
71677 pgoff_t pgoff = addr >> PAGE_SHIFT;
71678 int error;
71679 + unsigned long charged;
71680
71681 len = PAGE_ALIGN(len);
71682 if (!len)
71683 @@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71684
71685 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71686
71687 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71688 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71689 + flags &= ~VM_EXEC;
71690 +
71691 +#ifdef CONFIG_PAX_MPROTECT
71692 + if (mm->pax_flags & MF_PAX_MPROTECT)
71693 + flags &= ~VM_MAYEXEC;
71694 +#endif
71695 +
71696 + }
71697 +#endif
71698 +
71699 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71700 if (error & ~PAGE_MASK)
71701 return error;
71702
71703 + charged = len >> PAGE_SHIFT;
71704 +
71705 /*
71706 * mlock MCL_FUTURE?
71707 */
71708 if (mm->def_flags & VM_LOCKED) {
71709 unsigned long locked, lock_limit;
71710 - locked = len >> PAGE_SHIFT;
71711 + locked = charged;
71712 locked += mm->locked_vm;
71713 lock_limit = rlimit(RLIMIT_MEMLOCK);
71714 lock_limit >>= PAGE_SHIFT;
71715 @@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71716 /*
71717 * Clear old maps. this also does some error checking for us
71718 */
71719 - munmap_back:
71720 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71721 if (vma && vma->vm_start < addr + len) {
71722 if (do_munmap(mm, addr, len))
71723 return -ENOMEM;
71724 - goto munmap_back;
71725 - }
71726 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71727 + BUG_ON(vma && vma->vm_start < addr + len);
71728 + }
71729
71730 /* Check against address space limits *after* clearing old maps... */
71731 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71732 + if (!may_expand_vm(mm, charged))
71733 return -ENOMEM;
71734
71735 if (mm->map_count > sysctl_max_map_count)
71736 return -ENOMEM;
71737
71738 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
71739 + if (security_vm_enough_memory_mm(mm, charged))
71740 return -ENOMEM;
71741
71742 /* Can we just expand an old private anonymous mapping? */
71743 @@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71744 */
71745 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71746 if (!vma) {
71747 - vm_unacct_memory(len >> PAGE_SHIFT);
71748 + vm_unacct_memory(charged);
71749 return -ENOMEM;
71750 }
71751
71752 @@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71753 vma_link(mm, vma, prev, rb_link, rb_parent);
71754 out:
71755 perf_event_mmap(vma);
71756 - mm->total_vm += len >> PAGE_SHIFT;
71757 + mm->total_vm += charged;
71758 if (flags & VM_LOCKED) {
71759 if (!mlock_vma_pages_range(vma, addr, addr + len))
71760 - mm->locked_vm += (len >> PAGE_SHIFT);
71761 + mm->locked_vm += charged;
71762 }
71763 + track_exec_limit(mm, addr, addr + len, flags);
71764 return addr;
71765 }
71766
71767 @@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
71768 * Walk the list again, actually closing and freeing it,
71769 * with preemption enabled, without holding any MM locks.
71770 */
71771 - while (vma)
71772 + while (vma) {
71773 + vma->vm_mirror = NULL;
71774 vma = remove_vma(vma);
71775 + }
71776
71777 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71778 }
71779 @@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71780 struct vm_area_struct * __vma, * prev;
71781 struct rb_node ** rb_link, * rb_parent;
71782
71783 +#ifdef CONFIG_PAX_SEGMEXEC
71784 + struct vm_area_struct *vma_m = NULL;
71785 +#endif
71786 +
71787 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71788 + return -EPERM;
71789 +
71790 /*
71791 * The vm_pgoff of a purely anonymous vma should be irrelevant
71792 * until its first write fault, when page's anon_vma and index
71793 @@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71794 if ((vma->vm_flags & VM_ACCOUNT) &&
71795 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71796 return -ENOMEM;
71797 +
71798 +#ifdef CONFIG_PAX_SEGMEXEC
71799 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71800 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71801 + if (!vma_m)
71802 + return -ENOMEM;
71803 + }
71804 +#endif
71805 +
71806 vma_link(mm, vma, prev, rb_link, rb_parent);
71807 +
71808 +#ifdef CONFIG_PAX_SEGMEXEC
71809 + if (vma_m)
71810 + BUG_ON(pax_mirror_vma(vma_m, vma));
71811 +#endif
71812 +
71813 return 0;
71814 }
71815
71816 @@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71817 struct mempolicy *pol;
71818 bool faulted_in_anon_vma = true;
71819
71820 + BUG_ON(vma->vm_mirror);
71821 +
71822 /*
71823 * If anonymous vma has not yet been faulted, update new pgoff
71824 * to match new location, to increase its chance of merging.
71825 @@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71826 return NULL;
71827 }
71828
71829 +#ifdef CONFIG_PAX_SEGMEXEC
71830 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71831 +{
71832 + struct vm_area_struct *prev_m;
71833 + struct rb_node **rb_link_m, *rb_parent_m;
71834 + struct mempolicy *pol_m;
71835 +
71836 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71837 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71838 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71839 + *vma_m = *vma;
71840 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71841 + if (anon_vma_clone(vma_m, vma))
71842 + return -ENOMEM;
71843 + pol_m = vma_policy(vma_m);
71844 + mpol_get(pol_m);
71845 + vma_set_policy(vma_m, pol_m);
71846 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71847 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71848 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71849 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71850 + if (vma_m->vm_file)
71851 + get_file(vma_m->vm_file);
71852 + if (vma_m->vm_ops && vma_m->vm_ops->open)
71853 + vma_m->vm_ops->open(vma_m);
71854 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71855 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71856 + vma_m->vm_mirror = vma;
71857 + vma->vm_mirror = vma_m;
71858 + return 0;
71859 +}
71860 +#endif
71861 +
71862 /*
71863 * Return true if the calling process may expand its vm space by the passed
71864 * number of pages
71865 @@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71866
71867 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71868
71869 +#ifdef CONFIG_PAX_RANDMMAP
71870 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71871 + cur -= mm->brk_gap;
71872 +#endif
71873 +
71874 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71875 if (cur + npages > lim)
71876 return 0;
71877 return 1;
71878 @@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
71879 vma->vm_start = addr;
71880 vma->vm_end = addr + len;
71881
71882 +#ifdef CONFIG_PAX_MPROTECT
71883 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71884 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71885 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71886 + return -EPERM;
71887 + if (!(vm_flags & VM_EXEC))
71888 + vm_flags &= ~VM_MAYEXEC;
71889 +#else
71890 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71891 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71892 +#endif
71893 + else
71894 + vm_flags &= ~VM_MAYWRITE;
71895 + }
71896 +#endif
71897 +
71898 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71899 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71900
71901 diff --git a/mm/mprotect.c b/mm/mprotect.c
71902 index a409926..8b32e6d 100644
71903 --- a/mm/mprotect.c
71904 +++ b/mm/mprotect.c
71905 @@ -23,10 +23,17 @@
71906 #include <linux/mmu_notifier.h>
71907 #include <linux/migrate.h>
71908 #include <linux/perf_event.h>
71909 +
71910 +#ifdef CONFIG_PAX_MPROTECT
71911 +#include <linux/elf.h>
71912 +#include <linux/binfmts.h>
71913 +#endif
71914 +
71915 #include <asm/uaccess.h>
71916 #include <asm/pgtable.h>
71917 #include <asm/cacheflush.h>
71918 #include <asm/tlbflush.h>
71919 +#include <asm/mmu_context.h>
71920
71921 #ifndef pgprot_modify
71922 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71923 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
71924 flush_tlb_range(vma, start, end);
71925 }
71926
71927 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71928 +/* called while holding the mmap semaphor for writing except stack expansion */
71929 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71930 +{
71931 + unsigned long oldlimit, newlimit = 0UL;
71932 +
71933 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71934 + return;
71935 +
71936 + spin_lock(&mm->page_table_lock);
71937 + oldlimit = mm->context.user_cs_limit;
71938 + if ((prot & VM_EXEC) && oldlimit < end)
71939 + /* USER_CS limit moved up */
71940 + newlimit = end;
71941 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
71942 + /* USER_CS limit moved down */
71943 + newlimit = start;
71944 +
71945 + if (newlimit) {
71946 + mm->context.user_cs_limit = newlimit;
71947 +
71948 +#ifdef CONFIG_SMP
71949 + wmb();
71950 + cpus_clear(mm->context.cpu_user_cs_mask);
71951 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
71952 +#endif
71953 +
71954 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
71955 + }
71956 + spin_unlock(&mm->page_table_lock);
71957 + if (newlimit == end) {
71958 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
71959 +
71960 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
71961 + if (is_vm_hugetlb_page(vma))
71962 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
71963 + else
71964 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
71965 + }
71966 +}
71967 +#endif
71968 +
71969 int
71970 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71971 unsigned long start, unsigned long end, unsigned long newflags)
71972 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71973 int error;
71974 int dirty_accountable = 0;
71975
71976 +#ifdef CONFIG_PAX_SEGMEXEC
71977 + struct vm_area_struct *vma_m = NULL;
71978 + unsigned long start_m, end_m;
71979 +
71980 + start_m = start + SEGMEXEC_TASK_SIZE;
71981 + end_m = end + SEGMEXEC_TASK_SIZE;
71982 +#endif
71983 +
71984 if (newflags == oldflags) {
71985 *pprev = vma;
71986 return 0;
71987 }
71988
71989 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
71990 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
71991 +
71992 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
71993 + return -ENOMEM;
71994 +
71995 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
71996 + return -ENOMEM;
71997 + }
71998 +
71999 /*
72000 * If we make a private mapping writable we increase our commit;
72001 * but (without finer accounting) cannot reduce our commit if we
72002 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72003 }
72004 }
72005
72006 +#ifdef CONFIG_PAX_SEGMEXEC
72007 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72008 + if (start != vma->vm_start) {
72009 + error = split_vma(mm, vma, start, 1);
72010 + if (error)
72011 + goto fail;
72012 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72013 + *pprev = (*pprev)->vm_next;
72014 + }
72015 +
72016 + if (end != vma->vm_end) {
72017 + error = split_vma(mm, vma, end, 0);
72018 + if (error)
72019 + goto fail;
72020 + }
72021 +
72022 + if (pax_find_mirror_vma(vma)) {
72023 + error = __do_munmap(mm, start_m, end_m - start_m);
72024 + if (error)
72025 + goto fail;
72026 + } else {
72027 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72028 + if (!vma_m) {
72029 + error = -ENOMEM;
72030 + goto fail;
72031 + }
72032 + vma->vm_flags = newflags;
72033 + error = pax_mirror_vma(vma_m, vma);
72034 + if (error) {
72035 + vma->vm_flags = oldflags;
72036 + goto fail;
72037 + }
72038 + }
72039 + }
72040 +#endif
72041 +
72042 /*
72043 * First try to merge with previous and/or next vma.
72044 */
72045 @@ -204,9 +307,21 @@ success:
72046 * vm_flags and vm_page_prot are protected by the mmap_sem
72047 * held in write mode.
72048 */
72049 +
72050 +#ifdef CONFIG_PAX_SEGMEXEC
72051 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72052 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72053 +#endif
72054 +
72055 vma->vm_flags = newflags;
72056 +
72057 +#ifdef CONFIG_PAX_MPROTECT
72058 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72059 + mm->binfmt->handle_mprotect(vma, newflags);
72060 +#endif
72061 +
72062 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72063 - vm_get_page_prot(newflags));
72064 + vm_get_page_prot(vma->vm_flags));
72065
72066 if (vma_wants_writenotify(vma)) {
72067 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72068 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72069 end = start + len;
72070 if (end <= start)
72071 return -ENOMEM;
72072 +
72073 +#ifdef CONFIG_PAX_SEGMEXEC
72074 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72075 + if (end > SEGMEXEC_TASK_SIZE)
72076 + return -EINVAL;
72077 + } else
72078 +#endif
72079 +
72080 + if (end > TASK_SIZE)
72081 + return -EINVAL;
72082 +
72083 if (!arch_validate_prot(prot))
72084 return -EINVAL;
72085
72086 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72087 /*
72088 * Does the application expect PROT_READ to imply PROT_EXEC:
72089 */
72090 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72091 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72092 prot |= PROT_EXEC;
72093
72094 vm_flags = calc_vm_prot_bits(prot);
72095 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72096 if (start > vma->vm_start)
72097 prev = vma;
72098
72099 +#ifdef CONFIG_PAX_MPROTECT
72100 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72101 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72102 +#endif
72103 +
72104 for (nstart = start ; ; ) {
72105 unsigned long newflags;
72106
72107 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72108
72109 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72110 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72111 + if (prot & (PROT_WRITE | PROT_EXEC))
72112 + gr_log_rwxmprotect(vma->vm_file);
72113 +
72114 + error = -EACCES;
72115 + goto out;
72116 + }
72117 +
72118 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72119 error = -EACCES;
72120 goto out;
72121 }
72122 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72123 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72124 if (error)
72125 goto out;
72126 +
72127 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72128 +
72129 nstart = tmp;
72130
72131 if (nstart < prev->vm_end)
72132 diff --git a/mm/mremap.c b/mm/mremap.c
72133 index db8d983..76506cb 100644
72134 --- a/mm/mremap.c
72135 +++ b/mm/mremap.c
72136 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72137 continue;
72138 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72139 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72140 +
72141 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72142 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72143 + pte = pte_exprotect(pte);
72144 +#endif
72145 +
72146 set_pte_at(mm, new_addr, new_pte, pte);
72147 }
72148
72149 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72150 if (is_vm_hugetlb_page(vma))
72151 goto Einval;
72152
72153 +#ifdef CONFIG_PAX_SEGMEXEC
72154 + if (pax_find_mirror_vma(vma))
72155 + goto Einval;
72156 +#endif
72157 +
72158 /* We can't remap across vm area boundaries */
72159 if (old_len > vma->vm_end - addr)
72160 goto Efault;
72161 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72162 unsigned long ret = -EINVAL;
72163 unsigned long charged = 0;
72164 unsigned long map_flags;
72165 + unsigned long pax_task_size = TASK_SIZE;
72166
72167 if (new_addr & ~PAGE_MASK)
72168 goto out;
72169
72170 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72171 +#ifdef CONFIG_PAX_SEGMEXEC
72172 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72173 + pax_task_size = SEGMEXEC_TASK_SIZE;
72174 +#endif
72175 +
72176 + pax_task_size -= PAGE_SIZE;
72177 +
72178 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72179 goto out;
72180
72181 /* Check if the location we're moving into overlaps the
72182 * old location at all, and fail if it does.
72183 */
72184 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72185 - goto out;
72186 -
72187 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72188 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72189 goto out;
72190
72191 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72192 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72193 struct vm_area_struct *vma;
72194 unsigned long ret = -EINVAL;
72195 unsigned long charged = 0;
72196 + unsigned long pax_task_size = TASK_SIZE;
72197
72198 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72199 goto out;
72200 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72201 if (!new_len)
72202 goto out;
72203
72204 +#ifdef CONFIG_PAX_SEGMEXEC
72205 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72206 + pax_task_size = SEGMEXEC_TASK_SIZE;
72207 +#endif
72208 +
72209 + pax_task_size -= PAGE_SIZE;
72210 +
72211 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72212 + old_len > pax_task_size || addr > pax_task_size-old_len)
72213 + goto out;
72214 +
72215 if (flags & MREMAP_FIXED) {
72216 if (flags & MREMAP_MAYMOVE)
72217 ret = mremap_to(addr, old_len, new_addr, new_len);
72218 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72219 addr + new_len);
72220 }
72221 ret = addr;
72222 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72223 goto out;
72224 }
72225 }
72226 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72227 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72228 if (ret)
72229 goto out;
72230 +
72231 + map_flags = vma->vm_flags;
72232 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72233 + if (!(ret & ~PAGE_MASK)) {
72234 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72235 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72236 + }
72237 }
72238 out:
72239 if (ret & ~PAGE_MASK)
72240 diff --git a/mm/nommu.c b/mm/nommu.c
72241 index bb8f4f0..40d3e02 100644
72242 --- a/mm/nommu.c
72243 +++ b/mm/nommu.c
72244 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72245 int sysctl_overcommit_ratio = 50; /* default is 50% */
72246 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72247 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72248 -int heap_stack_gap = 0;
72249
72250 atomic_long_t mmap_pages_allocated;
72251
72252 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72253 EXPORT_SYMBOL(find_vma);
72254
72255 /*
72256 - * find a VMA
72257 - * - we don't extend stack VMAs under NOMMU conditions
72258 - */
72259 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72260 -{
72261 - return find_vma(mm, addr);
72262 -}
72263 -
72264 -/*
72265 * expand a stack to a given address
72266 * - not supported under NOMMU conditions
72267 */
72268 @@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72269
72270 /* most fields are the same, copy all, and then fixup */
72271 *new = *vma;
72272 + INIT_LIST_HEAD(&new->anon_vma_chain);
72273 *region = *vma->vm_region;
72274 new->vm_region = region;
72275
72276 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72277 index 918330f..ae99ae1 100644
72278 --- a/mm/page_alloc.c
72279 +++ b/mm/page_alloc.c
72280 @@ -335,7 +335,7 @@ out:
72281 * This usage means that zero-order pages may not be compound.
72282 */
72283
72284 -static void free_compound_page(struct page *page)
72285 +void free_compound_page(struct page *page)
72286 {
72287 __free_pages_ok(page, compound_order(page));
72288 }
72289 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72290 int i;
72291 int bad = 0;
72292
72293 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72294 + unsigned long index = 1UL << order;
72295 +#endif
72296 +
72297 trace_mm_page_free(page, order);
72298 kmemcheck_free_shadow(page, order);
72299
72300 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72301 debug_check_no_obj_freed(page_address(page),
72302 PAGE_SIZE << order);
72303 }
72304 +
72305 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72306 + for (; index; --index)
72307 + sanitize_highpage(page + index - 1);
72308 +#endif
72309 +
72310 arch_free_page(page, order);
72311 kernel_map_pages(page, 1 << order, 0);
72312
72313 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72314 arch_alloc_page(page, order);
72315 kernel_map_pages(page, 1 << order, 1);
72316
72317 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
72318 if (gfp_flags & __GFP_ZERO)
72319 prep_zero_page(page, order, gfp_flags);
72320 +#endif
72321
72322 if (order && (gfp_flags & __GFP_COMP))
72323 prep_compound_page(page, order);
72324 @@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72325 unsigned long pfn;
72326
72327 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72328 +#ifdef CONFIG_X86_32
72329 + /* boot failures in VMware 8 on 32bit vanilla since
72330 + this change */
72331 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72332 +#else
72333 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72334 +#endif
72335 return 1;
72336 }
72337 return 0;
72338 diff --git a/mm/percpu.c b/mm/percpu.c
72339 index bb4be74..a43ea85 100644
72340 --- a/mm/percpu.c
72341 +++ b/mm/percpu.c
72342 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72343 static unsigned int pcpu_high_unit_cpu __read_mostly;
72344
72345 /* the address of the first chunk which starts with the kernel static area */
72346 -void *pcpu_base_addr __read_mostly;
72347 +void *pcpu_base_addr __read_only;
72348 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72349
72350 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72351 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72352 index c20ff48..137702a 100644
72353 --- a/mm/process_vm_access.c
72354 +++ b/mm/process_vm_access.c
72355 @@ -13,6 +13,7 @@
72356 #include <linux/uio.h>
72357 #include <linux/sched.h>
72358 #include <linux/highmem.h>
72359 +#include <linux/security.h>
72360 #include <linux/ptrace.h>
72361 #include <linux/slab.h>
72362 #include <linux/syscalls.h>
72363 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72364 size_t iov_l_curr_offset = 0;
72365 ssize_t iov_len;
72366
72367 + return -ENOSYS; // PaX: until properly audited
72368 +
72369 /*
72370 * Work out how many pages of struct pages we're going to need
72371 * when eventually calling get_user_pages
72372 */
72373 for (i = 0; i < riovcnt; i++) {
72374 iov_len = rvec[i].iov_len;
72375 - if (iov_len > 0) {
72376 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
72377 - + iov_len)
72378 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72379 - / PAGE_SIZE + 1;
72380 - nr_pages = max(nr_pages, nr_pages_iov);
72381 - }
72382 + if (iov_len <= 0)
72383 + continue;
72384 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72385 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72386 + nr_pages = max(nr_pages, nr_pages_iov);
72387 }
72388
72389 if (nr_pages == 0)
72390 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72391 goto free_proc_pages;
72392 }
72393
72394 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72395 + rc = -EPERM;
72396 + goto put_task_struct;
72397 + }
72398 +
72399 mm = mm_access(task, PTRACE_MODE_ATTACH);
72400 if (!mm || IS_ERR(mm)) {
72401 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72402 diff --git a/mm/rmap.c b/mm/rmap.c
72403 index 5b5ad58..0f77903 100644
72404 --- a/mm/rmap.c
72405 +++ b/mm/rmap.c
72406 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72407 struct anon_vma *anon_vma = vma->anon_vma;
72408 struct anon_vma_chain *avc;
72409
72410 +#ifdef CONFIG_PAX_SEGMEXEC
72411 + struct anon_vma_chain *avc_m = NULL;
72412 +#endif
72413 +
72414 might_sleep();
72415 if (unlikely(!anon_vma)) {
72416 struct mm_struct *mm = vma->vm_mm;
72417 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72418 if (!avc)
72419 goto out_enomem;
72420
72421 +#ifdef CONFIG_PAX_SEGMEXEC
72422 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72423 + if (!avc_m)
72424 + goto out_enomem_free_avc;
72425 +#endif
72426 +
72427 anon_vma = find_mergeable_anon_vma(vma);
72428 allocated = NULL;
72429 if (!anon_vma) {
72430 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72431 /* page_table_lock to protect against threads */
72432 spin_lock(&mm->page_table_lock);
72433 if (likely(!vma->anon_vma)) {
72434 +
72435 +#ifdef CONFIG_PAX_SEGMEXEC
72436 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72437 +
72438 + if (vma_m) {
72439 + BUG_ON(vma_m->anon_vma);
72440 + vma_m->anon_vma = anon_vma;
72441 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
72442 + avc_m = NULL;
72443 + }
72444 +#endif
72445 +
72446 vma->anon_vma = anon_vma;
72447 anon_vma_chain_link(vma, avc, anon_vma);
72448 allocated = NULL;
72449 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72450
72451 if (unlikely(allocated))
72452 put_anon_vma(allocated);
72453 +
72454 +#ifdef CONFIG_PAX_SEGMEXEC
72455 + if (unlikely(avc_m))
72456 + anon_vma_chain_free(avc_m);
72457 +#endif
72458 +
72459 if (unlikely(avc))
72460 anon_vma_chain_free(avc);
72461 }
72462 return 0;
72463
72464 out_enomem_free_avc:
72465 +
72466 +#ifdef CONFIG_PAX_SEGMEXEC
72467 + if (avc_m)
72468 + anon_vma_chain_free(avc_m);
72469 +#endif
72470 +
72471 anon_vma_chain_free(avc);
72472 out_enomem:
72473 return -ENOMEM;
72474 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
72475 * Attach the anon_vmas from src to dst.
72476 * Returns 0 on success, -ENOMEM on failure.
72477 */
72478 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72479 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72480 {
72481 struct anon_vma_chain *avc, *pavc;
72482 struct anon_vma *root = NULL;
72483 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
72484 * the corresponding VMA in the parent process is attached to.
72485 * Returns 0 on success, non-zero on failure.
72486 */
72487 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72488 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72489 {
72490 struct anon_vma_chain *avc;
72491 struct anon_vma *anon_vma;
72492 diff --git a/mm/shmem.c b/mm/shmem.c
72493 index 9d65a02..7c877e7 100644
72494 --- a/mm/shmem.c
72495 +++ b/mm/shmem.c
72496 @@ -31,7 +31,7 @@
72497 #include <linux/export.h>
72498 #include <linux/swap.h>
72499
72500 -static struct vfsmount *shm_mnt;
72501 +struct vfsmount *shm_mnt;
72502
72503 #ifdef CONFIG_SHMEM
72504 /*
72505 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72506 #define BOGO_DIRENT_SIZE 20
72507
72508 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72509 -#define SHORT_SYMLINK_LEN 128
72510 +#define SHORT_SYMLINK_LEN 64
72511
72512 struct shmem_xattr {
72513 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72514 @@ -2236,8 +2236,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72515 int err = -ENOMEM;
72516
72517 /* Round up to L1_CACHE_BYTES to resist false sharing */
72518 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72519 - L1_CACHE_BYTES), GFP_KERNEL);
72520 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72521 if (!sbinfo)
72522 return -ENOMEM;
72523
72524 diff --git a/mm/slab.c b/mm/slab.c
72525 index e901a36..ee8fe97 100644
72526 --- a/mm/slab.c
72527 +++ b/mm/slab.c
72528 @@ -153,7 +153,7 @@
72529
72530 /* Legal flag mask for kmem_cache_create(). */
72531 #if DEBUG
72532 -# define CREATE_MASK (SLAB_RED_ZONE | \
72533 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72534 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72535 SLAB_CACHE_DMA | \
72536 SLAB_STORE_USER | \
72537 @@ -161,7 +161,7 @@
72538 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72539 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72540 #else
72541 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72542 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72543 SLAB_CACHE_DMA | \
72544 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72545 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72546 @@ -290,7 +290,7 @@ struct kmem_list3 {
72547 * Need this for bootstrapping a per node allocator.
72548 */
72549 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72550 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72551 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72552 #define CACHE_CACHE 0
72553 #define SIZE_AC MAX_NUMNODES
72554 #define SIZE_L3 (2 * MAX_NUMNODES)
72555 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72556 if ((x)->max_freeable < i) \
72557 (x)->max_freeable = i; \
72558 } while (0)
72559 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72560 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72561 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72562 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72563 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72564 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72565 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72566 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72567 #else
72568 #define STATS_INC_ACTIVE(x) do { } while (0)
72569 #define STATS_DEC_ACTIVE(x) do { } while (0)
72570 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72571 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72572 */
72573 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72574 - const struct slab *slab, void *obj)
72575 + const struct slab *slab, const void *obj)
72576 {
72577 u32 offset = (obj - slab->s_mem);
72578 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72579 @@ -568,7 +568,7 @@ struct cache_names {
72580 static struct cache_names __initdata cache_names[] = {
72581 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72582 #include <linux/kmalloc_sizes.h>
72583 - {NULL,}
72584 + {NULL}
72585 #undef CACHE
72586 };
72587
72588 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72589 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72590 sizes[INDEX_AC].cs_size,
72591 ARCH_KMALLOC_MINALIGN,
72592 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72593 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72594 NULL);
72595
72596 if (INDEX_AC != INDEX_L3) {
72597 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72598 kmem_cache_create(names[INDEX_L3].name,
72599 sizes[INDEX_L3].cs_size,
72600 ARCH_KMALLOC_MINALIGN,
72601 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72602 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72603 NULL);
72604 }
72605
72606 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72607 sizes->cs_cachep = kmem_cache_create(names->name,
72608 sizes->cs_size,
72609 ARCH_KMALLOC_MINALIGN,
72610 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72611 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72612 NULL);
72613 }
72614 #ifdef CONFIG_ZONE_DMA
72615 @@ -4390,10 +4390,10 @@ static int s_show(struct seq_file *m, void *p)
72616 }
72617 /* cpu stats */
72618 {
72619 - unsigned long allochit = atomic_read(&cachep->allochit);
72620 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72621 - unsigned long freehit = atomic_read(&cachep->freehit);
72622 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72623 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72624 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72625 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72626 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72627
72628 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72629 allochit, allocmiss, freehit, freemiss);
72630 @@ -4652,13 +4652,62 @@ static int __init slab_proc_init(void)
72631 {
72632 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72633 #ifdef CONFIG_DEBUG_SLAB_LEAK
72634 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72635 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72636 #endif
72637 return 0;
72638 }
72639 module_init(slab_proc_init);
72640 #endif
72641
72642 +void check_object_size(const void *ptr, unsigned long n, bool to)
72643 +{
72644 +
72645 +#ifdef CONFIG_PAX_USERCOPY
72646 + struct page *page;
72647 + struct kmem_cache *cachep = NULL;
72648 + struct slab *slabp;
72649 + unsigned int objnr;
72650 + unsigned long offset;
72651 + const char *type;
72652 +
72653 + if (!n)
72654 + return;
72655 +
72656 + type = "<null>";
72657 + if (ZERO_OR_NULL_PTR(ptr))
72658 + goto report;
72659 +
72660 + if (!virt_addr_valid(ptr))
72661 + return;
72662 +
72663 + page = virt_to_head_page(ptr);
72664 +
72665 + type = "<process stack>";
72666 + if (!PageSlab(page)) {
72667 + if (object_is_on_stack(ptr, n) == -1)
72668 + goto report;
72669 + return;
72670 + }
72671 +
72672 + cachep = page_get_cache(page);
72673 + type = cachep->name;
72674 + if (!(cachep->flags & SLAB_USERCOPY))
72675 + goto report;
72676 +
72677 + slabp = page_get_slab(page);
72678 + objnr = obj_to_index(cachep, slabp, ptr);
72679 + BUG_ON(objnr >= cachep->num);
72680 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72681 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72682 + return;
72683 +
72684 +report:
72685 + pax_report_usercopy(ptr, n, to, type);
72686 +#endif
72687 +
72688 +}
72689 +EXPORT_SYMBOL(check_object_size);
72690 +
72691 /**
72692 * ksize - get the actual amount of memory allocated for a given object
72693 * @objp: Pointer to the object
72694 diff --git a/mm/slob.c b/mm/slob.c
72695 index 8105be4..e045f96 100644
72696 --- a/mm/slob.c
72697 +++ b/mm/slob.c
72698 @@ -29,7 +29,7 @@
72699 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72700 * alloc_pages() directly, allocating compound pages so the page order
72701 * does not have to be separately tracked, and also stores the exact
72702 - * allocation size in page->private so that it can be used to accurately
72703 + * allocation size in slob_page->size so that it can be used to accurately
72704 * provide ksize(). These objects are detected in kfree() because slob_page()
72705 * is false for them.
72706 *
72707 @@ -58,6 +58,7 @@
72708 */
72709
72710 #include <linux/kernel.h>
72711 +#include <linux/sched.h>
72712 #include <linux/slab.h>
72713 #include <linux/mm.h>
72714 #include <linux/swap.h> /* struct reclaim_state */
72715 @@ -102,7 +103,8 @@ struct slob_page {
72716 unsigned long flags; /* mandatory */
72717 atomic_t _count; /* mandatory */
72718 slobidx_t units; /* free units left in page */
72719 - unsigned long pad[2];
72720 + unsigned long pad[1];
72721 + unsigned long size; /* size when >=PAGE_SIZE */
72722 slob_t *free; /* first free slob_t in page */
72723 struct list_head list; /* linked list of free pages */
72724 };
72725 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72726 */
72727 static inline int is_slob_page(struct slob_page *sp)
72728 {
72729 - return PageSlab((struct page *)sp);
72730 + return PageSlab((struct page *)sp) && !sp->size;
72731 }
72732
72733 static inline void set_slob_page(struct slob_page *sp)
72734 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72735
72736 static inline struct slob_page *slob_page(const void *addr)
72737 {
72738 - return (struct slob_page *)virt_to_page(addr);
72739 + return (struct slob_page *)virt_to_head_page(addr);
72740 }
72741
72742 /*
72743 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72744 /*
72745 * Return the size of a slob block.
72746 */
72747 -static slobidx_t slob_units(slob_t *s)
72748 +static slobidx_t slob_units(const slob_t *s)
72749 {
72750 if (s->units > 0)
72751 return s->units;
72752 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72753 /*
72754 * Return the next free slob block pointer after this one.
72755 */
72756 -static slob_t *slob_next(slob_t *s)
72757 +static slob_t *slob_next(const slob_t *s)
72758 {
72759 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72760 slobidx_t next;
72761 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72762 /*
72763 * Returns true if s is the last free block in its page.
72764 */
72765 -static int slob_last(slob_t *s)
72766 +static int slob_last(const slob_t *s)
72767 {
72768 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72769 }
72770 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72771 if (!page)
72772 return NULL;
72773
72774 + set_slob_page(page);
72775 return page_address(page);
72776 }
72777
72778 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72779 if (!b)
72780 return NULL;
72781 sp = slob_page(b);
72782 - set_slob_page(sp);
72783
72784 spin_lock_irqsave(&slob_lock, flags);
72785 sp->units = SLOB_UNITS(PAGE_SIZE);
72786 sp->free = b;
72787 + sp->size = 0;
72788 INIT_LIST_HEAD(&sp->list);
72789 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72790 set_slob_page_free(sp, slob_list);
72791 @@ -476,10 +479,9 @@ out:
72792 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72793 */
72794
72795 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72796 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72797 {
72798 - unsigned int *m;
72799 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72800 + slob_t *m;
72801 void *ret;
72802
72803 gfp &= gfp_allowed_mask;
72804 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72805
72806 if (!m)
72807 return NULL;
72808 - *m = size;
72809 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72810 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72811 + m[0].units = size;
72812 + m[1].units = align;
72813 ret = (void *)m + align;
72814
72815 trace_kmalloc_node(_RET_IP_, ret,
72816 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72817 gfp |= __GFP_COMP;
72818 ret = slob_new_pages(gfp, order, node);
72819 if (ret) {
72820 - struct page *page;
72821 - page = virt_to_page(ret);
72822 - page->private = size;
72823 + struct slob_page *sp;
72824 + sp = slob_page(ret);
72825 + sp->size = size;
72826 }
72827
72828 trace_kmalloc_node(_RET_IP_, ret,
72829 size, PAGE_SIZE << order, gfp, node);
72830 }
72831
72832 - kmemleak_alloc(ret, size, 1, gfp);
72833 + return ret;
72834 +}
72835 +
72836 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72837 +{
72838 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72839 + void *ret = __kmalloc_node_align(size, gfp, node, align);
72840 +
72841 + if (!ZERO_OR_NULL_PTR(ret))
72842 + kmemleak_alloc(ret, size, 1, gfp);
72843 return ret;
72844 }
72845 EXPORT_SYMBOL(__kmalloc_node);
72846 @@ -533,13 +547,92 @@ void kfree(const void *block)
72847 sp = slob_page(block);
72848 if (is_slob_page(sp)) {
72849 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72850 - unsigned int *m = (unsigned int *)(block - align);
72851 - slob_free(m, *m + align);
72852 - } else
72853 + slob_t *m = (slob_t *)(block - align);
72854 + slob_free(m, m[0].units + align);
72855 + } else {
72856 + clear_slob_page(sp);
72857 + free_slob_page(sp);
72858 + sp->size = 0;
72859 put_page(&sp->page);
72860 + }
72861 }
72862 EXPORT_SYMBOL(kfree);
72863
72864 +void check_object_size(const void *ptr, unsigned long n, bool to)
72865 +{
72866 +
72867 +#ifdef CONFIG_PAX_USERCOPY
72868 + struct slob_page *sp;
72869 + const slob_t *free;
72870 + const void *base;
72871 + unsigned long flags;
72872 + const char *type;
72873 +
72874 + if (!n)
72875 + return;
72876 +
72877 + type = "<null>";
72878 + if (ZERO_OR_NULL_PTR(ptr))
72879 + goto report;
72880 +
72881 + if (!virt_addr_valid(ptr))
72882 + return;
72883 +
72884 + type = "<process stack>";
72885 + sp = slob_page(ptr);
72886 + if (!PageSlab((struct page *)sp)) {
72887 + if (object_is_on_stack(ptr, n) == -1)
72888 + goto report;
72889 + return;
72890 + }
72891 +
72892 + type = "<slob>";
72893 + if (sp->size) {
72894 + base = page_address(&sp->page);
72895 + if (base <= ptr && n <= sp->size - (ptr - base))
72896 + return;
72897 + goto report;
72898 + }
72899 +
72900 + /* some tricky double walking to find the chunk */
72901 + spin_lock_irqsave(&slob_lock, flags);
72902 + base = (void *)((unsigned long)ptr & PAGE_MASK);
72903 + free = sp->free;
72904 +
72905 + while (!slob_last(free) && (void *)free <= ptr) {
72906 + base = free + slob_units(free);
72907 + free = slob_next(free);
72908 + }
72909 +
72910 + while (base < (void *)free) {
72911 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72912 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
72913 + int offset;
72914 +
72915 + if (ptr < base + align)
72916 + break;
72917 +
72918 + offset = ptr - base - align;
72919 + if (offset >= m) {
72920 + base += size;
72921 + continue;
72922 + }
72923 +
72924 + if (n > m - offset)
72925 + break;
72926 +
72927 + spin_unlock_irqrestore(&slob_lock, flags);
72928 + return;
72929 + }
72930 +
72931 + spin_unlock_irqrestore(&slob_lock, flags);
72932 +report:
72933 + pax_report_usercopy(ptr, n, to, type);
72934 +#endif
72935 +
72936 +}
72937 +EXPORT_SYMBOL(check_object_size);
72938 +
72939 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72940 size_t ksize(const void *block)
72941 {
72942 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
72943 sp = slob_page(block);
72944 if (is_slob_page(sp)) {
72945 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72946 - unsigned int *m = (unsigned int *)(block - align);
72947 - return SLOB_UNITS(*m) * SLOB_UNIT;
72948 + slob_t *m = (slob_t *)(block - align);
72949 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
72950 } else
72951 - return sp->page.private;
72952 + return sp->size;
72953 }
72954 EXPORT_SYMBOL(ksize);
72955
72956 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72957 {
72958 struct kmem_cache *c;
72959
72960 +#ifdef CONFIG_PAX_USERCOPY
72961 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
72962 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
72963 +#else
72964 c = slob_alloc(sizeof(struct kmem_cache),
72965 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
72966 +#endif
72967
72968 if (c) {
72969 c->name = name;
72970 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
72971
72972 lockdep_trace_alloc(flags);
72973
72974 +#ifdef CONFIG_PAX_USERCOPY
72975 + b = __kmalloc_node_align(c->size, flags, node, c->align);
72976 +#else
72977 if (c->size < PAGE_SIZE) {
72978 b = slob_alloc(c->size, flags, c->align, node);
72979 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72980 SLOB_UNITS(c->size) * SLOB_UNIT,
72981 flags, node);
72982 } else {
72983 + struct slob_page *sp;
72984 +
72985 b = slob_new_pages(flags, get_order(c->size), node);
72986 + sp = slob_page(b);
72987 + sp->size = c->size;
72988 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72989 PAGE_SIZE << get_order(c->size),
72990 flags, node);
72991 }
72992 +#endif
72993
72994 if (c->ctor)
72995 c->ctor(b);
72996 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
72997
72998 static void __kmem_cache_free(void *b, int size)
72999 {
73000 - if (size < PAGE_SIZE)
73001 + struct slob_page *sp = slob_page(b);
73002 +
73003 + if (is_slob_page(sp))
73004 slob_free(b, size);
73005 - else
73006 + else {
73007 + clear_slob_page(sp);
73008 + free_slob_page(sp);
73009 + sp->size = 0;
73010 slob_free_pages(b, get_order(size));
73011 + }
73012 }
73013
73014 static void kmem_rcu_free(struct rcu_head *head)
73015 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73016
73017 void kmem_cache_free(struct kmem_cache *c, void *b)
73018 {
73019 + int size = c->size;
73020 +
73021 +#ifdef CONFIG_PAX_USERCOPY
73022 + if (size + c->align < PAGE_SIZE) {
73023 + size += c->align;
73024 + b -= c->align;
73025 + }
73026 +#endif
73027 +
73028 kmemleak_free_recursive(b, c->flags);
73029 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73030 struct slob_rcu *slob_rcu;
73031 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73032 - slob_rcu->size = c->size;
73033 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73034 + slob_rcu->size = size;
73035 call_rcu(&slob_rcu->head, kmem_rcu_free);
73036 } else {
73037 - __kmem_cache_free(b, c->size);
73038 + __kmem_cache_free(b, size);
73039 }
73040
73041 +#ifdef CONFIG_PAX_USERCOPY
73042 + trace_kfree(_RET_IP_, b);
73043 +#else
73044 trace_kmem_cache_free(_RET_IP_, b);
73045 +#endif
73046 +
73047 }
73048 EXPORT_SYMBOL(kmem_cache_free);
73049
73050 diff --git a/mm/slub.c b/mm/slub.c
73051 index 71de9b5..dd263c5 100644
73052 --- a/mm/slub.c
73053 +++ b/mm/slub.c
73054 @@ -209,7 +209,7 @@ struct track {
73055
73056 enum track_item { TRACK_ALLOC, TRACK_FREE };
73057
73058 -#ifdef CONFIG_SYSFS
73059 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73060 static int sysfs_slab_add(struct kmem_cache *);
73061 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73062 static void sysfs_slab_remove(struct kmem_cache *);
73063 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73064 if (!t->addr)
73065 return;
73066
73067 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73068 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73069 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73070 #ifdef CONFIG_STACKTRACE
73071 {
73072 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73073
73074 page = virt_to_head_page(x);
73075
73076 + BUG_ON(!PageSlab(page));
73077 +
73078 slab_free(s, page, x, _RET_IP_);
73079
73080 trace_kmem_cache_free(_RET_IP_, x);
73081 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
73082 * Merge control. If this is set then no merging of slab caches will occur.
73083 * (Could be removed. This was introduced to pacify the merge skeptics.)
73084 */
73085 -static int slub_nomerge;
73086 +static int slub_nomerge = 1;
73087
73088 /*
73089 * Calculate the order of allocation given an slab object size.
73090 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73091 else
73092 s->cpu_partial = 30;
73093
73094 - s->refcount = 1;
73095 + atomic_set(&s->refcount, 1);
73096 #ifdef CONFIG_NUMA
73097 s->remote_node_defrag_ratio = 1000;
73098 #endif
73099 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73100 void kmem_cache_destroy(struct kmem_cache *s)
73101 {
73102 down_write(&slub_lock);
73103 - s->refcount--;
73104 - if (!s->refcount) {
73105 + if (atomic_dec_and_test(&s->refcount)) {
73106 list_del(&s->list);
73107 up_write(&slub_lock);
73108 if (kmem_cache_close(s)) {
73109 @@ -3405,6 +3406,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73110 EXPORT_SYMBOL(__kmalloc_node);
73111 #endif
73112
73113 +void check_object_size(const void *ptr, unsigned long n, bool to)
73114 +{
73115 +
73116 +#ifdef CONFIG_PAX_USERCOPY
73117 + struct page *page;
73118 + struct kmem_cache *s = NULL;
73119 + unsigned long offset;
73120 + const char *type;
73121 +
73122 + if (!n)
73123 + return;
73124 +
73125 + type = "<null>";
73126 + if (ZERO_OR_NULL_PTR(ptr))
73127 + goto report;
73128 +
73129 + if (!virt_addr_valid(ptr))
73130 + return;
73131 +
73132 + page = virt_to_head_page(ptr);
73133 +
73134 + type = "<process stack>";
73135 + if (!PageSlab(page)) {
73136 + if (object_is_on_stack(ptr, n) == -1)
73137 + goto report;
73138 + return;
73139 + }
73140 +
73141 + s = page->slab;
73142 + type = s->name;
73143 + if (!(s->flags & SLAB_USERCOPY))
73144 + goto report;
73145 +
73146 + offset = (ptr - page_address(page)) % s->size;
73147 + if (offset <= s->objsize && n <= s->objsize - offset)
73148 + return;
73149 +
73150 +report:
73151 + pax_report_usercopy(ptr, n, to, type);
73152 +#endif
73153 +
73154 +}
73155 +EXPORT_SYMBOL(check_object_size);
73156 +
73157 size_t ksize(const void *object)
73158 {
73159 struct page *page;
73160 @@ -3679,7 +3724,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73161 int node;
73162
73163 list_add(&s->list, &slab_caches);
73164 - s->refcount = -1;
73165 + atomic_set(&s->refcount, -1);
73166
73167 for_each_node_state(node, N_NORMAL_MEMORY) {
73168 struct kmem_cache_node *n = get_node(s, node);
73169 @@ -3799,17 +3844,17 @@ void __init kmem_cache_init(void)
73170
73171 /* Caches that are not of the two-to-the-power-of size */
73172 if (KMALLOC_MIN_SIZE <= 32) {
73173 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73174 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73175 caches++;
73176 }
73177
73178 if (KMALLOC_MIN_SIZE <= 64) {
73179 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73180 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73181 caches++;
73182 }
73183
73184 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73185 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73186 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73187 caches++;
73188 }
73189
73190 @@ -3877,7 +3922,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73191 /*
73192 * We may have set a slab to be unmergeable during bootstrap.
73193 */
73194 - if (s->refcount < 0)
73195 + if (atomic_read(&s->refcount) < 0)
73196 return 1;
73197
73198 return 0;
73199 @@ -3936,7 +3981,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73200 down_write(&slub_lock);
73201 s = find_mergeable(size, align, flags, name, ctor);
73202 if (s) {
73203 - s->refcount++;
73204 + atomic_inc(&s->refcount);
73205 /*
73206 * Adjust the object sizes so that we clear
73207 * the complete object on kzalloc.
73208 @@ -3945,7 +3990,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73209 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73210
73211 if (sysfs_slab_alias(s, name)) {
73212 - s->refcount--;
73213 + atomic_dec(&s->refcount);
73214 goto err;
73215 }
73216 up_write(&slub_lock);
73217 @@ -4074,7 +4119,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73218 }
73219 #endif
73220
73221 -#ifdef CONFIG_SYSFS
73222 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73223 static int count_inuse(struct page *page)
73224 {
73225 return page->inuse;
73226 @@ -4461,12 +4506,12 @@ static void resiliency_test(void)
73227 validate_slab_cache(kmalloc_caches[9]);
73228 }
73229 #else
73230 -#ifdef CONFIG_SYSFS
73231 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73232 static void resiliency_test(void) {};
73233 #endif
73234 #endif
73235
73236 -#ifdef CONFIG_SYSFS
73237 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73238 enum slab_stat_type {
73239 SL_ALL, /* All slabs */
73240 SL_PARTIAL, /* Only partially allocated slabs */
73241 @@ -4709,7 +4754,7 @@ SLAB_ATTR_RO(ctor);
73242
73243 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73244 {
73245 - return sprintf(buf, "%d\n", s->refcount - 1);
73246 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73247 }
73248 SLAB_ATTR_RO(aliases);
73249
73250 @@ -5280,6 +5325,7 @@ static char *create_unique_id(struct kmem_cache *s)
73251 return name;
73252 }
73253
73254 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73255 static int sysfs_slab_add(struct kmem_cache *s)
73256 {
73257 int err;
73258 @@ -5342,6 +5388,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73259 kobject_del(&s->kobj);
73260 kobject_put(&s->kobj);
73261 }
73262 +#endif
73263
73264 /*
73265 * Need to buffer aliases during bootup until sysfs becomes
73266 @@ -5355,6 +5402,7 @@ struct saved_alias {
73267
73268 static struct saved_alias *alias_list;
73269
73270 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73271 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73272 {
73273 struct saved_alias *al;
73274 @@ -5377,6 +5425,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73275 alias_list = al;
73276 return 0;
73277 }
73278 +#endif
73279
73280 static int __init slab_sysfs_init(void)
73281 {
73282 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73283 index 1b7e22a..3fcd4f3 100644
73284 --- a/mm/sparse-vmemmap.c
73285 +++ b/mm/sparse-vmemmap.c
73286 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73287 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73288 if (!p)
73289 return NULL;
73290 - pud_populate(&init_mm, pud, p);
73291 + pud_populate_kernel(&init_mm, pud, p);
73292 }
73293 return pud;
73294 }
73295 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
73296 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73297 if (!p)
73298 return NULL;
73299 - pgd_populate(&init_mm, pgd, p);
73300 + pgd_populate_kernel(&init_mm, pgd, p);
73301 }
73302 return pgd;
73303 }
73304 diff --git a/mm/swap.c b/mm/swap.c
73305 index 5c13f13..f1cfc13 100644
73306 --- a/mm/swap.c
73307 +++ b/mm/swap.c
73308 @@ -30,6 +30,7 @@
73309 #include <linux/backing-dev.h>
73310 #include <linux/memcontrol.h>
73311 #include <linux/gfp.h>
73312 +#include <linux/hugetlb.h>
73313
73314 #include "internal.h"
73315
73316 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73317
73318 __page_cache_release(page);
73319 dtor = get_compound_page_dtor(page);
73320 + if (!PageHuge(page))
73321 + BUG_ON(dtor != free_compound_page);
73322 (*dtor)(page);
73323 }
73324
73325 diff --git a/mm/swapfile.c b/mm/swapfile.c
73326 index 38186d9..bfba6d3 100644
73327 --- a/mm/swapfile.c
73328 +++ b/mm/swapfile.c
73329 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73330
73331 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73332 /* Activity counter to indicate that a swapon or swapoff has occurred */
73333 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
73334 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73335
73336 static inline unsigned char swap_count(unsigned char ent)
73337 {
73338 @@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73339 }
73340 filp_close(swap_file, NULL);
73341 err = 0;
73342 - atomic_inc(&proc_poll_event);
73343 + atomic_inc_unchecked(&proc_poll_event);
73344 wake_up_interruptible(&proc_poll_wait);
73345
73346 out_dput:
73347 @@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73348
73349 poll_wait(file, &proc_poll_wait, wait);
73350
73351 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
73352 - seq->poll_event = atomic_read(&proc_poll_event);
73353 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73354 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73355 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73356 }
73357
73358 @@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73359 return ret;
73360
73361 seq = file->private_data;
73362 - seq->poll_event = atomic_read(&proc_poll_event);
73363 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73364 return 0;
73365 }
73366
73367 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73368 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73369
73370 mutex_unlock(&swapon_mutex);
73371 - atomic_inc(&proc_poll_event);
73372 + atomic_inc_unchecked(&proc_poll_event);
73373 wake_up_interruptible(&proc_poll_wait);
73374
73375 if (S_ISREG(inode->i_mode))
73376 diff --git a/mm/util.c b/mm/util.c
73377 index ae962b3..0bba886 100644
73378 --- a/mm/util.c
73379 +++ b/mm/util.c
73380 @@ -284,6 +284,12 @@ done:
73381 void arch_pick_mmap_layout(struct mm_struct *mm)
73382 {
73383 mm->mmap_base = TASK_UNMAPPED_BASE;
73384 +
73385 +#ifdef CONFIG_PAX_RANDMMAP
73386 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73387 + mm->mmap_base += mm->delta_mmap;
73388 +#endif
73389 +
73390 mm->get_unmapped_area = arch_get_unmapped_area;
73391 mm->unmap_area = arch_unmap_area;
73392 }
73393 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73394 index 1196c77..2e608e8 100644
73395 --- a/mm/vmalloc.c
73396 +++ b/mm/vmalloc.c
73397 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73398
73399 pte = pte_offset_kernel(pmd, addr);
73400 do {
73401 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73402 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73403 +
73404 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73405 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73406 + BUG_ON(!pte_exec(*pte));
73407 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73408 + continue;
73409 + }
73410 +#endif
73411 +
73412 + {
73413 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73414 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73415 + }
73416 } while (pte++, addr += PAGE_SIZE, addr != end);
73417 }
73418
73419 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73420 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73421 {
73422 pte_t *pte;
73423 + int ret = -ENOMEM;
73424
73425 /*
73426 * nr is a running index into the array which helps higher level
73427 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73428 pte = pte_alloc_kernel(pmd, addr);
73429 if (!pte)
73430 return -ENOMEM;
73431 +
73432 + pax_open_kernel();
73433 do {
73434 struct page *page = pages[*nr];
73435
73436 - if (WARN_ON(!pte_none(*pte)))
73437 - return -EBUSY;
73438 - if (WARN_ON(!page))
73439 - return -ENOMEM;
73440 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73441 + if (pgprot_val(prot) & _PAGE_NX)
73442 +#endif
73443 +
73444 + if (WARN_ON(!pte_none(*pte))) {
73445 + ret = -EBUSY;
73446 + goto out;
73447 + }
73448 + if (WARN_ON(!page)) {
73449 + ret = -ENOMEM;
73450 + goto out;
73451 + }
73452 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73453 (*nr)++;
73454 } while (pte++, addr += PAGE_SIZE, addr != end);
73455 - return 0;
73456 + ret = 0;
73457 +out:
73458 + pax_close_kernel();
73459 + return ret;
73460 }
73461
73462 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73463 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73464 pmd_t *pmd;
73465 unsigned long next;
73466
73467 - pmd = pmd_alloc(&init_mm, pud, addr);
73468 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73469 if (!pmd)
73470 return -ENOMEM;
73471 do {
73472 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
73473 pud_t *pud;
73474 unsigned long next;
73475
73476 - pud = pud_alloc(&init_mm, pgd, addr);
73477 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73478 if (!pud)
73479 return -ENOMEM;
73480 do {
73481 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73482 * and fall back on vmalloc() if that fails. Others
73483 * just put it in the vmalloc space.
73484 */
73485 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73486 +#ifdef CONFIG_MODULES
73487 +#ifdef MODULES_VADDR
73488 unsigned long addr = (unsigned long)x;
73489 if (addr >= MODULES_VADDR && addr < MODULES_END)
73490 return 1;
73491 #endif
73492 +
73493 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73494 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73495 + return 1;
73496 +#endif
73497 +
73498 +#endif
73499 +
73500 return is_vmalloc_addr(x);
73501 }
73502
73503 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73504
73505 if (!pgd_none(*pgd)) {
73506 pud_t *pud = pud_offset(pgd, addr);
73507 +#ifdef CONFIG_X86
73508 + if (!pud_large(*pud))
73509 +#endif
73510 if (!pud_none(*pud)) {
73511 pmd_t *pmd = pmd_offset(pud, addr);
73512 +#ifdef CONFIG_X86
73513 + if (!pmd_large(*pmd))
73514 +#endif
73515 if (!pmd_none(*pmd)) {
73516 pte_t *ptep, pte;
73517
73518 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
73519 static struct vmap_area *alloc_vmap_area(unsigned long size,
73520 unsigned long align,
73521 unsigned long vstart, unsigned long vend,
73522 + int node, gfp_t gfp_mask) __size_overflow(1);
73523 +static struct vmap_area *alloc_vmap_area(unsigned long size,
73524 + unsigned long align,
73525 + unsigned long vstart, unsigned long vend,
73526 int node, gfp_t gfp_mask)
73527 {
73528 struct vmap_area *va;
73529 @@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73530 struct vm_struct *area;
73531
73532 BUG_ON(in_interrupt());
73533 +
73534 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73535 + if (flags & VM_KERNEXEC) {
73536 + if (start != VMALLOC_START || end != VMALLOC_END)
73537 + return NULL;
73538 + start = (unsigned long)MODULES_EXEC_VADDR;
73539 + end = (unsigned long)MODULES_EXEC_END;
73540 + }
73541 +#endif
73542 +
73543 if (flags & VM_IOREMAP) {
73544 int bit = fls(size);
73545
73546 @@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
73547 if (count > totalram_pages)
73548 return NULL;
73549
73550 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73551 + if (!(pgprot_val(prot) & _PAGE_NX))
73552 + flags |= VM_KERNEXEC;
73553 +#endif
73554 +
73555 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73556 __builtin_return_address(0));
73557 if (!area)
73558 @@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73559 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73560 goto fail;
73561
73562 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73563 + if (!(pgprot_val(prot) & _PAGE_NX))
73564 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73565 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73566 + else
73567 +#endif
73568 +
73569 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73570 start, end, node, gfp_mask, caller);
73571 if (!area)
73572 @@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
73573 * For tight control over page level allocator and protection flags
73574 * use __vmalloc() instead.
73575 */
73576 -
73577 void *vmalloc_exec(unsigned long size)
73578 {
73579 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73580 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73581 -1, __builtin_return_address(0));
73582 }
73583
73584 @@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73585 unsigned long uaddr = vma->vm_start;
73586 unsigned long usize = vma->vm_end - vma->vm_start;
73587
73588 + BUG_ON(vma->vm_mirror);
73589 +
73590 if ((PAGE_SIZE-1) & (unsigned long)addr)
73591 return -EINVAL;
73592
73593 @@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
73594 return NULL;
73595 }
73596
73597 - vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
73598 - vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
73599 + vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
73600 + vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
73601 if (!vas || !vms)
73602 goto err_free2;
73603
73604 diff --git a/mm/vmstat.c b/mm/vmstat.c
73605 index 7db1b9b..e9f6b07 100644
73606 --- a/mm/vmstat.c
73607 +++ b/mm/vmstat.c
73608 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73609 *
73610 * vm_stat contains the global counters
73611 */
73612 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73613 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73614 EXPORT_SYMBOL(vm_stat);
73615
73616 #ifdef CONFIG_SMP
73617 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73618 v = p->vm_stat_diff[i];
73619 p->vm_stat_diff[i] = 0;
73620 local_irq_restore(flags);
73621 - atomic_long_add(v, &zone->vm_stat[i]);
73622 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73623 global_diff[i] += v;
73624 #ifdef CONFIG_NUMA
73625 /* 3 seconds idle till flush */
73626 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73627
73628 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73629 if (global_diff[i])
73630 - atomic_long_add(global_diff[i], &vm_stat[i]);
73631 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73632 }
73633
73634 #endif
73635 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73636 start_cpu_timer(cpu);
73637 #endif
73638 #ifdef CONFIG_PROC_FS
73639 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73640 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73641 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73642 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73643 + {
73644 + mode_t gr_mode = S_IRUGO;
73645 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73646 + gr_mode = S_IRUSR;
73647 +#endif
73648 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73649 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73650 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73651 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73652 +#else
73653 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73654 +#endif
73655 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73656 + }
73657 #endif
73658 return 0;
73659 }
73660 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73661 index efea35b..9c8dd0b 100644
73662 --- a/net/8021q/vlan.c
73663 +++ b/net/8021q/vlan.c
73664 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73665 err = -EPERM;
73666 if (!capable(CAP_NET_ADMIN))
73667 break;
73668 - if ((args.u.name_type >= 0) &&
73669 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73670 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73671 struct vlan_net *vn;
73672
73673 vn = net_generic(net, vlan_net_id);
73674 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73675 index fccae26..e7ece2f 100644
73676 --- a/net/9p/trans_fd.c
73677 +++ b/net/9p/trans_fd.c
73678 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73679 oldfs = get_fs();
73680 set_fs(get_ds());
73681 /* The cast to a user pointer is valid due to the set_fs() */
73682 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73683 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73684 set_fs(oldfs);
73685
73686 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73687 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73688 index 876fbe8..8bbea9f 100644
73689 --- a/net/atm/atm_misc.c
73690 +++ b/net/atm/atm_misc.c
73691 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73692 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73693 return 1;
73694 atm_return(vcc, truesize);
73695 - atomic_inc(&vcc->stats->rx_drop);
73696 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73697 return 0;
73698 }
73699 EXPORT_SYMBOL(atm_charge);
73700 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73701 }
73702 }
73703 atm_return(vcc, guess);
73704 - atomic_inc(&vcc->stats->rx_drop);
73705 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73706 return NULL;
73707 }
73708 EXPORT_SYMBOL(atm_alloc_charge);
73709 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73710
73711 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73712 {
73713 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73714 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73715 __SONET_ITEMS
73716 #undef __HANDLE_ITEM
73717 }
73718 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73719
73720 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73721 {
73722 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73723 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73724 __SONET_ITEMS
73725 #undef __HANDLE_ITEM
73726 }
73727 diff --git a/net/atm/lec.h b/net/atm/lec.h
73728 index dfc0719..47c5322 100644
73729 --- a/net/atm/lec.h
73730 +++ b/net/atm/lec.h
73731 @@ -48,7 +48,7 @@ struct lane2_ops {
73732 const u8 *tlvs, u32 sizeoftlvs);
73733 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73734 const u8 *tlvs, u32 sizeoftlvs);
73735 -};
73736 +} __no_const;
73737
73738 /*
73739 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73740 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73741 index 0919a88..a23d54e 100644
73742 --- a/net/atm/mpc.h
73743 +++ b/net/atm/mpc.h
73744 @@ -33,7 +33,7 @@ struct mpoa_client {
73745 struct mpc_parameters parameters; /* parameters for this client */
73746
73747 const struct net_device_ops *old_ops;
73748 - struct net_device_ops new_ops;
73749 + net_device_ops_no_const new_ops;
73750 };
73751
73752
73753 diff --git a/net/atm/proc.c b/net/atm/proc.c
73754 index 0d020de..011c7bb 100644
73755 --- a/net/atm/proc.c
73756 +++ b/net/atm/proc.c
73757 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73758 const struct k_atm_aal_stats *stats)
73759 {
73760 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73761 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73762 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73763 - atomic_read(&stats->rx_drop));
73764 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73765 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73766 + atomic_read_unchecked(&stats->rx_drop));
73767 }
73768
73769 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73770 diff --git a/net/atm/resources.c b/net/atm/resources.c
73771 index 23f45ce..c748f1a 100644
73772 --- a/net/atm/resources.c
73773 +++ b/net/atm/resources.c
73774 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73775 static void copy_aal_stats(struct k_atm_aal_stats *from,
73776 struct atm_aal_stats *to)
73777 {
73778 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73779 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73780 __AAL_STAT_ITEMS
73781 #undef __HANDLE_ITEM
73782 }
73783 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73784 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73785 struct atm_aal_stats *to)
73786 {
73787 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73788 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73789 __AAL_STAT_ITEMS
73790 #undef __HANDLE_ITEM
73791 }
73792 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73793 index a6d5d63..1cc6c2b 100644
73794 --- a/net/batman-adv/bat_iv_ogm.c
73795 +++ b/net/batman-adv/bat_iv_ogm.c
73796 @@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73797
73798 /* change sequence number to network order */
73799 batman_ogm_packet->seqno =
73800 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
73801 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73802
73803 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73804 batman_ogm_packet->tt_crc = htons((uint16_t)
73805 @@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73806 else
73807 batman_ogm_packet->gw_flags = NO_FLAGS;
73808
73809 - atomic_inc(&hard_iface->seqno);
73810 + atomic_inc_unchecked(&hard_iface->seqno);
73811
73812 slide_own_bcast_window(hard_iface);
73813 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73814 @@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
73815 return;
73816
73817 /* could be changed by schedule_own_packet() */
73818 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
73819 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73820
73821 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73822
73823 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73824 index 3778977..f6a9450 100644
73825 --- a/net/batman-adv/hard-interface.c
73826 +++ b/net/batman-adv/hard-interface.c
73827 @@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73828 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73829 dev_add_pack(&hard_iface->batman_adv_ptype);
73830
73831 - atomic_set(&hard_iface->seqno, 1);
73832 - atomic_set(&hard_iface->frag_seqno, 1);
73833 + atomic_set_unchecked(&hard_iface->seqno, 1);
73834 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73835 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73836 hard_iface->net_dev->name);
73837
73838 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73839 index a5590f4..8d31969 100644
73840 --- a/net/batman-adv/soft-interface.c
73841 +++ b/net/batman-adv/soft-interface.c
73842 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73843
73844 /* set broadcast sequence number */
73845 bcast_packet->seqno =
73846 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73847 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73848
73849 add_bcast_packet_to_list(bat_priv, skb, 1);
73850
73851 @@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
73852 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73853
73854 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73855 - atomic_set(&bat_priv->bcast_seqno, 1);
73856 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73857 atomic_set(&bat_priv->ttvn, 0);
73858 atomic_set(&bat_priv->tt_local_changes, 0);
73859 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73860 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73861 index 302efb5..1590365 100644
73862 --- a/net/batman-adv/types.h
73863 +++ b/net/batman-adv/types.h
73864 @@ -38,8 +38,8 @@ struct hard_iface {
73865 int16_t if_num;
73866 char if_status;
73867 struct net_device *net_dev;
73868 - atomic_t seqno;
73869 - atomic_t frag_seqno;
73870 + atomic_unchecked_t seqno;
73871 + atomic_unchecked_t frag_seqno;
73872 unsigned char *packet_buff;
73873 int packet_len;
73874 struct kobject *hardif_obj;
73875 @@ -155,7 +155,7 @@ struct bat_priv {
73876 atomic_t orig_interval; /* uint */
73877 atomic_t hop_penalty; /* uint */
73878 atomic_t log_level; /* uint */
73879 - atomic_t bcast_seqno;
73880 + atomic_unchecked_t bcast_seqno;
73881 atomic_t bcast_queue_left;
73882 atomic_t batman_queue_left;
73883 atomic_t ttvn; /* translation table version number */
73884 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73885 index 676f6a6..3b4e668 100644
73886 --- a/net/batman-adv/unicast.c
73887 +++ b/net/batman-adv/unicast.c
73888 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73889 frag1->flags = UNI_FRAG_HEAD | large_tail;
73890 frag2->flags = large_tail;
73891
73892 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73893 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73894 frag1->seqno = htons(seqno - 1);
73895 frag2->seqno = htons(seqno);
73896
73897 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73898 index 5238b6b..c9798ce 100644
73899 --- a/net/bluetooth/hci_conn.c
73900 +++ b/net/bluetooth/hci_conn.c
73901 @@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73902 memset(&cp, 0, sizeof(cp));
73903
73904 cp.handle = cpu_to_le16(conn->handle);
73905 - memcpy(cp.ltk, ltk, sizeof(ltk));
73906 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73907
73908 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73909 }
73910 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73911 index 6f9c25b..d19fd66 100644
73912 --- a/net/bluetooth/l2cap_core.c
73913 +++ b/net/bluetooth/l2cap_core.c
73914 @@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73915 break;
73916
73917 case L2CAP_CONF_RFC:
73918 - if (olen == sizeof(rfc))
73919 - memcpy(&rfc, (void *)val, olen);
73920 + if (olen != sizeof(rfc))
73921 + break;
73922 +
73923 + memcpy(&rfc, (void *)val, olen);
73924
73925 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73926 rfc.mode != chan->mode)
73927 @@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73928
73929 switch (type) {
73930 case L2CAP_CONF_RFC:
73931 - if (olen == sizeof(rfc))
73932 - memcpy(&rfc, (void *)val, olen);
73933 + if (olen != sizeof(rfc))
73934 + break;
73935 +
73936 + memcpy(&rfc, (void *)val, olen);
73937 goto done;
73938 }
73939 }
73940 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73941 index 5fe2ff3..10968b5 100644
73942 --- a/net/bridge/netfilter/ebtables.c
73943 +++ b/net/bridge/netfilter/ebtables.c
73944 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
73945 tmp.valid_hooks = t->table->valid_hooks;
73946 }
73947 mutex_unlock(&ebt_mutex);
73948 - if (copy_to_user(user, &tmp, *len) != 0){
73949 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
73950 BUGPRINT("c2u Didn't work\n");
73951 ret = -EFAULT;
73952 break;
73953 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
73954 index 5cf5222..6f704ad 100644
73955 --- a/net/caif/cfctrl.c
73956 +++ b/net/caif/cfctrl.c
73957 @@ -9,6 +9,7 @@
73958 #include <linux/stddef.h>
73959 #include <linux/spinlock.h>
73960 #include <linux/slab.h>
73961 +#include <linux/sched.h>
73962 #include <net/caif/caif_layer.h>
73963 #include <net/caif/cfpkt.h>
73964 #include <net/caif/cfctrl.h>
73965 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
73966 memset(&dev_info, 0, sizeof(dev_info));
73967 dev_info.id = 0xff;
73968 cfsrvl_init(&this->serv, 0, &dev_info, false);
73969 - atomic_set(&this->req_seq_no, 1);
73970 - atomic_set(&this->rsp_seq_no, 1);
73971 + atomic_set_unchecked(&this->req_seq_no, 1);
73972 + atomic_set_unchecked(&this->rsp_seq_no, 1);
73973 this->serv.layer.receive = cfctrl_recv;
73974 sprintf(this->serv.layer.name, "ctrl");
73975 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
73976 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
73977 struct cfctrl_request_info *req)
73978 {
73979 spin_lock_bh(&ctrl->info_list_lock);
73980 - atomic_inc(&ctrl->req_seq_no);
73981 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
73982 + atomic_inc_unchecked(&ctrl->req_seq_no);
73983 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
73984 list_add_tail(&req->list, &ctrl->list);
73985 spin_unlock_bh(&ctrl->info_list_lock);
73986 }
73987 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
73988 if (p != first)
73989 pr_warn("Requests are not received in order\n");
73990
73991 - atomic_set(&ctrl->rsp_seq_no,
73992 + atomic_set_unchecked(&ctrl->rsp_seq_no,
73993 p->sequence_no);
73994 list_del(&p->list);
73995 goto out;
73996 diff --git a/net/can/gw.c b/net/can/gw.c
73997 index 3d79b12..8de85fa 100644
73998 --- a/net/can/gw.c
73999 +++ b/net/can/gw.c
74000 @@ -96,7 +96,7 @@ struct cf_mod {
74001 struct {
74002 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74003 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74004 - } csumfunc;
74005 + } __no_const csumfunc;
74006 };
74007
74008
74009 diff --git a/net/compat.c b/net/compat.c
74010 index e055708..3f80795 100644
74011 --- a/net/compat.c
74012 +++ b/net/compat.c
74013 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74014 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74015 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74016 return -EFAULT;
74017 - kmsg->msg_name = compat_ptr(tmp1);
74018 - kmsg->msg_iov = compat_ptr(tmp2);
74019 - kmsg->msg_control = compat_ptr(tmp3);
74020 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74021 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74022 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74023 return 0;
74024 }
74025
74026 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74027
74028 if (kern_msg->msg_namelen) {
74029 if (mode == VERIFY_READ) {
74030 - int err = move_addr_to_kernel(kern_msg->msg_name,
74031 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74032 kern_msg->msg_namelen,
74033 kern_address);
74034 if (err < 0)
74035 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74036 kern_msg->msg_name = NULL;
74037
74038 tot_len = iov_from_user_compat_to_kern(kern_iov,
74039 - (struct compat_iovec __user *)kern_msg->msg_iov,
74040 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74041 kern_msg->msg_iovlen);
74042 if (tot_len >= 0)
74043 kern_msg->msg_iov = kern_iov;
74044 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74045
74046 #define CMSG_COMPAT_FIRSTHDR(msg) \
74047 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74048 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74049 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74050 (struct compat_cmsghdr __user *)NULL)
74051
74052 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74053 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74054 (ucmlen) <= (unsigned long) \
74055 ((mhdr)->msg_controllen - \
74056 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74057 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74058
74059 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74060 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74061 {
74062 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74063 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74064 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74065 msg->msg_controllen)
74066 return NULL;
74067 return (struct compat_cmsghdr __user *)ptr;
74068 @@ -219,7 +219,7 @@ Efault:
74069
74070 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74071 {
74072 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74073 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74074 struct compat_cmsghdr cmhdr;
74075 int cmlen;
74076
74077 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74078
74079 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74080 {
74081 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74082 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74083 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74084 int fdnum = scm->fp->count;
74085 struct file **fp = scm->fp->fp;
74086 @@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74087 return -EFAULT;
74088 old_fs = get_fs();
74089 set_fs(KERNEL_DS);
74090 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74091 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74092 set_fs(old_fs);
74093
74094 return err;
74095 @@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74096 len = sizeof(ktime);
74097 old_fs = get_fs();
74098 set_fs(KERNEL_DS);
74099 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74100 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74101 set_fs(old_fs);
74102
74103 if (!err) {
74104 @@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74105 case MCAST_JOIN_GROUP:
74106 case MCAST_LEAVE_GROUP:
74107 {
74108 - struct compat_group_req __user *gr32 = (void *)optval;
74109 + struct compat_group_req __user *gr32 = (void __user *)optval;
74110 struct group_req __user *kgr =
74111 compat_alloc_user_space(sizeof(struct group_req));
74112 u32 interface;
74113 @@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74114 case MCAST_BLOCK_SOURCE:
74115 case MCAST_UNBLOCK_SOURCE:
74116 {
74117 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74118 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74119 struct group_source_req __user *kgsr = compat_alloc_user_space(
74120 sizeof(struct group_source_req));
74121 u32 interface;
74122 @@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74123 }
74124 case MCAST_MSFILTER:
74125 {
74126 - struct compat_group_filter __user *gf32 = (void *)optval;
74127 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74128 struct group_filter __user *kgf;
74129 u32 interface, fmode, numsrc;
74130
74131 @@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74132 char __user *optval, int __user *optlen,
74133 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74134 {
74135 - struct compat_group_filter __user *gf32 = (void *)optval;
74136 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74137 struct group_filter __user *kgf;
74138 int __user *koptlen;
74139 u32 interface, fmode, numsrc;
74140 diff --git a/net/core/datagram.c b/net/core/datagram.c
74141 index e4fbfd6..6a6ac94 100644
74142 --- a/net/core/datagram.c
74143 +++ b/net/core/datagram.c
74144 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74145 }
74146
74147 kfree_skb(skb);
74148 - atomic_inc(&sk->sk_drops);
74149 + atomic_inc_unchecked(&sk->sk_drops);
74150 sk_mem_reclaim_partial(sk);
74151
74152 return err;
74153 diff --git a/net/core/dev.c b/net/core/dev.c
74154 index 533c586..f78a55f 100644
74155 --- a/net/core/dev.c
74156 +++ b/net/core/dev.c
74157 @@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
74158 if (no_module && capable(CAP_NET_ADMIN))
74159 no_module = request_module("netdev-%s", name);
74160 if (no_module && capable(CAP_SYS_MODULE)) {
74161 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74162 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74163 +#else
74164 if (!request_module("%s", name))
74165 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
74166 name);
74167 +#endif
74168 }
74169 }
74170 EXPORT_SYMBOL(dev_load);
74171 @@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74172 {
74173 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74174 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74175 - atomic_long_inc(&dev->rx_dropped);
74176 + atomic_long_inc_unchecked(&dev->rx_dropped);
74177 kfree_skb(skb);
74178 return NET_RX_DROP;
74179 }
74180 @@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74181 nf_reset(skb);
74182
74183 if (unlikely(!is_skb_forwardable(dev, skb))) {
74184 - atomic_long_inc(&dev->rx_dropped);
74185 + atomic_long_inc_unchecked(&dev->rx_dropped);
74186 kfree_skb(skb);
74187 return NET_RX_DROP;
74188 }
74189 @@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74190
74191 struct dev_gso_cb {
74192 void (*destructor)(struct sk_buff *skb);
74193 -};
74194 +} __no_const;
74195
74196 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74197
74198 @@ -2877,7 +2881,7 @@ enqueue:
74199
74200 local_irq_restore(flags);
74201
74202 - atomic_long_inc(&skb->dev->rx_dropped);
74203 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74204 kfree_skb(skb);
74205 return NET_RX_DROP;
74206 }
74207 @@ -2949,7 +2953,7 @@ int netif_rx_ni(struct sk_buff *skb)
74208 }
74209 EXPORT_SYMBOL(netif_rx_ni);
74210
74211 -static void net_tx_action(struct softirq_action *h)
74212 +static void net_tx_action(void)
74213 {
74214 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74215
74216 @@ -3237,7 +3241,7 @@ ncls:
74217 if (pt_prev) {
74218 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74219 } else {
74220 - atomic_long_inc(&skb->dev->rx_dropped);
74221 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74222 kfree_skb(skb);
74223 /* Jamal, now you will not able to escape explaining
74224 * me how you were going to use this. :-)
74225 @@ -3797,7 +3801,7 @@ void netif_napi_del(struct napi_struct *napi)
74226 }
74227 EXPORT_SYMBOL(netif_napi_del);
74228
74229 -static void net_rx_action(struct softirq_action *h)
74230 +static void net_rx_action(void)
74231 {
74232 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74233 unsigned long time_limit = jiffies + 2;
74234 @@ -4267,8 +4271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
74235 else
74236 seq_printf(seq, "%04x", ntohs(pt->type));
74237
74238 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74239 + seq_printf(seq, " %-8s %p\n",
74240 + pt->dev ? pt->dev->name : "", NULL);
74241 +#else
74242 seq_printf(seq, " %-8s %pF\n",
74243 pt->dev ? pt->dev->name : "", pt->func);
74244 +#endif
74245 }
74246
74247 return 0;
74248 @@ -5818,7 +5827,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74249 } else {
74250 netdev_stats_to_stats64(storage, &dev->stats);
74251 }
74252 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74253 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74254 return storage;
74255 }
74256 EXPORT_SYMBOL(dev_get_stats);
74257 diff --git a/net/core/flow.c b/net/core/flow.c
74258 index e318c7e..168b1d0 100644
74259 --- a/net/core/flow.c
74260 +++ b/net/core/flow.c
74261 @@ -61,7 +61,7 @@ struct flow_cache {
74262 struct timer_list rnd_timer;
74263 };
74264
74265 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
74266 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74267 EXPORT_SYMBOL(flow_cache_genid);
74268 static struct flow_cache flow_cache_global;
74269 static struct kmem_cache *flow_cachep __read_mostly;
74270 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74271
74272 static int flow_entry_valid(struct flow_cache_entry *fle)
74273 {
74274 - if (atomic_read(&flow_cache_genid) != fle->genid)
74275 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74276 return 0;
74277 if (fle->object && !fle->object->ops->check(fle->object))
74278 return 0;
74279 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74280 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74281 fcp->hash_count++;
74282 }
74283 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74284 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74285 flo = fle->object;
74286 if (!flo)
74287 goto ret_object;
74288 @@ -280,7 +280,7 @@ nocache:
74289 }
74290 flo = resolver(net, key, family, dir, flo, ctx);
74291 if (fle) {
74292 - fle->genid = atomic_read(&flow_cache_genid);
74293 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
74294 if (!IS_ERR(flo))
74295 fle->object = flo;
74296 else
74297 diff --git a/net/core/iovec.c b/net/core/iovec.c
74298 index 7e7aeb0..2a998cb 100644
74299 --- a/net/core/iovec.c
74300 +++ b/net/core/iovec.c
74301 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74302 if (m->msg_namelen) {
74303 if (mode == VERIFY_READ) {
74304 void __user *namep;
74305 - namep = (void __user __force *) m->msg_name;
74306 + namep = (void __force_user *) m->msg_name;
74307 err = move_addr_to_kernel(namep, m->msg_namelen,
74308 address);
74309 if (err < 0)
74310 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74311 }
74312
74313 size = m->msg_iovlen * sizeof(struct iovec);
74314 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74315 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74316 return -EFAULT;
74317
74318 m->msg_iov = iov;
74319 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74320 index 90430b7..0032ec0 100644
74321 --- a/net/core/rtnetlink.c
74322 +++ b/net/core/rtnetlink.c
74323 @@ -56,7 +56,7 @@ struct rtnl_link {
74324 rtnl_doit_func doit;
74325 rtnl_dumpit_func dumpit;
74326 rtnl_calcit_func calcit;
74327 -};
74328 +} __no_const;
74329
74330 static DEFINE_MUTEX(rtnl_mutex);
74331
74332 diff --git a/net/core/scm.c b/net/core/scm.c
74333 index 611c5ef..88f6d6d 100644
74334 --- a/net/core/scm.c
74335 +++ b/net/core/scm.c
74336 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
74337 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74338 {
74339 struct cmsghdr __user *cm
74340 - = (__force struct cmsghdr __user *)msg->msg_control;
74341 + = (struct cmsghdr __force_user *)msg->msg_control;
74342 struct cmsghdr cmhdr;
74343 int cmlen = CMSG_LEN(len);
74344 int err;
74345 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74346 err = -EFAULT;
74347 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74348 goto out;
74349 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74350 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74351 goto out;
74352 cmlen = CMSG_SPACE(len);
74353 if (msg->msg_controllen < cmlen)
74354 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
74355 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74356 {
74357 struct cmsghdr __user *cm
74358 - = (__force struct cmsghdr __user*)msg->msg_control;
74359 + = (struct cmsghdr __force_user *)msg->msg_control;
74360
74361 int fdmax = 0;
74362 int fdnum = scm->fp->count;
74363 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74364 if (fdnum < fdmax)
74365 fdmax = fdnum;
74366
74367 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74368 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74369 i++, cmfptr++)
74370 {
74371 int new_fd;
74372 diff --git a/net/core/sock.c b/net/core/sock.c
74373 index 0f8402e..f0b6338 100644
74374 --- a/net/core/sock.c
74375 +++ b/net/core/sock.c
74376 @@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74377 struct sk_buff_head *list = &sk->sk_receive_queue;
74378
74379 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74380 - atomic_inc(&sk->sk_drops);
74381 + atomic_inc_unchecked(&sk->sk_drops);
74382 trace_sock_rcvqueue_full(sk, skb);
74383 return -ENOMEM;
74384 }
74385 @@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74386 return err;
74387
74388 if (!sk_rmem_schedule(sk, skb->truesize)) {
74389 - atomic_inc(&sk->sk_drops);
74390 + atomic_inc_unchecked(&sk->sk_drops);
74391 return -ENOBUFS;
74392 }
74393
74394 @@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74395 skb_dst_force(skb);
74396
74397 spin_lock_irqsave(&list->lock, flags);
74398 - skb->dropcount = atomic_read(&sk->sk_drops);
74399 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74400 __skb_queue_tail(list, skb);
74401 spin_unlock_irqrestore(&list->lock, flags);
74402
74403 @@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74404 skb->dev = NULL;
74405
74406 if (sk_rcvqueues_full(sk, skb)) {
74407 - atomic_inc(&sk->sk_drops);
74408 + atomic_inc_unchecked(&sk->sk_drops);
74409 goto discard_and_relse;
74410 }
74411 if (nested)
74412 @@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74413 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74414 } else if (sk_add_backlog(sk, skb)) {
74415 bh_unlock_sock(sk);
74416 - atomic_inc(&sk->sk_drops);
74417 + atomic_inc_unchecked(&sk->sk_drops);
74418 goto discard_and_relse;
74419 }
74420
74421 @@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74422 if (len > sizeof(peercred))
74423 len = sizeof(peercred);
74424 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74425 - if (copy_to_user(optval, &peercred, len))
74426 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74427 return -EFAULT;
74428 goto lenout;
74429 }
74430 @@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74431 return -ENOTCONN;
74432 if (lv < len)
74433 return -EINVAL;
74434 - if (copy_to_user(optval, address, len))
74435 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74436 return -EFAULT;
74437 goto lenout;
74438 }
74439 @@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74440
74441 if (len > lv)
74442 len = lv;
74443 - if (copy_to_user(optval, &v, len))
74444 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74445 return -EFAULT;
74446 lenout:
74447 if (put_user(len, optlen))
74448 @@ -2131,7 +2131,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74449 */
74450 smp_wmb();
74451 atomic_set(&sk->sk_refcnt, 1);
74452 - atomic_set(&sk->sk_drops, 0);
74453 + atomic_set_unchecked(&sk->sk_drops, 0);
74454 }
74455 EXPORT_SYMBOL(sock_init_data);
74456
74457 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74458 index b9868e1..849f809 100644
74459 --- a/net/core/sock_diag.c
74460 +++ b/net/core/sock_diag.c
74461 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74462
74463 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74464 {
74465 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74466 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74467 cookie[1] != INET_DIAG_NOCOOKIE) &&
74468 ((u32)(unsigned long)sk != cookie[0] ||
74469 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74470 return -ESTALE;
74471 else
74472 +#endif
74473 return 0;
74474 }
74475 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74476
74477 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74478 {
74479 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74480 + cookie[0] = 0;
74481 + cookie[1] = 0;
74482 +#else
74483 cookie[0] = (u32)(unsigned long)sk;
74484 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74485 +#endif
74486 }
74487 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74488
74489 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74490 index 02e75d1..9a57a7c 100644
74491 --- a/net/decnet/sysctl_net_decnet.c
74492 +++ b/net/decnet/sysctl_net_decnet.c
74493 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74494
74495 if (len > *lenp) len = *lenp;
74496
74497 - if (copy_to_user(buffer, addr, len))
74498 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74499 return -EFAULT;
74500
74501 *lenp = len;
74502 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74503
74504 if (len > *lenp) len = *lenp;
74505
74506 - if (copy_to_user(buffer, devname, len))
74507 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74508 return -EFAULT;
74509
74510 *lenp = len;
74511 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74512 index 39a2d29..f39c0fe 100644
74513 --- a/net/econet/Kconfig
74514 +++ b/net/econet/Kconfig
74515 @@ -4,7 +4,7 @@
74516
74517 config ECONET
74518 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74519 - depends on EXPERIMENTAL && INET
74520 + depends on EXPERIMENTAL && INET && BROKEN
74521 ---help---
74522 Econet is a fairly old and slow networking protocol mainly used by
74523 Acorn computers to access file and print servers. It uses native
74524 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74525 index cbe3a68..a879b75 100644
74526 --- a/net/ipv4/fib_frontend.c
74527 +++ b/net/ipv4/fib_frontend.c
74528 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74529 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74530 fib_sync_up(dev);
74531 #endif
74532 - atomic_inc(&net->ipv4.dev_addr_genid);
74533 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74534 rt_cache_flush(dev_net(dev), -1);
74535 break;
74536 case NETDEV_DOWN:
74537 fib_del_ifaddr(ifa, NULL);
74538 - atomic_inc(&net->ipv4.dev_addr_genid);
74539 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74540 if (ifa->ifa_dev->ifa_list == NULL) {
74541 /* Last address was deleted from this interface.
74542 * Disable IP.
74543 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74544 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74545 fib_sync_up(dev);
74546 #endif
74547 - atomic_inc(&net->ipv4.dev_addr_genid);
74548 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74549 rt_cache_flush(dev_net(dev), -1);
74550 break;
74551 case NETDEV_DOWN:
74552 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74553 index 8861f91..ab1e3c1 100644
74554 --- a/net/ipv4/fib_semantics.c
74555 +++ b/net/ipv4/fib_semantics.c
74556 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74557 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74558 nh->nh_gw,
74559 nh->nh_parent->fib_scope);
74560 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74561 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74562
74563 return nh->nh_saddr;
74564 }
74565 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74566 index 984ec65..97ac518 100644
74567 --- a/net/ipv4/inet_hashtables.c
74568 +++ b/net/ipv4/inet_hashtables.c
74569 @@ -18,12 +18,15 @@
74570 #include <linux/sched.h>
74571 #include <linux/slab.h>
74572 #include <linux/wait.h>
74573 +#include <linux/security.h>
74574
74575 #include <net/inet_connection_sock.h>
74576 #include <net/inet_hashtables.h>
74577 #include <net/secure_seq.h>
74578 #include <net/ip.h>
74579
74580 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74581 +
74582 /*
74583 * Allocate and initialize a new local port bind bucket.
74584 * The bindhash mutex for snum's hash chain must be held here.
74585 @@ -530,6 +533,8 @@ ok:
74586 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74587 spin_unlock(&head->lock);
74588
74589 + gr_update_task_in_ip_table(current, inet_sk(sk));
74590 +
74591 if (tw) {
74592 inet_twsk_deschedule(tw, death_row);
74593 while (twrefcnt) {
74594 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74595 index dfba343..c827d50 100644
74596 --- a/net/ipv4/inetpeer.c
74597 +++ b/net/ipv4/inetpeer.c
74598 @@ -487,8 +487,8 @@ relookup:
74599 if (p) {
74600 p->daddr = *daddr;
74601 atomic_set(&p->refcnt, 1);
74602 - atomic_set(&p->rid, 0);
74603 - atomic_set(&p->ip_id_count,
74604 + atomic_set_unchecked(&p->rid, 0);
74605 + atomic_set_unchecked(&p->ip_id_count,
74606 (daddr->family == AF_INET) ?
74607 secure_ip_id(daddr->addr.a4) :
74608 secure_ipv6_id(daddr->addr.a6));
74609 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74610 index 3727e23..517f5df 100644
74611 --- a/net/ipv4/ip_fragment.c
74612 +++ b/net/ipv4/ip_fragment.c
74613 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74614 return 0;
74615
74616 start = qp->rid;
74617 - end = atomic_inc_return(&peer->rid);
74618 + end = atomic_inc_return_unchecked(&peer->rid);
74619 qp->rid = end;
74620
74621 rc = qp->q.fragments && (end - start) > max;
74622 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74623 index 2fd0fba..83fac99 100644
74624 --- a/net/ipv4/ip_sockglue.c
74625 +++ b/net/ipv4/ip_sockglue.c
74626 @@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74627 len = min_t(unsigned int, len, opt->optlen);
74628 if (put_user(len, optlen))
74629 return -EFAULT;
74630 - if (copy_to_user(optval, opt->__data, len))
74631 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74632 + copy_to_user(optval, opt->__data, len))
74633 return -EFAULT;
74634 return 0;
74635 }
74636 @@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74637 if (sk->sk_type != SOCK_STREAM)
74638 return -ENOPROTOOPT;
74639
74640 - msg.msg_control = optval;
74641 + msg.msg_control = (void __force_kernel *)optval;
74642 msg.msg_controllen = len;
74643 msg.msg_flags = flags;
74644
74645 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74646 index 92ac7e7..13f93d9 100644
74647 --- a/net/ipv4/ipconfig.c
74648 +++ b/net/ipv4/ipconfig.c
74649 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74650
74651 mm_segment_t oldfs = get_fs();
74652 set_fs(get_ds());
74653 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74654 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74655 set_fs(oldfs);
74656 return res;
74657 }
74658 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74659
74660 mm_segment_t oldfs = get_fs();
74661 set_fs(get_ds());
74662 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74663 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74664 set_fs(oldfs);
74665 return res;
74666 }
74667 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74668
74669 mm_segment_t oldfs = get_fs();
74670 set_fs(get_ds());
74671 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74672 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74673 set_fs(oldfs);
74674 return res;
74675 }
74676 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74677 index 50009c7..5996a9f 100644
74678 --- a/net/ipv4/ping.c
74679 +++ b/net/ipv4/ping.c
74680 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74681 sk_rmem_alloc_get(sp),
74682 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74683 atomic_read(&sp->sk_refcnt), sp,
74684 - atomic_read(&sp->sk_drops), len);
74685 + atomic_read_unchecked(&sp->sk_drops), len);
74686 }
74687
74688 static int ping_seq_show(struct seq_file *seq, void *v)
74689 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74690 index bbd604c..4d5469c 100644
74691 --- a/net/ipv4/raw.c
74692 +++ b/net/ipv4/raw.c
74693 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74694 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74695 {
74696 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74697 - atomic_inc(&sk->sk_drops);
74698 + atomic_inc_unchecked(&sk->sk_drops);
74699 kfree_skb(skb);
74700 return NET_RX_DROP;
74701 }
74702 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
74703
74704 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74705 {
74706 + struct icmp_filter filter;
74707 +
74708 if (optlen > sizeof(struct icmp_filter))
74709 optlen = sizeof(struct icmp_filter);
74710 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74711 + if (copy_from_user(&filter, optval, optlen))
74712 return -EFAULT;
74713 + raw_sk(sk)->filter = filter;
74714 return 0;
74715 }
74716
74717 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74718 {
74719 int len, ret = -EFAULT;
74720 + struct icmp_filter filter;
74721
74722 if (get_user(len, optlen))
74723 goto out;
74724 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74725 if (len > sizeof(struct icmp_filter))
74726 len = sizeof(struct icmp_filter);
74727 ret = -EFAULT;
74728 - if (put_user(len, optlen) ||
74729 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74730 + filter = raw_sk(sk)->filter;
74731 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74732 goto out;
74733 ret = 0;
74734 out: return ret;
74735 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74736 sk_wmem_alloc_get(sp),
74737 sk_rmem_alloc_get(sp),
74738 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74739 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74740 + atomic_read(&sp->sk_refcnt),
74741 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74742 + NULL,
74743 +#else
74744 + sp,
74745 +#endif
74746 + atomic_read_unchecked(&sp->sk_drops));
74747 }
74748
74749 static int raw_seq_show(struct seq_file *seq, void *v)
74750 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74751 index 167ea10..4b15883 100644
74752 --- a/net/ipv4/route.c
74753 +++ b/net/ipv4/route.c
74754 @@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74755
74756 static inline int rt_genid(struct net *net)
74757 {
74758 - return atomic_read(&net->ipv4.rt_genid);
74759 + return atomic_read_unchecked(&net->ipv4.rt_genid);
74760 }
74761
74762 #ifdef CONFIG_PROC_FS
74763 @@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
74764 unsigned char shuffle;
74765
74766 get_random_bytes(&shuffle, sizeof(shuffle));
74767 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74768 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74769 inetpeer_invalidate_tree(AF_INET);
74770 }
74771
74772 @@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
74773 error = rt->dst.error;
74774 if (peer) {
74775 inet_peer_refcheck(rt->peer);
74776 - id = atomic_read(&peer->ip_id_count) & 0xffff;
74777 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74778 if (peer->tcp_ts_stamp) {
74779 ts = peer->tcp_ts;
74780 tsage = get_seconds() - peer->tcp_ts_stamp;
74781 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74782 index 0cb86ce..8e7fda8 100644
74783 --- a/net/ipv4/tcp_ipv4.c
74784 +++ b/net/ipv4/tcp_ipv4.c
74785 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
74786 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74787
74788
74789 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74790 +extern int grsec_enable_blackhole;
74791 +#endif
74792 +
74793 #ifdef CONFIG_TCP_MD5SIG
74794 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
74795 __be32 daddr, __be32 saddr, const struct tcphdr *th);
74796 @@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74797 return 0;
74798
74799 reset:
74800 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74801 + if (!grsec_enable_blackhole)
74802 +#endif
74803 tcp_v4_send_reset(rsk, skb);
74804 discard:
74805 kfree_skb(skb);
74806 @@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74807 TCP_SKB_CB(skb)->sacked = 0;
74808
74809 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74810 - if (!sk)
74811 + if (!sk) {
74812 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74813 + ret = 1;
74814 +#endif
74815 goto no_tcp_socket;
74816 -
74817 + }
74818 process:
74819 - if (sk->sk_state == TCP_TIME_WAIT)
74820 + if (sk->sk_state == TCP_TIME_WAIT) {
74821 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74822 + ret = 2;
74823 +#endif
74824 goto do_time_wait;
74825 + }
74826
74827 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74828 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74829 @@ -1758,6 +1772,10 @@ no_tcp_socket:
74830 bad_packet:
74831 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74832 } else {
74833 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74834 + if (!grsec_enable_blackhole || (ret == 1 &&
74835 + (skb->dev->flags & IFF_LOOPBACK)))
74836 +#endif
74837 tcp_v4_send_reset(NULL, skb);
74838 }
74839
74840 @@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74841 0, /* non standard timer */
74842 0, /* open_requests have no inode */
74843 atomic_read(&sk->sk_refcnt),
74844 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74845 + NULL,
74846 +#else
74847 req,
74848 +#endif
74849 len);
74850 }
74851
74852 @@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74853 sock_i_uid(sk),
74854 icsk->icsk_probes_out,
74855 sock_i_ino(sk),
74856 - atomic_read(&sk->sk_refcnt), sk,
74857 + atomic_read(&sk->sk_refcnt),
74858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74859 + NULL,
74860 +#else
74861 + sk,
74862 +#endif
74863 jiffies_to_clock_t(icsk->icsk_rto),
74864 jiffies_to_clock_t(icsk->icsk_ack.ato),
74865 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74866 @@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74867 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74868 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74869 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74870 - atomic_read(&tw->tw_refcnt), tw, len);
74871 + atomic_read(&tw->tw_refcnt),
74872 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74873 + NULL,
74874 +#else
74875 + tw,
74876 +#endif
74877 + len);
74878 }
74879
74880 #define TMPSZ 150
74881 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74882 index 3cabafb..640525b 100644
74883 --- a/net/ipv4/tcp_minisocks.c
74884 +++ b/net/ipv4/tcp_minisocks.c
74885 @@ -27,6 +27,10 @@
74886 #include <net/inet_common.h>
74887 #include <net/xfrm.h>
74888
74889 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74890 +extern int grsec_enable_blackhole;
74891 +#endif
74892 +
74893 int sysctl_tcp_syncookies __read_mostly = 1;
74894 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74895
74896 @@ -753,6 +757,10 @@ listen_overflow:
74897
74898 embryonic_reset:
74899 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74900 +
74901 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74902 + if (!grsec_enable_blackhole)
74903 +#endif
74904 if (!(flg & TCP_FLAG_RST))
74905 req->rsk_ops->send_reset(sk, skb);
74906
74907 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74908 index a981cdc..48f4c3a 100644
74909 --- a/net/ipv4/tcp_probe.c
74910 +++ b/net/ipv4/tcp_probe.c
74911 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74912 if (cnt + width >= len)
74913 break;
74914
74915 - if (copy_to_user(buf + cnt, tbuf, width))
74916 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74917 return -EFAULT;
74918 cnt += width;
74919 }
74920 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74921 index 34d4a02..3b57f86 100644
74922 --- a/net/ipv4/tcp_timer.c
74923 +++ b/net/ipv4/tcp_timer.c
74924 @@ -22,6 +22,10 @@
74925 #include <linux/gfp.h>
74926 #include <net/tcp.h>
74927
74928 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74929 +extern int grsec_lastack_retries;
74930 +#endif
74931 +
74932 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74933 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
74934 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
74935 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
74936 }
74937 }
74938
74939 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74940 + if ((sk->sk_state == TCP_LAST_ACK) &&
74941 + (grsec_lastack_retries > 0) &&
74942 + (grsec_lastack_retries < retry_until))
74943 + retry_until = grsec_lastack_retries;
74944 +#endif
74945 +
74946 if (retransmits_timed_out(sk, retry_until,
74947 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
74948 /* Has it gone just too far? */
74949 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
74950 index fe14105..0618260 100644
74951 --- a/net/ipv4/udp.c
74952 +++ b/net/ipv4/udp.c
74953 @@ -87,6 +87,7 @@
74954 #include <linux/types.h>
74955 #include <linux/fcntl.h>
74956 #include <linux/module.h>
74957 +#include <linux/security.h>
74958 #include <linux/socket.h>
74959 #include <linux/sockios.h>
74960 #include <linux/igmp.h>
74961 @@ -109,6 +110,10 @@
74962 #include <trace/events/udp.h>
74963 #include "udp_impl.h"
74964
74965 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74966 +extern int grsec_enable_blackhole;
74967 +#endif
74968 +
74969 struct udp_table udp_table __read_mostly;
74970 EXPORT_SYMBOL(udp_table);
74971
74972 @@ -567,6 +572,9 @@ found:
74973 return s;
74974 }
74975
74976 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
74977 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
74978 +
74979 /*
74980 * This routine is called by the ICMP module when it gets some
74981 * sort of error condition. If err < 0 then the socket should
74982 @@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
74983 dport = usin->sin_port;
74984 if (dport == 0)
74985 return -EINVAL;
74986 +
74987 + err = gr_search_udp_sendmsg(sk, usin);
74988 + if (err)
74989 + return err;
74990 } else {
74991 if (sk->sk_state != TCP_ESTABLISHED)
74992 return -EDESTADDRREQ;
74993 +
74994 + err = gr_search_udp_sendmsg(sk, NULL);
74995 + if (err)
74996 + return err;
74997 +
74998 daddr = inet->inet_daddr;
74999 dport = inet->inet_dport;
75000 /* Open fast path for connected socket.
75001 @@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75002 udp_lib_checksum_complete(skb)) {
75003 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75004 IS_UDPLITE(sk));
75005 - atomic_inc(&sk->sk_drops);
75006 + atomic_inc_unchecked(&sk->sk_drops);
75007 __skb_unlink(skb, rcvq);
75008 __skb_queue_tail(&list_kill, skb);
75009 }
75010 @@ -1188,6 +1205,10 @@ try_again:
75011 if (!skb)
75012 goto out;
75013
75014 + err = gr_search_udp_recvmsg(sk, skb);
75015 + if (err)
75016 + goto out_free;
75017 +
75018 ulen = skb->len - sizeof(struct udphdr);
75019 copied = len;
75020 if (copied > ulen)
75021 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75022
75023 drop:
75024 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75025 - atomic_inc(&sk->sk_drops);
75026 + atomic_inc_unchecked(&sk->sk_drops);
75027 kfree_skb(skb);
75028 return -1;
75029 }
75030 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75031 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75032
75033 if (!skb1) {
75034 - atomic_inc(&sk->sk_drops);
75035 + atomic_inc_unchecked(&sk->sk_drops);
75036 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75037 IS_UDPLITE(sk));
75038 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75039 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75040 goto csum_error;
75041
75042 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75043 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75044 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75045 +#endif
75046 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75047
75048 /*
75049 @@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75050 sk_wmem_alloc_get(sp),
75051 sk_rmem_alloc_get(sp),
75052 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75053 - atomic_read(&sp->sk_refcnt), sp,
75054 - atomic_read(&sp->sk_drops), len);
75055 + atomic_read(&sp->sk_refcnt),
75056 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75057 + NULL,
75058 +#else
75059 + sp,
75060 +#endif
75061 + atomic_read_unchecked(&sp->sk_drops), len);
75062 }
75063
75064 int udp4_seq_show(struct seq_file *seq, void *v)
75065 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75066 index 7d5cb97..c56564f 100644
75067 --- a/net/ipv6/addrconf.c
75068 +++ b/net/ipv6/addrconf.c
75069 @@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75070 p.iph.ihl = 5;
75071 p.iph.protocol = IPPROTO_IPV6;
75072 p.iph.ttl = 64;
75073 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75074 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75075
75076 if (ops->ndo_do_ioctl) {
75077 mm_segment_t oldfs = get_fs();
75078 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75079 index 02dd203..e03fcc9 100644
75080 --- a/net/ipv6/inet6_connection_sock.c
75081 +++ b/net/ipv6/inet6_connection_sock.c
75082 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75083 #ifdef CONFIG_XFRM
75084 {
75085 struct rt6_info *rt = (struct rt6_info *)dst;
75086 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75087 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75088 }
75089 #endif
75090 }
75091 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75092 #ifdef CONFIG_XFRM
75093 if (dst) {
75094 struct rt6_info *rt = (struct rt6_info *)dst;
75095 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75096 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75097 __sk_dst_reset(sk);
75098 dst = NULL;
75099 }
75100 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75101 index 63dd1f8..e7f53ca 100644
75102 --- a/net/ipv6/ipv6_sockglue.c
75103 +++ b/net/ipv6/ipv6_sockglue.c
75104 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75105 if (sk->sk_type != SOCK_STREAM)
75106 return -ENOPROTOOPT;
75107
75108 - msg.msg_control = optval;
75109 + msg.msg_control = (void __force_kernel *)optval;
75110 msg.msg_controllen = len;
75111 msg.msg_flags = flags;
75112
75113 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75114 index 5bddea7..82d9d67 100644
75115 --- a/net/ipv6/raw.c
75116 +++ b/net/ipv6/raw.c
75117 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75118 {
75119 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75120 skb_checksum_complete(skb)) {
75121 - atomic_inc(&sk->sk_drops);
75122 + atomic_inc_unchecked(&sk->sk_drops);
75123 kfree_skb(skb);
75124 return NET_RX_DROP;
75125 }
75126 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75127 struct raw6_sock *rp = raw6_sk(sk);
75128
75129 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75130 - atomic_inc(&sk->sk_drops);
75131 + atomic_inc_unchecked(&sk->sk_drops);
75132 kfree_skb(skb);
75133 return NET_RX_DROP;
75134 }
75135 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75136
75137 if (inet->hdrincl) {
75138 if (skb_checksum_complete(skb)) {
75139 - atomic_inc(&sk->sk_drops);
75140 + atomic_inc_unchecked(&sk->sk_drops);
75141 kfree_skb(skb);
75142 return NET_RX_DROP;
75143 }
75144 @@ -602,7 +602,7 @@ out:
75145 return err;
75146 }
75147
75148 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75149 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75150 struct flowi6 *fl6, struct dst_entry **dstp,
75151 unsigned int flags)
75152 {
75153 @@ -914,12 +914,15 @@ do_confirm:
75154 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75155 char __user *optval, int optlen)
75156 {
75157 + struct icmp6_filter filter;
75158 +
75159 switch (optname) {
75160 case ICMPV6_FILTER:
75161 if (optlen > sizeof(struct icmp6_filter))
75162 optlen = sizeof(struct icmp6_filter);
75163 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75164 + if (copy_from_user(&filter, optval, optlen))
75165 return -EFAULT;
75166 + raw6_sk(sk)->filter = filter;
75167 return 0;
75168 default:
75169 return -ENOPROTOOPT;
75170 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75171 char __user *optval, int __user *optlen)
75172 {
75173 int len;
75174 + struct icmp6_filter filter;
75175
75176 switch (optname) {
75177 case ICMPV6_FILTER:
75178 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75179 len = sizeof(struct icmp6_filter);
75180 if (put_user(len, optlen))
75181 return -EFAULT;
75182 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75183 + filter = raw6_sk(sk)->filter;
75184 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
75185 return -EFAULT;
75186 return 0;
75187 default:
75188 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75189 0, 0L, 0,
75190 sock_i_uid(sp), 0,
75191 sock_i_ino(sp),
75192 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75193 + atomic_read(&sp->sk_refcnt),
75194 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75195 + NULL,
75196 +#else
75197 + sp,
75198 +#endif
75199 + atomic_read_unchecked(&sp->sk_drops));
75200 }
75201
75202 static int raw6_seq_show(struct seq_file *seq, void *v)
75203 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75204 index 98256cf..7f16dbd 100644
75205 --- a/net/ipv6/tcp_ipv6.c
75206 +++ b/net/ipv6/tcp_ipv6.c
75207 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75208 }
75209 #endif
75210
75211 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75212 +extern int grsec_enable_blackhole;
75213 +#endif
75214 +
75215 static void tcp_v6_hash(struct sock *sk)
75216 {
75217 if (sk->sk_state != TCP_CLOSE) {
75218 @@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75219 return 0;
75220
75221 reset:
75222 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75223 + if (!grsec_enable_blackhole)
75224 +#endif
75225 tcp_v6_send_reset(sk, skb);
75226 discard:
75227 if (opt_skb)
75228 @@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75229 TCP_SKB_CB(skb)->sacked = 0;
75230
75231 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75232 - if (!sk)
75233 + if (!sk) {
75234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75235 + ret = 1;
75236 +#endif
75237 goto no_tcp_socket;
75238 + }
75239
75240 process:
75241 - if (sk->sk_state == TCP_TIME_WAIT)
75242 + if (sk->sk_state == TCP_TIME_WAIT) {
75243 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75244 + ret = 2;
75245 +#endif
75246 goto do_time_wait;
75247 + }
75248
75249 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75250 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75251 @@ -1676,6 +1691,10 @@ no_tcp_socket:
75252 bad_packet:
75253 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75254 } else {
75255 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75256 + if (!grsec_enable_blackhole || (ret == 1 &&
75257 + (skb->dev->flags & IFF_LOOPBACK)))
75258 +#endif
75259 tcp_v6_send_reset(NULL, skb);
75260 }
75261
75262 @@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
75263 uid,
75264 0, /* non standard timer */
75265 0, /* open_requests have no inode */
75266 - 0, req);
75267 + 0,
75268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75269 + NULL
75270 +#else
75271 + req
75272 +#endif
75273 + );
75274 }
75275
75276 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75277 @@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75278 sock_i_uid(sp),
75279 icsk->icsk_probes_out,
75280 sock_i_ino(sp),
75281 - atomic_read(&sp->sk_refcnt), sp,
75282 + atomic_read(&sp->sk_refcnt),
75283 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75284 + NULL,
75285 +#else
75286 + sp,
75287 +#endif
75288 jiffies_to_clock_t(icsk->icsk_rto),
75289 jiffies_to_clock_t(icsk->icsk_ack.ato),
75290 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75291 @@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75292 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75293 tw->tw_substate, 0, 0,
75294 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75295 - atomic_read(&tw->tw_refcnt), tw);
75296 + atomic_read(&tw->tw_refcnt),
75297 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75298 + NULL
75299 +#else
75300 + tw
75301 +#endif
75302 + );
75303 }
75304
75305 static int tcp6_seq_show(struct seq_file *seq, void *v)
75306 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75307 index 37b0699..d323408 100644
75308 --- a/net/ipv6/udp.c
75309 +++ b/net/ipv6/udp.c
75310 @@ -50,6 +50,10 @@
75311 #include <linux/seq_file.h>
75312 #include "udp_impl.h"
75313
75314 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75315 +extern int grsec_enable_blackhole;
75316 +#endif
75317 +
75318 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75319 {
75320 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75321 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75322
75323 return 0;
75324 drop:
75325 - atomic_inc(&sk->sk_drops);
75326 + atomic_inc_unchecked(&sk->sk_drops);
75327 drop_no_sk_drops_inc:
75328 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75329 kfree_skb(skb);
75330 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75331 continue;
75332 }
75333 drop:
75334 - atomic_inc(&sk->sk_drops);
75335 + atomic_inc_unchecked(&sk->sk_drops);
75336 UDP6_INC_STATS_BH(sock_net(sk),
75337 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75338 UDP6_INC_STATS_BH(sock_net(sk),
75339 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75340 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75341 proto == IPPROTO_UDPLITE);
75342
75343 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75344 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75345 +#endif
75346 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75347
75348 kfree_skb(skb);
75349 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75350 if (!sock_owned_by_user(sk))
75351 udpv6_queue_rcv_skb(sk, skb);
75352 else if (sk_add_backlog(sk, skb)) {
75353 - atomic_inc(&sk->sk_drops);
75354 + atomic_inc_unchecked(&sk->sk_drops);
75355 bh_unlock_sock(sk);
75356 sock_put(sk);
75357 goto discard;
75358 @@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75359 0, 0L, 0,
75360 sock_i_uid(sp), 0,
75361 sock_i_ino(sp),
75362 - atomic_read(&sp->sk_refcnt), sp,
75363 - atomic_read(&sp->sk_drops));
75364 + atomic_read(&sp->sk_refcnt),
75365 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75366 + NULL,
75367 +#else
75368 + sp,
75369 +#endif
75370 + atomic_read_unchecked(&sp->sk_drops));
75371 }
75372
75373 int udp6_seq_show(struct seq_file *seq, void *v)
75374 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75375 index 6b9d5a0..4dffaf1 100644
75376 --- a/net/irda/ircomm/ircomm_tty.c
75377 +++ b/net/irda/ircomm/ircomm_tty.c
75378 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75379 add_wait_queue(&self->open_wait, &wait);
75380
75381 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75382 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75383 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75384
75385 /* As far as I can see, we protect open_count - Jean II */
75386 spin_lock_irqsave(&self->spinlock, flags);
75387 if (!tty_hung_up_p(filp)) {
75388 extra_count = 1;
75389 - self->open_count--;
75390 + local_dec(&self->open_count);
75391 }
75392 spin_unlock_irqrestore(&self->spinlock, flags);
75393 - self->blocked_open++;
75394 + local_inc(&self->blocked_open);
75395
75396 while (1) {
75397 if (tty->termios->c_cflag & CBAUD) {
75398 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75399 }
75400
75401 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75402 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75403 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75404
75405 schedule();
75406 }
75407 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75408 if (extra_count) {
75409 /* ++ is not atomic, so this should be protected - Jean II */
75410 spin_lock_irqsave(&self->spinlock, flags);
75411 - self->open_count++;
75412 + local_inc(&self->open_count);
75413 spin_unlock_irqrestore(&self->spinlock, flags);
75414 }
75415 - self->blocked_open--;
75416 + local_dec(&self->blocked_open);
75417
75418 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75419 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75420 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75421
75422 if (!retval)
75423 self->flags |= ASYNC_NORMAL_ACTIVE;
75424 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75425 }
75426 /* ++ is not atomic, so this should be protected - Jean II */
75427 spin_lock_irqsave(&self->spinlock, flags);
75428 - self->open_count++;
75429 + local_inc(&self->open_count);
75430
75431 tty->driver_data = self;
75432 self->tty = tty;
75433 spin_unlock_irqrestore(&self->spinlock, flags);
75434
75435 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75436 - self->line, self->open_count);
75437 + self->line, local_read(&self->open_count));
75438
75439 /* Not really used by us, but lets do it anyway */
75440 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75441 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75442 return;
75443 }
75444
75445 - if ((tty->count == 1) && (self->open_count != 1)) {
75446 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75447 /*
75448 * Uh, oh. tty->count is 1, which means that the tty
75449 * structure will be freed. state->count should always
75450 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75451 */
75452 IRDA_DEBUG(0, "%s(), bad serial port count; "
75453 "tty->count is 1, state->count is %d\n", __func__ ,
75454 - self->open_count);
75455 - self->open_count = 1;
75456 + local_read(&self->open_count));
75457 + local_set(&self->open_count, 1);
75458 }
75459
75460 - if (--self->open_count < 0) {
75461 + if (local_dec_return(&self->open_count) < 0) {
75462 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75463 - __func__, self->line, self->open_count);
75464 - self->open_count = 0;
75465 + __func__, self->line, local_read(&self->open_count));
75466 + local_set(&self->open_count, 0);
75467 }
75468 - if (self->open_count) {
75469 + if (local_read(&self->open_count)) {
75470 spin_unlock_irqrestore(&self->spinlock, flags);
75471
75472 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75473 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75474 tty->closing = 0;
75475 self->tty = NULL;
75476
75477 - if (self->blocked_open) {
75478 + if (local_read(&self->blocked_open)) {
75479 if (self->close_delay)
75480 schedule_timeout_interruptible(self->close_delay);
75481 wake_up_interruptible(&self->open_wait);
75482 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75483 spin_lock_irqsave(&self->spinlock, flags);
75484 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75485 self->tty = NULL;
75486 - self->open_count = 0;
75487 + local_set(&self->open_count, 0);
75488 spin_unlock_irqrestore(&self->spinlock, flags);
75489
75490 wake_up_interruptible(&self->open_wait);
75491 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75492 seq_putc(m, '\n');
75493
75494 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75495 - seq_printf(m, "Open count: %d\n", self->open_count);
75496 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75497 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75498 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75499
75500 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75501 index cd6f7a9..e63fe89 100644
75502 --- a/net/iucv/af_iucv.c
75503 +++ b/net/iucv/af_iucv.c
75504 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
75505
75506 write_lock_bh(&iucv_sk_list.lock);
75507
75508 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75509 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75510 while (__iucv_get_sock_by_name(name)) {
75511 sprintf(name, "%08x",
75512 - atomic_inc_return(&iucv_sk_list.autobind_name));
75513 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75514 }
75515
75516 write_unlock_bh(&iucv_sk_list.lock);
75517 diff --git a/net/key/af_key.c b/net/key/af_key.c
75518 index 7e5d927..cdbb54e 100644
75519 --- a/net/key/af_key.c
75520 +++ b/net/key/af_key.c
75521 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75522 static u32 get_acqseq(void)
75523 {
75524 u32 res;
75525 - static atomic_t acqseq;
75526 + static atomic_unchecked_t acqseq;
75527
75528 do {
75529 - res = atomic_inc_return(&acqseq);
75530 + res = atomic_inc_return_unchecked(&acqseq);
75531 } while (!res);
75532 return res;
75533 }
75534 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75535 index db8fae5..ff070cd 100644
75536 --- a/net/mac80211/ieee80211_i.h
75537 +++ b/net/mac80211/ieee80211_i.h
75538 @@ -28,6 +28,7 @@
75539 #include <net/ieee80211_radiotap.h>
75540 #include <net/cfg80211.h>
75541 #include <net/mac80211.h>
75542 +#include <asm/local.h>
75543 #include "key.h"
75544 #include "sta_info.h"
75545
75546 @@ -842,7 +843,7 @@ struct ieee80211_local {
75547 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75548 spinlock_t queue_stop_reason_lock;
75549
75550 - int open_count;
75551 + local_t open_count;
75552 int monitors, cooked_mntrs;
75553 /* number of interfaces with corresponding FIF_ flags */
75554 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75555 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75556 index 48f937e..4ccd7b8 100644
75557 --- a/net/mac80211/iface.c
75558 +++ b/net/mac80211/iface.c
75559 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75560 break;
75561 }
75562
75563 - if (local->open_count == 0) {
75564 + if (local_read(&local->open_count) == 0) {
75565 res = drv_start(local);
75566 if (res)
75567 goto err_del_bss;
75568 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75569 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75570
75571 if (!is_valid_ether_addr(dev->dev_addr)) {
75572 - if (!local->open_count)
75573 + if (!local_read(&local->open_count))
75574 drv_stop(local);
75575 return -EADDRNOTAVAIL;
75576 }
75577 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75578 mutex_unlock(&local->mtx);
75579
75580 if (coming_up)
75581 - local->open_count++;
75582 + local_inc(&local->open_count);
75583
75584 if (hw_reconf_flags)
75585 ieee80211_hw_config(local, hw_reconf_flags);
75586 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75587 err_del_interface:
75588 drv_remove_interface(local, sdata);
75589 err_stop:
75590 - if (!local->open_count)
75591 + if (!local_read(&local->open_count))
75592 drv_stop(local);
75593 err_del_bss:
75594 sdata->bss = NULL;
75595 @@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75596 }
75597
75598 if (going_down)
75599 - local->open_count--;
75600 + local_dec(&local->open_count);
75601
75602 switch (sdata->vif.type) {
75603 case NL80211_IFTYPE_AP_VLAN:
75604 @@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75605
75606 ieee80211_recalc_ps(local, -1);
75607
75608 - if (local->open_count == 0) {
75609 + if (local_read(&local->open_count) == 0) {
75610 if (local->ops->napi_poll)
75611 napi_disable(&local->napi);
75612 ieee80211_clear_tx_pending(local);
75613 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75614 index 1633648..d45ebfa 100644
75615 --- a/net/mac80211/main.c
75616 +++ b/net/mac80211/main.c
75617 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75618 local->hw.conf.power_level = power;
75619 }
75620
75621 - if (changed && local->open_count) {
75622 + if (changed && local_read(&local->open_count)) {
75623 ret = drv_config(local, changed);
75624 /*
75625 * Goal:
75626 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75627 index ef8eba1..5c63952 100644
75628 --- a/net/mac80211/pm.c
75629 +++ b/net/mac80211/pm.c
75630 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75631 struct ieee80211_sub_if_data *sdata;
75632 struct sta_info *sta;
75633
75634 - if (!local->open_count)
75635 + if (!local_read(&local->open_count))
75636 goto suspend;
75637
75638 ieee80211_scan_cancel(local);
75639 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75640 cancel_work_sync(&local->dynamic_ps_enable_work);
75641 del_timer_sync(&local->dynamic_ps_timer);
75642
75643 - local->wowlan = wowlan && local->open_count;
75644 + local->wowlan = wowlan && local_read(&local->open_count);
75645 if (local->wowlan) {
75646 int err = drv_suspend(local, wowlan);
75647 if (err < 0) {
75648 @@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75649 }
75650
75651 /* stop hardware - this must stop RX */
75652 - if (local->open_count)
75653 + if (local_read(&local->open_count))
75654 ieee80211_stop_device(local);
75655
75656 suspend:
75657 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75658 index 3313c11..bec9f17 100644
75659 --- a/net/mac80211/rate.c
75660 +++ b/net/mac80211/rate.c
75661 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75662
75663 ASSERT_RTNL();
75664
75665 - if (local->open_count)
75666 + if (local_read(&local->open_count))
75667 return -EBUSY;
75668
75669 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75670 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75671 index c97a065..ff61928 100644
75672 --- a/net/mac80211/rc80211_pid_debugfs.c
75673 +++ b/net/mac80211/rc80211_pid_debugfs.c
75674 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75675
75676 spin_unlock_irqrestore(&events->lock, status);
75677
75678 - if (copy_to_user(buf, pb, p))
75679 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75680 return -EFAULT;
75681
75682 return p;
75683 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75684 index eb9d7c0..d34b832 100644
75685 --- a/net/mac80211/util.c
75686 +++ b/net/mac80211/util.c
75687 @@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75688 }
75689 #endif
75690 /* everything else happens only if HW was up & running */
75691 - if (!local->open_count)
75692 + if (!local_read(&local->open_count))
75693 goto wake_up;
75694
75695 /*
75696 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75697 index 0c6f67e..d02cdfc 100644
75698 --- a/net/netfilter/Kconfig
75699 +++ b/net/netfilter/Kconfig
75700 @@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
75701
75702 To compile it as a module, choose M here. If unsure, say N.
75703
75704 +config NETFILTER_XT_MATCH_GRADM
75705 + tristate '"gradm" match support'
75706 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75707 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75708 + ---help---
75709 + The gradm match allows to match on grsecurity RBAC being enabled.
75710 + It is useful when iptables rules are applied early on bootup to
75711 + prevent connections to the machine (except from a trusted host)
75712 + while the RBAC system is disabled.
75713 +
75714 config NETFILTER_XT_MATCH_HASHLIMIT
75715 tristate '"hashlimit" match support'
75716 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75717 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75718 index ca36765..0882e7c 100644
75719 --- a/net/netfilter/Makefile
75720 +++ b/net/netfilter/Makefile
75721 @@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75722 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75723 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75724 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75725 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75726 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75727 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75728 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75729 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75730 index 29fa5ba..8debc79 100644
75731 --- a/net/netfilter/ipvs/ip_vs_conn.c
75732 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75733 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75734 /* Increase the refcnt counter of the dest */
75735 atomic_inc(&dest->refcnt);
75736
75737 - conn_flags = atomic_read(&dest->conn_flags);
75738 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75739 if (cp->protocol != IPPROTO_UDP)
75740 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75741 /* Bind with the destination and its corresponding transmitter */
75742 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75743 atomic_set(&cp->refcnt, 1);
75744
75745 atomic_set(&cp->n_control, 0);
75746 - atomic_set(&cp->in_pkts, 0);
75747 + atomic_set_unchecked(&cp->in_pkts, 0);
75748
75749 atomic_inc(&ipvs->conn_count);
75750 if (flags & IP_VS_CONN_F_NO_CPORT)
75751 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75752
75753 /* Don't drop the entry if its number of incoming packets is not
75754 located in [0, 8] */
75755 - i = atomic_read(&cp->in_pkts);
75756 + i = atomic_read_unchecked(&cp->in_pkts);
75757 if (i > 8 || i < 0) return 0;
75758
75759 if (!todrop_rate[i]) return 0;
75760 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75761 index 00bdb1d..6725a48 100644
75762 --- a/net/netfilter/ipvs/ip_vs_core.c
75763 +++ b/net/netfilter/ipvs/ip_vs_core.c
75764 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75765 ret = cp->packet_xmit(skb, cp, pd->pp);
75766 /* do not touch skb anymore */
75767
75768 - atomic_inc(&cp->in_pkts);
75769 + atomic_inc_unchecked(&cp->in_pkts);
75770 ip_vs_conn_put(cp);
75771 return ret;
75772 }
75773 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75774 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75775 pkts = sysctl_sync_threshold(ipvs);
75776 else
75777 - pkts = atomic_add_return(1, &cp->in_pkts);
75778 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75779
75780 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75781 cp->protocol == IPPROTO_SCTP) {
75782 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75783 index f558998..9cdff60 100644
75784 --- a/net/netfilter/ipvs/ip_vs_ctl.c
75785 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
75786 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75787 ip_vs_rs_hash(ipvs, dest);
75788 write_unlock_bh(&ipvs->rs_lock);
75789 }
75790 - atomic_set(&dest->conn_flags, conn_flags);
75791 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
75792
75793 /* bind the service */
75794 if (!dest->svc) {
75795 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75796 " %-7s %-6d %-10d %-10d\n",
75797 &dest->addr.in6,
75798 ntohs(dest->port),
75799 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75800 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75801 atomic_read(&dest->weight),
75802 atomic_read(&dest->activeconns),
75803 atomic_read(&dest->inactconns));
75804 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75805 "%-7s %-6d %-10d %-10d\n",
75806 ntohl(dest->addr.ip),
75807 ntohs(dest->port),
75808 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75809 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75810 atomic_read(&dest->weight),
75811 atomic_read(&dest->activeconns),
75812 atomic_read(&dest->inactconns));
75813 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75814
75815 entry.addr = dest->addr.ip;
75816 entry.port = dest->port;
75817 - entry.conn_flags = atomic_read(&dest->conn_flags);
75818 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75819 entry.weight = atomic_read(&dest->weight);
75820 entry.u_threshold = dest->u_threshold;
75821 entry.l_threshold = dest->l_threshold;
75822 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75823 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75824
75825 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75826 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75827 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75828 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75829 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75830 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75831 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75832 index 8a0d6d6..90ec197 100644
75833 --- a/net/netfilter/ipvs/ip_vs_sync.c
75834 +++ b/net/netfilter/ipvs/ip_vs_sync.c
75835 @@ -649,7 +649,7 @@ control:
75836 * i.e only increment in_pkts for Templates.
75837 */
75838 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75839 - int pkts = atomic_add_return(1, &cp->in_pkts);
75840 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75841
75842 if (pkts % sysctl_sync_period(ipvs) != 1)
75843 return;
75844 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75845
75846 if (opt)
75847 memcpy(&cp->in_seq, opt, sizeof(*opt));
75848 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75849 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75850 cp->state = state;
75851 cp->old_state = cp->state;
75852 /*
75853 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75854 index 7fd66de..e6fb361 100644
75855 --- a/net/netfilter/ipvs/ip_vs_xmit.c
75856 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
75857 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75858 else
75859 rc = NF_ACCEPT;
75860 /* do not touch skb anymore */
75861 - atomic_inc(&cp->in_pkts);
75862 + atomic_inc_unchecked(&cp->in_pkts);
75863 goto out;
75864 }
75865
75866 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75867 else
75868 rc = NF_ACCEPT;
75869 /* do not touch skb anymore */
75870 - atomic_inc(&cp->in_pkts);
75871 + atomic_inc_unchecked(&cp->in_pkts);
75872 goto out;
75873 }
75874
75875 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75876 index 66b2c54..c7884e3 100644
75877 --- a/net/netfilter/nfnetlink_log.c
75878 +++ b/net/netfilter/nfnetlink_log.c
75879 @@ -70,7 +70,7 @@ struct nfulnl_instance {
75880 };
75881
75882 static DEFINE_SPINLOCK(instances_lock);
75883 -static atomic_t global_seq;
75884 +static atomic_unchecked_t global_seq;
75885
75886 #define INSTANCE_BUCKETS 16
75887 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75888 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75889 /* global sequence number */
75890 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75891 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75892 - htonl(atomic_inc_return(&global_seq)));
75893 + htonl(atomic_inc_return_unchecked(&global_seq)));
75894
75895 if (data_len) {
75896 struct nlattr *nla;
75897 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75898 new file mode 100644
75899 index 0000000..6905327
75900 --- /dev/null
75901 +++ b/net/netfilter/xt_gradm.c
75902 @@ -0,0 +1,51 @@
75903 +/*
75904 + * gradm match for netfilter
75905 + * Copyright © Zbigniew Krzystolik, 2010
75906 + *
75907 + * This program is free software; you can redistribute it and/or modify
75908 + * it under the terms of the GNU General Public License; either version
75909 + * 2 or 3 as published by the Free Software Foundation.
75910 + */
75911 +#include <linux/module.h>
75912 +#include <linux/moduleparam.h>
75913 +#include <linux/skbuff.h>
75914 +#include <linux/netfilter/x_tables.h>
75915 +#include <linux/grsecurity.h>
75916 +#include <linux/netfilter/xt_gradm.h>
75917 +
75918 +static bool
75919 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
75920 +{
75921 + const struct xt_gradm_mtinfo *info = par->matchinfo;
75922 + bool retval = false;
75923 + if (gr_acl_is_enabled())
75924 + retval = true;
75925 + return retval ^ info->invflags;
75926 +}
75927 +
75928 +static struct xt_match gradm_mt_reg __read_mostly = {
75929 + .name = "gradm",
75930 + .revision = 0,
75931 + .family = NFPROTO_UNSPEC,
75932 + .match = gradm_mt,
75933 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
75934 + .me = THIS_MODULE,
75935 +};
75936 +
75937 +static int __init gradm_mt_init(void)
75938 +{
75939 + return xt_register_match(&gradm_mt_reg);
75940 +}
75941 +
75942 +static void __exit gradm_mt_exit(void)
75943 +{
75944 + xt_unregister_match(&gradm_mt_reg);
75945 +}
75946 +
75947 +module_init(gradm_mt_init);
75948 +module_exit(gradm_mt_exit);
75949 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
75950 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
75951 +MODULE_LICENSE("GPL");
75952 +MODULE_ALIAS("ipt_gradm");
75953 +MODULE_ALIAS("ip6t_gradm");
75954 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
75955 index 4fe4fb4..87a89e5 100644
75956 --- a/net/netfilter/xt_statistic.c
75957 +++ b/net/netfilter/xt_statistic.c
75958 @@ -19,7 +19,7 @@
75959 #include <linux/module.h>
75960
75961 struct xt_statistic_priv {
75962 - atomic_t count;
75963 + atomic_unchecked_t count;
75964 } ____cacheline_aligned_in_smp;
75965
75966 MODULE_LICENSE("GPL");
75967 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
75968 break;
75969 case XT_STATISTIC_MODE_NTH:
75970 do {
75971 - oval = atomic_read(&info->master->count);
75972 + oval = atomic_read_unchecked(&info->master->count);
75973 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
75974 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
75975 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
75976 if (nval == 0)
75977 ret = !ret;
75978 break;
75979 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
75980 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
75981 if (info->master == NULL)
75982 return -ENOMEM;
75983 - atomic_set(&info->master->count, info->u.nth.count);
75984 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
75985
75986 return 0;
75987 }
75988 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
75989 index faa48f7..65f7f54 100644
75990 --- a/net/netlink/af_netlink.c
75991 +++ b/net/netlink/af_netlink.c
75992 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
75993 sk->sk_error_report(sk);
75994 }
75995 }
75996 - atomic_inc(&sk->sk_drops);
75997 + atomic_inc_unchecked(&sk->sk_drops);
75998 }
75999
76000 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76001 @@ -2013,7 +2013,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76002 sk_wmem_alloc_get(s),
76003 nlk->cb,
76004 atomic_read(&s->sk_refcnt),
76005 - atomic_read(&s->sk_drops),
76006 + atomic_read_unchecked(&s->sk_drops),
76007 sock_i_ino(s)
76008 );
76009
76010 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
76011 index 06592d8..64860f6 100644
76012 --- a/net/netrom/af_netrom.c
76013 +++ b/net/netrom/af_netrom.c
76014 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76015 struct sock *sk = sock->sk;
76016 struct nr_sock *nr = nr_sk(sk);
76017
76018 + memset(sax, 0, sizeof(*sax));
76019 lock_sock(sk);
76020 if (peer != 0) {
76021 if (sk->sk_state != TCP_ESTABLISHED) {
76022 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76023 *uaddr_len = sizeof(struct full_sockaddr_ax25);
76024 } else {
76025 sax->fsa_ax25.sax25_family = AF_NETROM;
76026 - sax->fsa_ax25.sax25_ndigis = 0;
76027 sax->fsa_ax25.sax25_call = nr->source_addr;
76028 *uaddr_len = sizeof(struct sockaddr_ax25);
76029 }
76030 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
76031 index 4f2c0df..f0ff342 100644
76032 --- a/net/packet/af_packet.c
76033 +++ b/net/packet/af_packet.c
76034 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76035
76036 spin_lock(&sk->sk_receive_queue.lock);
76037 po->stats.tp_packets++;
76038 - skb->dropcount = atomic_read(&sk->sk_drops);
76039 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76040 __skb_queue_tail(&sk->sk_receive_queue, skb);
76041 spin_unlock(&sk->sk_receive_queue.lock);
76042 sk->sk_data_ready(sk, skb->len);
76043 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76044 drop_n_acct:
76045 spin_lock(&sk->sk_receive_queue.lock);
76046 po->stats.tp_drops++;
76047 - atomic_inc(&sk->sk_drops);
76048 + atomic_inc_unchecked(&sk->sk_drops);
76049 spin_unlock(&sk->sk_receive_queue.lock);
76050
76051 drop_n_restore:
76052 @@ -3294,7 +3294,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76053 case PACKET_HDRLEN:
76054 if (len > sizeof(int))
76055 len = sizeof(int);
76056 - if (copy_from_user(&val, optval, len))
76057 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
76058 return -EFAULT;
76059 switch (val) {
76060 case TPACKET_V1:
76061 @@ -3344,7 +3344,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76062
76063 if (put_user(len, optlen))
76064 return -EFAULT;
76065 - if (copy_to_user(optval, data, len))
76066 + if (len > sizeof(st) || copy_to_user(optval, data, len))
76067 return -EFAULT;
76068 return 0;
76069 }
76070 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
76071 index d65f699..05aa6ce 100644
76072 --- a/net/phonet/af_phonet.c
76073 +++ b/net/phonet/af_phonet.c
76074 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
76075 {
76076 struct phonet_protocol *pp;
76077
76078 - if (protocol >= PHONET_NPROTO)
76079 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76080 return NULL;
76081
76082 rcu_read_lock();
76083 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
76084 {
76085 int err = 0;
76086
76087 - if (protocol >= PHONET_NPROTO)
76088 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76089 return -EINVAL;
76090
76091 err = proto_register(pp->prot, 1);
76092 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
76093 index 9726fe6..fc4e3a4 100644
76094 --- a/net/phonet/pep.c
76095 +++ b/net/phonet/pep.c
76096 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76097
76098 case PNS_PEP_CTRL_REQ:
76099 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
76100 - atomic_inc(&sk->sk_drops);
76101 + atomic_inc_unchecked(&sk->sk_drops);
76102 break;
76103 }
76104 __skb_pull(skb, 4);
76105 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76106 }
76107
76108 if (pn->rx_credits == 0) {
76109 - atomic_inc(&sk->sk_drops);
76110 + atomic_inc_unchecked(&sk->sk_drops);
76111 err = -ENOBUFS;
76112 break;
76113 }
76114 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
76115 }
76116
76117 if (pn->rx_credits == 0) {
76118 - atomic_inc(&sk->sk_drops);
76119 + atomic_inc_unchecked(&sk->sk_drops);
76120 err = NET_RX_DROP;
76121 break;
76122 }
76123 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
76124 index 4c7eff3..59c727f 100644
76125 --- a/net/phonet/socket.c
76126 +++ b/net/phonet/socket.c
76127 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
76128 pn->resource, sk->sk_state,
76129 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
76130 sock_i_uid(sk), sock_i_ino(sk),
76131 - atomic_read(&sk->sk_refcnt), sk,
76132 - atomic_read(&sk->sk_drops), &len);
76133 + atomic_read(&sk->sk_refcnt),
76134 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76135 + NULL,
76136 +#else
76137 + sk,
76138 +#endif
76139 + atomic_read_unchecked(&sk->sk_drops), &len);
76140 }
76141 seq_printf(seq, "%*s\n", 127 - len, "");
76142 return 0;
76143 diff --git a/net/rds/cong.c b/net/rds/cong.c
76144 index e5b65ac..f3b6fb7 100644
76145 --- a/net/rds/cong.c
76146 +++ b/net/rds/cong.c
76147 @@ -78,7 +78,7 @@
76148 * finds that the saved generation number is smaller than the global generation
76149 * number, it wakes up the process.
76150 */
76151 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
76152 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
76153
76154 /*
76155 * Congestion monitoring
76156 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
76157 rdsdebug("waking map %p for %pI4\n",
76158 map, &map->m_addr);
76159 rds_stats_inc(s_cong_update_received);
76160 - atomic_inc(&rds_cong_generation);
76161 + atomic_inc_unchecked(&rds_cong_generation);
76162 if (waitqueue_active(&map->m_waitq))
76163 wake_up(&map->m_waitq);
76164 if (waitqueue_active(&rds_poll_waitq))
76165 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
76166
76167 int rds_cong_updated_since(unsigned long *recent)
76168 {
76169 - unsigned long gen = atomic_read(&rds_cong_generation);
76170 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
76171
76172 if (likely(*recent == gen))
76173 return 0;
76174 diff --git a/net/rds/ib.h b/net/rds/ib.h
76175 index edfaaaf..8c89879 100644
76176 --- a/net/rds/ib.h
76177 +++ b/net/rds/ib.h
76178 @@ -128,7 +128,7 @@ struct rds_ib_connection {
76179 /* sending acks */
76180 unsigned long i_ack_flags;
76181 #ifdef KERNEL_HAS_ATOMIC64
76182 - atomic64_t i_ack_next; /* next ACK to send */
76183 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76184 #else
76185 spinlock_t i_ack_lock; /* protect i_ack_next */
76186 u64 i_ack_next; /* next ACK to send */
76187 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
76188 index a1e1162..265e129 100644
76189 --- a/net/rds/ib_cm.c
76190 +++ b/net/rds/ib_cm.c
76191 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
76192 /* Clear the ACK state */
76193 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76194 #ifdef KERNEL_HAS_ATOMIC64
76195 - atomic64_set(&ic->i_ack_next, 0);
76196 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76197 #else
76198 ic->i_ack_next = 0;
76199 #endif
76200 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
76201 index 8d19491..05a3e65 100644
76202 --- a/net/rds/ib_recv.c
76203 +++ b/net/rds/ib_recv.c
76204 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76205 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
76206 int ack_required)
76207 {
76208 - atomic64_set(&ic->i_ack_next, seq);
76209 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76210 if (ack_required) {
76211 smp_mb__before_clear_bit();
76212 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76213 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76214 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76215 smp_mb__after_clear_bit();
76216
76217 - return atomic64_read(&ic->i_ack_next);
76218 + return atomic64_read_unchecked(&ic->i_ack_next);
76219 }
76220 #endif
76221
76222 diff --git a/net/rds/iw.h b/net/rds/iw.h
76223 index 04ce3b1..48119a6 100644
76224 --- a/net/rds/iw.h
76225 +++ b/net/rds/iw.h
76226 @@ -134,7 +134,7 @@ struct rds_iw_connection {
76227 /* sending acks */
76228 unsigned long i_ack_flags;
76229 #ifdef KERNEL_HAS_ATOMIC64
76230 - atomic64_t i_ack_next; /* next ACK to send */
76231 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76232 #else
76233 spinlock_t i_ack_lock; /* protect i_ack_next */
76234 u64 i_ack_next; /* next ACK to send */
76235 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
76236 index a91e1db..cf3053f 100644
76237 --- a/net/rds/iw_cm.c
76238 +++ b/net/rds/iw_cm.c
76239 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
76240 /* Clear the ACK state */
76241 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76242 #ifdef KERNEL_HAS_ATOMIC64
76243 - atomic64_set(&ic->i_ack_next, 0);
76244 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76245 #else
76246 ic->i_ack_next = 0;
76247 #endif
76248 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
76249 index 4503335..db566b4 100644
76250 --- a/net/rds/iw_recv.c
76251 +++ b/net/rds/iw_recv.c
76252 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76253 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
76254 int ack_required)
76255 {
76256 - atomic64_set(&ic->i_ack_next, seq);
76257 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76258 if (ack_required) {
76259 smp_mb__before_clear_bit();
76260 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76261 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76262 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76263 smp_mb__after_clear_bit();
76264
76265 - return atomic64_read(&ic->i_ack_next);
76266 + return atomic64_read_unchecked(&ic->i_ack_next);
76267 }
76268 #endif
76269
76270 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
76271 index edac9ef..16bcb98 100644
76272 --- a/net/rds/tcp.c
76273 +++ b/net/rds/tcp.c
76274 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
76275 int val = 1;
76276
76277 set_fs(KERNEL_DS);
76278 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
76279 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
76280 sizeof(val));
76281 set_fs(oldfs);
76282 }
76283 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
76284 index 1b4fd68..2234175 100644
76285 --- a/net/rds/tcp_send.c
76286 +++ b/net/rds/tcp_send.c
76287 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
76288
76289 oldfs = get_fs();
76290 set_fs(KERNEL_DS);
76291 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
76292 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
76293 sizeof(val));
76294 set_fs(oldfs);
76295 }
76296 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
76297 index 74c064c..fdec26f 100644
76298 --- a/net/rxrpc/af_rxrpc.c
76299 +++ b/net/rxrpc/af_rxrpc.c
76300 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
76301 __be32 rxrpc_epoch;
76302
76303 /* current debugging ID */
76304 -atomic_t rxrpc_debug_id;
76305 +atomic_unchecked_t rxrpc_debug_id;
76306
76307 /* count of skbs currently in use */
76308 atomic_t rxrpc_n_skbs;
76309 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
76310 index c3126e8..21facc7 100644
76311 --- a/net/rxrpc/ar-ack.c
76312 +++ b/net/rxrpc/ar-ack.c
76313 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76314
76315 _enter("{%d,%d,%d,%d},",
76316 call->acks_hard, call->acks_unacked,
76317 - atomic_read(&call->sequence),
76318 + atomic_read_unchecked(&call->sequence),
76319 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
76320
76321 stop = 0;
76322 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76323
76324 /* each Tx packet has a new serial number */
76325 sp->hdr.serial =
76326 - htonl(atomic_inc_return(&call->conn->serial));
76327 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
76328
76329 hdr = (struct rxrpc_header *) txb->head;
76330 hdr->serial = sp->hdr.serial;
76331 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
76332 */
76333 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
76334 {
76335 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
76336 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
76337 }
76338
76339 /*
76340 @@ -629,7 +629,7 @@ process_further:
76341
76342 latest = ntohl(sp->hdr.serial);
76343 hard = ntohl(ack.firstPacket);
76344 - tx = atomic_read(&call->sequence);
76345 + tx = atomic_read_unchecked(&call->sequence);
76346
76347 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76348 latest,
76349 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
76350 goto maybe_reschedule;
76351
76352 send_ACK_with_skew:
76353 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
76354 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
76355 ntohl(ack.serial));
76356 send_ACK:
76357 mtu = call->conn->trans->peer->if_mtu;
76358 @@ -1173,7 +1173,7 @@ send_ACK:
76359 ackinfo.rxMTU = htonl(5692);
76360 ackinfo.jumbo_max = htonl(4);
76361
76362 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76363 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76364 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76365 ntohl(hdr.serial),
76366 ntohs(ack.maxSkew),
76367 @@ -1191,7 +1191,7 @@ send_ACK:
76368 send_message:
76369 _debug("send message");
76370
76371 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76372 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76373 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76374 send_message_2:
76375
76376 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76377 index bf656c2..48f9d27 100644
76378 --- a/net/rxrpc/ar-call.c
76379 +++ b/net/rxrpc/ar-call.c
76380 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76381 spin_lock_init(&call->lock);
76382 rwlock_init(&call->state_lock);
76383 atomic_set(&call->usage, 1);
76384 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76385 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76386 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76387
76388 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76389 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76390 index 4106ca9..a338d7a 100644
76391 --- a/net/rxrpc/ar-connection.c
76392 +++ b/net/rxrpc/ar-connection.c
76393 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76394 rwlock_init(&conn->lock);
76395 spin_lock_init(&conn->state_lock);
76396 atomic_set(&conn->usage, 1);
76397 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76398 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76399 conn->avail_calls = RXRPC_MAXCALLS;
76400 conn->size_align = 4;
76401 conn->header_size = sizeof(struct rxrpc_header);
76402 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76403 index e7ed43a..6afa140 100644
76404 --- a/net/rxrpc/ar-connevent.c
76405 +++ b/net/rxrpc/ar-connevent.c
76406 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76407
76408 len = iov[0].iov_len + iov[1].iov_len;
76409
76410 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76411 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76412 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76413
76414 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76415 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76416 index 1a2b0633..e8d1382 100644
76417 --- a/net/rxrpc/ar-input.c
76418 +++ b/net/rxrpc/ar-input.c
76419 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76420 /* track the latest serial number on this connection for ACK packet
76421 * information */
76422 serial = ntohl(sp->hdr.serial);
76423 - hi_serial = atomic_read(&call->conn->hi_serial);
76424 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76425 while (serial > hi_serial)
76426 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76427 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76428 serial);
76429
76430 /* request ACK generation for any ACK or DATA packet that requests
76431 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76432 index 8e22bd3..f66d1c0 100644
76433 --- a/net/rxrpc/ar-internal.h
76434 +++ b/net/rxrpc/ar-internal.h
76435 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76436 int error; /* error code for local abort */
76437 int debug_id; /* debug ID for printks */
76438 unsigned call_counter; /* call ID counter */
76439 - atomic_t serial; /* packet serial number counter */
76440 - atomic_t hi_serial; /* highest serial number received */
76441 + atomic_unchecked_t serial; /* packet serial number counter */
76442 + atomic_unchecked_t hi_serial; /* highest serial number received */
76443 u8 avail_calls; /* number of calls available */
76444 u8 size_align; /* data size alignment (for security) */
76445 u8 header_size; /* rxrpc + security header size */
76446 @@ -346,7 +346,7 @@ struct rxrpc_call {
76447 spinlock_t lock;
76448 rwlock_t state_lock; /* lock for state transition */
76449 atomic_t usage;
76450 - atomic_t sequence; /* Tx data packet sequence counter */
76451 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76452 u32 abort_code; /* local/remote abort code */
76453 enum { /* current state of call */
76454 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76455 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76456 */
76457 extern atomic_t rxrpc_n_skbs;
76458 extern __be32 rxrpc_epoch;
76459 -extern atomic_t rxrpc_debug_id;
76460 +extern atomic_unchecked_t rxrpc_debug_id;
76461 extern struct workqueue_struct *rxrpc_workqueue;
76462
76463 /*
76464 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76465 index 87f7135..74d3703 100644
76466 --- a/net/rxrpc/ar-local.c
76467 +++ b/net/rxrpc/ar-local.c
76468 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76469 spin_lock_init(&local->lock);
76470 rwlock_init(&local->services_lock);
76471 atomic_set(&local->usage, 1);
76472 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76473 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76474 memcpy(&local->srx, srx, sizeof(*srx));
76475 }
76476
76477 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76478 index 16ae887..d24f12b 100644
76479 --- a/net/rxrpc/ar-output.c
76480 +++ b/net/rxrpc/ar-output.c
76481 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76482 sp->hdr.cid = call->cid;
76483 sp->hdr.callNumber = call->call_id;
76484 sp->hdr.seq =
76485 - htonl(atomic_inc_return(&call->sequence));
76486 + htonl(atomic_inc_return_unchecked(&call->sequence));
76487 sp->hdr.serial =
76488 - htonl(atomic_inc_return(&conn->serial));
76489 + htonl(atomic_inc_return_unchecked(&conn->serial));
76490 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76491 sp->hdr.userStatus = 0;
76492 sp->hdr.securityIndex = conn->security_ix;
76493 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76494 index 2754f09..b20e38f 100644
76495 --- a/net/rxrpc/ar-peer.c
76496 +++ b/net/rxrpc/ar-peer.c
76497 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76498 INIT_LIST_HEAD(&peer->error_targets);
76499 spin_lock_init(&peer->lock);
76500 atomic_set(&peer->usage, 1);
76501 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76502 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76503 memcpy(&peer->srx, srx, sizeof(*srx));
76504
76505 rxrpc_assess_MTU_size(peer);
76506 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76507 index 38047f7..9f48511 100644
76508 --- a/net/rxrpc/ar-proc.c
76509 +++ b/net/rxrpc/ar-proc.c
76510 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76511 atomic_read(&conn->usage),
76512 rxrpc_conn_states[conn->state],
76513 key_serial(conn->key),
76514 - atomic_read(&conn->serial),
76515 - atomic_read(&conn->hi_serial));
76516 + atomic_read_unchecked(&conn->serial),
76517 + atomic_read_unchecked(&conn->hi_serial));
76518
76519 return 0;
76520 }
76521 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76522 index 92df566..87ec1bf 100644
76523 --- a/net/rxrpc/ar-transport.c
76524 +++ b/net/rxrpc/ar-transport.c
76525 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76526 spin_lock_init(&trans->client_lock);
76527 rwlock_init(&trans->conn_lock);
76528 atomic_set(&trans->usage, 1);
76529 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76530 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76531
76532 if (peer->srx.transport.family == AF_INET) {
76533 switch (peer->srx.transport_type) {
76534 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76535 index 7635107..4670276 100644
76536 --- a/net/rxrpc/rxkad.c
76537 +++ b/net/rxrpc/rxkad.c
76538 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76539
76540 len = iov[0].iov_len + iov[1].iov_len;
76541
76542 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76543 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76544 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76545
76546 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76547 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76548
76549 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76550
76551 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76552 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76553 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76554
76555 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76556 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76557 index 1e2eee8..ce3967e 100644
76558 --- a/net/sctp/proc.c
76559 +++ b/net/sctp/proc.c
76560 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76561 seq_printf(seq,
76562 "%8pK %8pK %-3d %-3d %-2d %-4d "
76563 "%4d %8d %8d %7d %5lu %-5d %5d ",
76564 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76565 + assoc, sk,
76566 + sctp_sk(sk)->type, sk->sk_state,
76567 assoc->state, hash,
76568 assoc->assoc_id,
76569 assoc->sndbuf_used,
76570 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76571 index 92ba71d..9a97902 100644
76572 --- a/net/sctp/socket.c
76573 +++ b/net/sctp/socket.c
76574 @@ -4569,7 +4569,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76575 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76576 if (space_left < addrlen)
76577 return -ENOMEM;
76578 - if (copy_to_user(to, &temp, addrlen))
76579 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76580 return -EFAULT;
76581 to += addrlen;
76582 cnt++;
76583 diff --git a/net/socket.c b/net/socket.c
76584 index 851edcd..b786851 100644
76585 --- a/net/socket.c
76586 +++ b/net/socket.c
76587 @@ -88,6 +88,7 @@
76588 #include <linux/nsproxy.h>
76589 #include <linux/magic.h>
76590 #include <linux/slab.h>
76591 +#include <linux/in.h>
76592
76593 #include <asm/uaccess.h>
76594 #include <asm/unistd.h>
76595 @@ -105,6 +106,8 @@
76596 #include <linux/sockios.h>
76597 #include <linux/atalk.h>
76598
76599 +#include <linux/grsock.h>
76600 +
76601 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76602 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76603 unsigned long nr_segs, loff_t pos);
76604 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76605 &sockfs_dentry_operations, SOCKFS_MAGIC);
76606 }
76607
76608 -static struct vfsmount *sock_mnt __read_mostly;
76609 +struct vfsmount *sock_mnt __read_mostly;
76610
76611 static struct file_system_type sock_fs_type = {
76612 .name = "sockfs",
76613 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76614 return -EAFNOSUPPORT;
76615 if (type < 0 || type >= SOCK_MAX)
76616 return -EINVAL;
76617 + if (protocol < 0)
76618 + return -EINVAL;
76619
76620 /* Compatibility.
76621
76622 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76623 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76624 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76625
76626 + if(!gr_search_socket(family, type, protocol)) {
76627 + retval = -EACCES;
76628 + goto out;
76629 + }
76630 +
76631 + if (gr_handle_sock_all(family, type, protocol)) {
76632 + retval = -EACCES;
76633 + goto out;
76634 + }
76635 +
76636 retval = sock_create(family, type, protocol, &sock);
76637 if (retval < 0)
76638 goto out;
76639 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76640 if (sock) {
76641 err = move_addr_to_kernel(umyaddr, addrlen, &address);
76642 if (err >= 0) {
76643 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76644 + err = -EACCES;
76645 + goto error;
76646 + }
76647 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76648 + if (err)
76649 + goto error;
76650 +
76651 err = security_socket_bind(sock,
76652 (struct sockaddr *)&address,
76653 addrlen);
76654 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76655 (struct sockaddr *)
76656 &address, addrlen);
76657 }
76658 +error:
76659 fput_light(sock->file, fput_needed);
76660 }
76661 return err;
76662 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76663 if ((unsigned)backlog > somaxconn)
76664 backlog = somaxconn;
76665
76666 + if (gr_handle_sock_server_other(sock->sk)) {
76667 + err = -EPERM;
76668 + goto error;
76669 + }
76670 +
76671 + err = gr_search_listen(sock);
76672 + if (err)
76673 + goto error;
76674 +
76675 err = security_socket_listen(sock, backlog);
76676 if (!err)
76677 err = sock->ops->listen(sock, backlog);
76678
76679 +error:
76680 fput_light(sock->file, fput_needed);
76681 }
76682 return err;
76683 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76684 newsock->type = sock->type;
76685 newsock->ops = sock->ops;
76686
76687 + if (gr_handle_sock_server_other(sock->sk)) {
76688 + err = -EPERM;
76689 + sock_release(newsock);
76690 + goto out_put;
76691 + }
76692 +
76693 + err = gr_search_accept(sock);
76694 + if (err) {
76695 + sock_release(newsock);
76696 + goto out_put;
76697 + }
76698 +
76699 /*
76700 * We don't need try_module_get here, as the listening socket (sock)
76701 * has the protocol module (sock->ops->owner) held.
76702 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76703 fd_install(newfd, newfile);
76704 err = newfd;
76705
76706 + gr_attach_curr_ip(newsock->sk);
76707 +
76708 out_put:
76709 fput_light(sock->file, fput_needed);
76710 out:
76711 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76712 int, addrlen)
76713 {
76714 struct socket *sock;
76715 + struct sockaddr *sck;
76716 struct sockaddr_storage address;
76717 int err, fput_needed;
76718
76719 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76720 if (err < 0)
76721 goto out_put;
76722
76723 + sck = (struct sockaddr *)&address;
76724 +
76725 + if (gr_handle_sock_client(sck)) {
76726 + err = -EACCES;
76727 + goto out_put;
76728 + }
76729 +
76730 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
76731 + if (err)
76732 + goto out_put;
76733 +
76734 err =
76735 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
76736 if (err)
76737 @@ -1966,7 +2026,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
76738 * checking falls down on this.
76739 */
76740 if (copy_from_user(ctl_buf,
76741 - (void __user __force *)msg_sys->msg_control,
76742 + (void __force_user *)msg_sys->msg_control,
76743 ctl_len))
76744 goto out_freectl;
76745 msg_sys->msg_control = ctl_buf;
76746 @@ -2136,7 +2196,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
76747 * kernel msghdr to use the kernel address space)
76748 */
76749
76750 - uaddr = (__force void __user *)msg_sys->msg_name;
76751 + uaddr = (void __force_user *)msg_sys->msg_name;
76752 uaddr_len = COMPAT_NAMELEN(msg);
76753 if (MSG_CMSG_COMPAT & flags) {
76754 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
76755 @@ -2758,7 +2818,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76756 }
76757
76758 ifr = compat_alloc_user_space(buf_size);
76759 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
76760 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
76761
76762 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
76763 return -EFAULT;
76764 @@ -2782,12 +2842,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76765 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
76766
76767 if (copy_in_user(rxnfc, compat_rxnfc,
76768 - (void *)(&rxnfc->fs.m_ext + 1) -
76769 - (void *)rxnfc) ||
76770 + (void __user *)(&rxnfc->fs.m_ext + 1) -
76771 + (void __user *)rxnfc) ||
76772 copy_in_user(&rxnfc->fs.ring_cookie,
76773 &compat_rxnfc->fs.ring_cookie,
76774 - (void *)(&rxnfc->fs.location + 1) -
76775 - (void *)&rxnfc->fs.ring_cookie) ||
76776 + (void __user *)(&rxnfc->fs.location + 1) -
76777 + (void __user *)&rxnfc->fs.ring_cookie) ||
76778 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
76779 sizeof(rxnfc->rule_cnt)))
76780 return -EFAULT;
76781 @@ -2799,12 +2859,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76782
76783 if (convert_out) {
76784 if (copy_in_user(compat_rxnfc, rxnfc,
76785 - (const void *)(&rxnfc->fs.m_ext + 1) -
76786 - (const void *)rxnfc) ||
76787 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
76788 + (const void __user *)rxnfc) ||
76789 copy_in_user(&compat_rxnfc->fs.ring_cookie,
76790 &rxnfc->fs.ring_cookie,
76791 - (const void *)(&rxnfc->fs.location + 1) -
76792 - (const void *)&rxnfc->fs.ring_cookie) ||
76793 + (const void __user *)(&rxnfc->fs.location + 1) -
76794 + (const void __user *)&rxnfc->fs.ring_cookie) ||
76795 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
76796 sizeof(rxnfc->rule_cnt)))
76797 return -EFAULT;
76798 @@ -2874,7 +2934,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
76799 old_fs = get_fs();
76800 set_fs(KERNEL_DS);
76801 err = dev_ioctl(net, cmd,
76802 - (struct ifreq __user __force *) &kifr);
76803 + (struct ifreq __force_user *) &kifr);
76804 set_fs(old_fs);
76805
76806 return err;
76807 @@ -2983,7 +3043,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
76808
76809 old_fs = get_fs();
76810 set_fs(KERNEL_DS);
76811 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
76812 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
76813 set_fs(old_fs);
76814
76815 if (cmd == SIOCGIFMAP && !err) {
76816 @@ -3088,7 +3148,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
76817 ret |= __get_user(rtdev, &(ur4->rt_dev));
76818 if (rtdev) {
76819 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
76820 - r4.rt_dev = (char __user __force *)devname;
76821 + r4.rt_dev = (char __force_user *)devname;
76822 devname[15] = 0;
76823 } else
76824 r4.rt_dev = NULL;
76825 @@ -3314,8 +3374,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
76826 int __user *uoptlen;
76827 int err;
76828
76829 - uoptval = (char __user __force *) optval;
76830 - uoptlen = (int __user __force *) optlen;
76831 + uoptval = (char __force_user *) optval;
76832 + uoptlen = (int __force_user *) optlen;
76833
76834 set_fs(KERNEL_DS);
76835 if (level == SOL_SOCKET)
76836 @@ -3335,7 +3395,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
76837 char __user *uoptval;
76838 int err;
76839
76840 - uoptval = (char __user __force *) optval;
76841 + uoptval = (char __force_user *) optval;
76842
76843 set_fs(KERNEL_DS);
76844 if (level == SOL_SOCKET)
76845 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
76846 index 994cfea..5343b6b 100644
76847 --- a/net/sunrpc/sched.c
76848 +++ b/net/sunrpc/sched.c
76849 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
76850 #ifdef RPC_DEBUG
76851 static void rpc_task_set_debuginfo(struct rpc_task *task)
76852 {
76853 - static atomic_t rpc_pid;
76854 + static atomic_unchecked_t rpc_pid;
76855
76856 - task->tk_pid = atomic_inc_return(&rpc_pid);
76857 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
76858 }
76859 #else
76860 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
76861 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
76862 index 8343737..677025e 100644
76863 --- a/net/sunrpc/xprtrdma/svc_rdma.c
76864 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
76865 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
76866 static unsigned int min_max_inline = 4096;
76867 static unsigned int max_max_inline = 65536;
76868
76869 -atomic_t rdma_stat_recv;
76870 -atomic_t rdma_stat_read;
76871 -atomic_t rdma_stat_write;
76872 -atomic_t rdma_stat_sq_starve;
76873 -atomic_t rdma_stat_rq_starve;
76874 -atomic_t rdma_stat_rq_poll;
76875 -atomic_t rdma_stat_rq_prod;
76876 -atomic_t rdma_stat_sq_poll;
76877 -atomic_t rdma_stat_sq_prod;
76878 +atomic_unchecked_t rdma_stat_recv;
76879 +atomic_unchecked_t rdma_stat_read;
76880 +atomic_unchecked_t rdma_stat_write;
76881 +atomic_unchecked_t rdma_stat_sq_starve;
76882 +atomic_unchecked_t rdma_stat_rq_starve;
76883 +atomic_unchecked_t rdma_stat_rq_poll;
76884 +atomic_unchecked_t rdma_stat_rq_prod;
76885 +atomic_unchecked_t rdma_stat_sq_poll;
76886 +atomic_unchecked_t rdma_stat_sq_prod;
76887
76888 /* Temporary NFS request map and context caches */
76889 struct kmem_cache *svc_rdma_map_cachep;
76890 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
76891 len -= *ppos;
76892 if (len > *lenp)
76893 len = *lenp;
76894 - if (len && copy_to_user(buffer, str_buf, len))
76895 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
76896 return -EFAULT;
76897 *lenp = len;
76898 *ppos += len;
76899 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
76900 {
76901 .procname = "rdma_stat_read",
76902 .data = &rdma_stat_read,
76903 - .maxlen = sizeof(atomic_t),
76904 + .maxlen = sizeof(atomic_unchecked_t),
76905 .mode = 0644,
76906 .proc_handler = read_reset_stat,
76907 },
76908 {
76909 .procname = "rdma_stat_recv",
76910 .data = &rdma_stat_recv,
76911 - .maxlen = sizeof(atomic_t),
76912 + .maxlen = sizeof(atomic_unchecked_t),
76913 .mode = 0644,
76914 .proc_handler = read_reset_stat,
76915 },
76916 {
76917 .procname = "rdma_stat_write",
76918 .data = &rdma_stat_write,
76919 - .maxlen = sizeof(atomic_t),
76920 + .maxlen = sizeof(atomic_unchecked_t),
76921 .mode = 0644,
76922 .proc_handler = read_reset_stat,
76923 },
76924 {
76925 .procname = "rdma_stat_sq_starve",
76926 .data = &rdma_stat_sq_starve,
76927 - .maxlen = sizeof(atomic_t),
76928 + .maxlen = sizeof(atomic_unchecked_t),
76929 .mode = 0644,
76930 .proc_handler = read_reset_stat,
76931 },
76932 {
76933 .procname = "rdma_stat_rq_starve",
76934 .data = &rdma_stat_rq_starve,
76935 - .maxlen = sizeof(atomic_t),
76936 + .maxlen = sizeof(atomic_unchecked_t),
76937 .mode = 0644,
76938 .proc_handler = read_reset_stat,
76939 },
76940 {
76941 .procname = "rdma_stat_rq_poll",
76942 .data = &rdma_stat_rq_poll,
76943 - .maxlen = sizeof(atomic_t),
76944 + .maxlen = sizeof(atomic_unchecked_t),
76945 .mode = 0644,
76946 .proc_handler = read_reset_stat,
76947 },
76948 {
76949 .procname = "rdma_stat_rq_prod",
76950 .data = &rdma_stat_rq_prod,
76951 - .maxlen = sizeof(atomic_t),
76952 + .maxlen = sizeof(atomic_unchecked_t),
76953 .mode = 0644,
76954 .proc_handler = read_reset_stat,
76955 },
76956 {
76957 .procname = "rdma_stat_sq_poll",
76958 .data = &rdma_stat_sq_poll,
76959 - .maxlen = sizeof(atomic_t),
76960 + .maxlen = sizeof(atomic_unchecked_t),
76961 .mode = 0644,
76962 .proc_handler = read_reset_stat,
76963 },
76964 {
76965 .procname = "rdma_stat_sq_prod",
76966 .data = &rdma_stat_sq_prod,
76967 - .maxlen = sizeof(atomic_t),
76968 + .maxlen = sizeof(atomic_unchecked_t),
76969 .mode = 0644,
76970 .proc_handler = read_reset_stat,
76971 },
76972 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76973 index 41cb63b..c4a1489 100644
76974 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76975 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76976 @@ -501,7 +501,7 @@ next_sge:
76977 svc_rdma_put_context(ctxt, 0);
76978 goto out;
76979 }
76980 - atomic_inc(&rdma_stat_read);
76981 + atomic_inc_unchecked(&rdma_stat_read);
76982
76983 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
76984 chl_map->ch[ch_no].count -= read_wr.num_sge;
76985 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76986 dto_q);
76987 list_del_init(&ctxt->dto_q);
76988 } else {
76989 - atomic_inc(&rdma_stat_rq_starve);
76990 + atomic_inc_unchecked(&rdma_stat_rq_starve);
76991 clear_bit(XPT_DATA, &xprt->xpt_flags);
76992 ctxt = NULL;
76993 }
76994 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76995 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
76996 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
76997 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
76998 - atomic_inc(&rdma_stat_recv);
76999 + atomic_inc_unchecked(&rdma_stat_recv);
77000
77001 /* Build up the XDR from the receive buffers. */
77002 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
77003 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77004 index 42eb7ba..c887c45 100644
77005 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77006 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77007 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
77008 write_wr.wr.rdma.remote_addr = to;
77009
77010 /* Post It */
77011 - atomic_inc(&rdma_stat_write);
77012 + atomic_inc_unchecked(&rdma_stat_write);
77013 if (svc_rdma_send(xprt, &write_wr))
77014 goto err;
77015 return 0;
77016 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77017 index 73b428b..5f3f8f3 100644
77018 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
77019 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77020 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77021 return;
77022
77023 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
77024 - atomic_inc(&rdma_stat_rq_poll);
77025 + atomic_inc_unchecked(&rdma_stat_rq_poll);
77026
77027 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
77028 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
77029 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77030 }
77031
77032 if (ctxt)
77033 - atomic_inc(&rdma_stat_rq_prod);
77034 + atomic_inc_unchecked(&rdma_stat_rq_prod);
77035
77036 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
77037 /*
77038 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77039 return;
77040
77041 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
77042 - atomic_inc(&rdma_stat_sq_poll);
77043 + atomic_inc_unchecked(&rdma_stat_sq_poll);
77044 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
77045 if (wc.status != IB_WC_SUCCESS)
77046 /* Close the transport */
77047 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77048 }
77049
77050 if (ctxt)
77051 - atomic_inc(&rdma_stat_sq_prod);
77052 + atomic_inc_unchecked(&rdma_stat_sq_prod);
77053 }
77054
77055 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
77056 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
77057 spin_lock_bh(&xprt->sc_lock);
77058 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
77059 spin_unlock_bh(&xprt->sc_lock);
77060 - atomic_inc(&rdma_stat_sq_starve);
77061 + atomic_inc_unchecked(&rdma_stat_sq_starve);
77062
77063 /* See if we can opportunistically reap SQ WR to make room */
77064 sq_cq_reap(xprt);
77065 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
77066 index c3e65ae..f512a2b 100644
77067 --- a/net/sysctl_net.c
77068 +++ b/net/sysctl_net.c
77069 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
77070 struct ctl_table *table)
77071 {
77072 /* Allow network administrator to have same access as root. */
77073 - if (capable(CAP_NET_ADMIN)) {
77074 + if (capable_nolog(CAP_NET_ADMIN)) {
77075 int mode = (table->mode >> 6) & 7;
77076 return (mode << 6) | (mode << 3) | mode;
77077 }
77078 diff --git a/net/tipc/link.c b/net/tipc/link.c
77079 index b4b9b30..5b62131 100644
77080 --- a/net/tipc/link.c
77081 +++ b/net/tipc/link.c
77082 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
77083 struct tipc_msg fragm_hdr;
77084 struct sk_buff *buf, *buf_chain, *prev;
77085 u32 fragm_crs, fragm_rest, hsz, sect_rest;
77086 - const unchar *sect_crs;
77087 + const unchar __user *sect_crs;
77088 int curr_sect;
77089 u32 fragm_no;
77090
77091 @@ -1247,7 +1247,7 @@ again:
77092
77093 if (!sect_rest) {
77094 sect_rest = msg_sect[++curr_sect].iov_len;
77095 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
77096 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
77097 }
77098
77099 if (sect_rest < fragm_rest)
77100 @@ -1266,7 +1266,7 @@ error:
77101 }
77102 } else
77103 skb_copy_to_linear_data_offset(buf, fragm_crs,
77104 - sect_crs, sz);
77105 + (const void __force_kernel *)sect_crs, sz);
77106 sect_crs += sz;
77107 sect_rest -= sz;
77108 fragm_crs += sz;
77109 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
77110 index e3afe16..333ea83 100644
77111 --- a/net/tipc/msg.c
77112 +++ b/net/tipc/msg.c
77113 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
77114 msg_sect[cnt].iov_len);
77115 else
77116 skb_copy_to_linear_data_offset(*buf, pos,
77117 - msg_sect[cnt].iov_base,
77118 + (const void __force_kernel *)msg_sect[cnt].iov_base,
77119 msg_sect[cnt].iov_len);
77120 pos += msg_sect[cnt].iov_len;
77121 }
77122 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
77123 index b2964e9..fdf2e27 100644
77124 --- a/net/tipc/subscr.c
77125 +++ b/net/tipc/subscr.c
77126 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
77127 {
77128 struct iovec msg_sect;
77129
77130 - msg_sect.iov_base = (void *)&sub->evt;
77131 + msg_sect.iov_base = (void __force_user *)&sub->evt;
77132 msg_sect.iov_len = sizeof(struct tipc_event);
77133
77134 sub->evt.event = htohl(event, sub->swap);
77135 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
77136 index d510353..26c8a32 100644
77137 --- a/net/unix/af_unix.c
77138 +++ b/net/unix/af_unix.c
77139 @@ -779,6 +779,12 @@ static struct sock *unix_find_other(struct net *net,
77140 err = -ECONNREFUSED;
77141 if (!S_ISSOCK(inode->i_mode))
77142 goto put_fail;
77143 +
77144 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
77145 + err = -EACCES;
77146 + goto put_fail;
77147 + }
77148 +
77149 u = unix_find_socket_byinode(inode);
77150 if (!u)
77151 goto put_fail;
77152 @@ -799,6 +805,13 @@ static struct sock *unix_find_other(struct net *net,
77153 if (u) {
77154 struct dentry *dentry;
77155 dentry = unix_sk(u)->path.dentry;
77156 +
77157 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
77158 + err = -EPERM;
77159 + sock_put(u);
77160 + goto fail;
77161 + }
77162 +
77163 if (dentry)
77164 touch_atime(&unix_sk(u)->path);
77165 } else
77166 @@ -881,11 +894,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
77167 err = security_path_mknod(&path, dentry, mode, 0);
77168 if (err)
77169 goto out_mknod_drop_write;
77170 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
77171 + err = -EACCES;
77172 + goto out_mknod_drop_write;
77173 + }
77174 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
77175 out_mknod_drop_write:
77176 mnt_drop_write(path.mnt);
77177 if (err)
77178 goto out_mknod_dput;
77179 +
77180 + gr_handle_create(dentry, path.mnt);
77181 +
77182 mutex_unlock(&path.dentry->d_inode->i_mutex);
77183 dput(path.dentry);
77184 path.dentry = dentry;
77185 diff --git a/net/wireless/core.h b/net/wireless/core.h
77186 index 3ac2dd0..fbe533e 100644
77187 --- a/net/wireless/core.h
77188 +++ b/net/wireless/core.h
77189 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
77190 struct mutex mtx;
77191
77192 /* rfkill support */
77193 - struct rfkill_ops rfkill_ops;
77194 + rfkill_ops_no_const rfkill_ops;
77195 struct rfkill *rfkill;
77196 struct work_struct rfkill_sync;
77197
77198 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
77199 index af648e0..6185d3a 100644
77200 --- a/net/wireless/wext-core.c
77201 +++ b/net/wireless/wext-core.c
77202 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77203 */
77204
77205 /* Support for very large requests */
77206 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
77207 - (user_length > descr->max_tokens)) {
77208 + if (user_length > descr->max_tokens) {
77209 /* Allow userspace to GET more than max so
77210 * we can support any size GET requests.
77211 * There is still a limit : -ENOMEM.
77212 @@ -787,22 +786,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77213 }
77214 }
77215
77216 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
77217 - /*
77218 - * If this is a GET, but not NOMAX, it means that the extra
77219 - * data is not bounded by userspace, but by max_tokens. Thus
77220 - * set the length to max_tokens. This matches the extra data
77221 - * allocation.
77222 - * The driver should fill it with the number of tokens it
77223 - * provided, and it may check iwp->length rather than having
77224 - * knowledge of max_tokens. If the driver doesn't change the
77225 - * iwp->length, this ioctl just copies back max_token tokens
77226 - * filled with zeroes. Hopefully the driver isn't claiming
77227 - * them to be valid data.
77228 - */
77229 - iwp->length = descr->max_tokens;
77230 - }
77231 -
77232 err = handler(dev, info, (union iwreq_data *) iwp, extra);
77233
77234 iwp->length += essid_compat;
77235 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
77236 index a15d2a0..12142af 100644
77237 --- a/net/xfrm/xfrm_policy.c
77238 +++ b/net/xfrm/xfrm_policy.c
77239 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
77240 {
77241 policy->walk.dead = 1;
77242
77243 - atomic_inc(&policy->genid);
77244 + atomic_inc_unchecked(&policy->genid);
77245
77246 if (del_timer(&policy->timer))
77247 xfrm_pol_put(policy);
77248 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
77249 hlist_add_head(&policy->bydst, chain);
77250 xfrm_pol_hold(policy);
77251 net->xfrm.policy_count[dir]++;
77252 - atomic_inc(&flow_cache_genid);
77253 + atomic_inc_unchecked(&flow_cache_genid);
77254 if (delpol)
77255 __xfrm_policy_unlink(delpol, dir);
77256 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
77257 @@ -1530,7 +1530,7 @@ free_dst:
77258 goto out;
77259 }
77260
77261 -static int inline
77262 +static inline int
77263 xfrm_dst_alloc_copy(void **target, const void *src, int size)
77264 {
77265 if (!*target) {
77266 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
77267 return 0;
77268 }
77269
77270 -static int inline
77271 +static inline int
77272 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77273 {
77274 #ifdef CONFIG_XFRM_SUB_POLICY
77275 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77276 #endif
77277 }
77278
77279 -static int inline
77280 +static inline int
77281 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
77282 {
77283 #ifdef CONFIG_XFRM_SUB_POLICY
77284 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
77285
77286 xdst->num_pols = num_pols;
77287 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
77288 - xdst->policy_genid = atomic_read(&pols[0]->genid);
77289 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
77290
77291 return xdst;
77292 }
77293 @@ -2348,7 +2348,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
77294 if (xdst->xfrm_genid != dst->xfrm->genid)
77295 return 0;
77296 if (xdst->num_pols > 0 &&
77297 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
77298 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
77299 return 0;
77300
77301 mtu = dst_mtu(dst->child);
77302 @@ -2885,7 +2885,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
77303 sizeof(pol->xfrm_vec[i].saddr));
77304 pol->xfrm_vec[i].encap_family = mp->new_family;
77305 /* flush bundles */
77306 - atomic_inc(&pol->genid);
77307 + atomic_inc_unchecked(&pol->genid);
77308 }
77309 }
77310
77311 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
77312 index ff1720d..ed8475e 100644
77313 --- a/scripts/Makefile.build
77314 +++ b/scripts/Makefile.build
77315 @@ -111,7 +111,7 @@ endif
77316 endif
77317
77318 # Do not include host rules unless needed
77319 -ifneq ($(hostprogs-y)$(hostprogs-m),)
77320 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
77321 include scripts/Makefile.host
77322 endif
77323
77324 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
77325 index 686cb0d..9d653bf 100644
77326 --- a/scripts/Makefile.clean
77327 +++ b/scripts/Makefile.clean
77328 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
77329 __clean-files := $(extra-y) $(always) \
77330 $(targets) $(clean-files) \
77331 $(host-progs) \
77332 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
77333 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
77334 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
77335
77336 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
77337
77338 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
77339 index 1ac414f..38575f7 100644
77340 --- a/scripts/Makefile.host
77341 +++ b/scripts/Makefile.host
77342 @@ -31,6 +31,8 @@
77343 # Note: Shared libraries consisting of C++ files are not supported
77344
77345 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
77346 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
77347 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
77348
77349 # C code
77350 # Executables compiled from a single .c file
77351 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77352 # Shared libaries (only .c supported)
77353 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77354 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77355 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77356 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
77357 # Remove .so files from "xxx-objs"
77358 host-cobjs := $(filter-out %.so,$(host-cobjs))
77359 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
77360
77361 -#Object (.o) files used by the shared libaries
77362 +# Object (.o) files used by the shared libaries
77363 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
77364 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
77365
77366 # output directory for programs/.o files
77367 # hostprogs-y := tools/build may have been specified. Retrieve directory
77368 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
77369 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
77370 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
77371 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
77372 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
77373 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
77374 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
77375 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
77376
77377 obj-dirs += $(host-objdirs)
77378 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
77379 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
77380 $(call if_changed_dep,host-cshobjs)
77381
77382 +# Compile .c file, create position independent .o file
77383 +# host-cxxshobjs -> .o
77384 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
77385 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
77386 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
77387 + $(call if_changed_dep,host-cxxshobjs)
77388 +
77389 # Link a shared library, based on position independent .o files
77390 # *.o -> .so shared library (host-cshlib)
77391 quiet_cmd_host-cshlib = HOSTLLD -shared $@
77392 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
77393 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
77394 $(call if_changed,host-cshlib)
77395
77396 +# Link a shared library, based on position independent .o files
77397 +# *.o -> .so shared library (host-cxxshlib)
77398 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
77399 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
77400 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
77401 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
77402 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
77403 + $(call if_changed,host-cxxshlib)
77404 +
77405 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
77406 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
77407 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
77408
77409 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77410 index cb1f50c..cef2a7c 100644
77411 --- a/scripts/basic/fixdep.c
77412 +++ b/scripts/basic/fixdep.c
77413 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77414 /*
77415 * Lookup a value in the configuration string.
77416 */
77417 -static int is_defined_config(const char *name, int len, unsigned int hash)
77418 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77419 {
77420 struct item *aux;
77421
77422 @@ -211,10 +211,10 @@ static void clear_config(void)
77423 /*
77424 * Record the use of a CONFIG_* word.
77425 */
77426 -static void use_config(const char *m, int slen)
77427 +static void use_config(const char *m, unsigned int slen)
77428 {
77429 unsigned int hash = strhash(m, slen);
77430 - int c, i;
77431 + unsigned int c, i;
77432
77433 if (is_defined_config(m, slen, hash))
77434 return;
77435 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77436
77437 static void parse_config_file(const char *map, size_t len)
77438 {
77439 - const int *end = (const int *) (map + len);
77440 + const unsigned int *end = (const unsigned int *) (map + len);
77441 /* start at +1, so that p can never be < map */
77442 - const int *m = (const int *) map + 1;
77443 + const unsigned int *m = (const unsigned int *) map + 1;
77444 const char *p, *q;
77445
77446 for (; m < end; m++) {
77447 @@ -406,7 +406,7 @@ static void print_deps(void)
77448 static void traps(void)
77449 {
77450 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77451 - int *p = (int *)test;
77452 + unsigned int *p = (unsigned int *)test;
77453
77454 if (*p != INT_CONF) {
77455 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77456 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77457 new file mode 100644
77458 index 0000000..008ac1a
77459 --- /dev/null
77460 +++ b/scripts/gcc-plugin.sh
77461 @@ -0,0 +1,17 @@
77462 +#!/bin/bash
77463 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
77464 +#include "gcc-plugin.h"
77465 +#include "tree.h"
77466 +#include "tm.h"
77467 +#include "rtl.h"
77468 +#ifdef ENABLE_BUILD_WITH_CXX
77469 +#warning $2
77470 +#else
77471 +#warning $1
77472 +#endif
77473 +EOF`
77474 +if [ $? -eq 0 ]
77475 +then
77476 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
77477 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
77478 +fi
77479 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77480 index 44ddaa5..a3119bd 100644
77481 --- a/scripts/mod/file2alias.c
77482 +++ b/scripts/mod/file2alias.c
77483 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
77484 unsigned long size, unsigned long id_size,
77485 void *symval)
77486 {
77487 - int i;
77488 + unsigned int i;
77489
77490 if (size % id_size || size < id_size) {
77491 if (cross_build != 0)
77492 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
77493 /* USB is special because the bcdDevice can be matched against a numeric range */
77494 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77495 static void do_usb_entry(struct usb_device_id *id,
77496 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77497 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77498 unsigned char range_lo, unsigned char range_hi,
77499 unsigned char max, struct module *mod)
77500 {
77501 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77502 {
77503 unsigned int devlo, devhi;
77504 unsigned char chi, clo, max;
77505 - int ndigits;
77506 + unsigned int ndigits;
77507
77508 id->match_flags = TO_NATIVE(id->match_flags);
77509 id->idVendor = TO_NATIVE(id->idVendor);
77510 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77511 for (i = 0; i < count; i++) {
77512 const char *id = (char *)devs[i].id;
77513 char acpi_id[sizeof(devs[0].id)];
77514 - int j;
77515 + unsigned int j;
77516
77517 buf_printf(&mod->dev_table_buf,
77518 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77519 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77520
77521 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77522 const char *id = (char *)card->devs[j].id;
77523 - int i2, j2;
77524 + unsigned int i2, j2;
77525 int dup = 0;
77526
77527 if (!id[0])
77528 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77529 /* add an individual alias for every device entry */
77530 if (!dup) {
77531 char acpi_id[sizeof(card->devs[0].id)];
77532 - int k;
77533 + unsigned int k;
77534
77535 buf_printf(&mod->dev_table_buf,
77536 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77537 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77538 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77539 char *alias)
77540 {
77541 - int i, j;
77542 + unsigned int i, j;
77543
77544 sprintf(alias, "dmi*");
77545
77546 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77547 index c4e7d15..4241aef 100644
77548 --- a/scripts/mod/modpost.c
77549 +++ b/scripts/mod/modpost.c
77550 @@ -922,6 +922,7 @@ enum mismatch {
77551 ANY_INIT_TO_ANY_EXIT,
77552 ANY_EXIT_TO_ANY_INIT,
77553 EXPORT_TO_INIT_EXIT,
77554 + DATA_TO_TEXT
77555 };
77556
77557 struct sectioncheck {
77558 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
77559 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77560 .mismatch = EXPORT_TO_INIT_EXIT,
77561 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77562 +},
77563 +/* Do not reference code from writable data */
77564 +{
77565 + .fromsec = { DATA_SECTIONS, NULL },
77566 + .tosec = { TEXT_SECTIONS, NULL },
77567 + .mismatch = DATA_TO_TEXT
77568 }
77569 };
77570
77571 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77572 continue;
77573 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77574 continue;
77575 - if (sym->st_value == addr)
77576 - return sym;
77577 /* Find a symbol nearby - addr are maybe negative */
77578 d = sym->st_value - addr;
77579 + if (d == 0)
77580 + return sym;
77581 if (d < 0)
77582 d = addr - sym->st_value;
77583 if (d < distance) {
77584 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
77585 tosym, prl_to, prl_to, tosym);
77586 free(prl_to);
77587 break;
77588 + case DATA_TO_TEXT:
77589 +/*
77590 + fprintf(stderr,
77591 + "The variable %s references\n"
77592 + "the %s %s%s%s\n",
77593 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77594 +*/
77595 + break;
77596 }
77597 fprintf(stderr, "\n");
77598 }
77599 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77600 static void check_sec_ref(struct module *mod, const char *modname,
77601 struct elf_info *elf)
77602 {
77603 - int i;
77604 + unsigned int i;
77605 Elf_Shdr *sechdrs = elf->sechdrs;
77606
77607 /* Walk through all sections */
77608 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77609 va_end(ap);
77610 }
77611
77612 -void buf_write(struct buffer *buf, const char *s, int len)
77613 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77614 {
77615 if (buf->size - buf->pos < len) {
77616 buf->size += len + SZ;
77617 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77618 if (fstat(fileno(file), &st) < 0)
77619 goto close_write;
77620
77621 - if (st.st_size != b->pos)
77622 + if (st.st_size != (off_t)b->pos)
77623 goto close_write;
77624
77625 tmp = NOFAIL(malloc(b->pos));
77626 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77627 index 51207e4..f7d603d 100644
77628 --- a/scripts/mod/modpost.h
77629 +++ b/scripts/mod/modpost.h
77630 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77631
77632 struct buffer {
77633 char *p;
77634 - int pos;
77635 - int size;
77636 + unsigned int pos;
77637 + unsigned int size;
77638 };
77639
77640 void __attribute__((format(printf, 2, 3)))
77641 buf_printf(struct buffer *buf, const char *fmt, ...);
77642
77643 void
77644 -buf_write(struct buffer *buf, const char *s, int len);
77645 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77646
77647 struct module {
77648 struct module *next;
77649 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77650 index 9dfcd6d..099068e 100644
77651 --- a/scripts/mod/sumversion.c
77652 +++ b/scripts/mod/sumversion.c
77653 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77654 goto out;
77655 }
77656
77657 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77658 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77659 warn("writing sum in %s failed: %s\n",
77660 filename, strerror(errno));
77661 goto out;
77662 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77663 index 5c11312..72742b5 100644
77664 --- a/scripts/pnmtologo.c
77665 +++ b/scripts/pnmtologo.c
77666 @@ -237,14 +237,14 @@ static void write_header(void)
77667 fprintf(out, " * Linux logo %s\n", logoname);
77668 fputs(" */\n\n", out);
77669 fputs("#include <linux/linux_logo.h>\n\n", out);
77670 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77671 + fprintf(out, "static unsigned char %s_data[] = {\n",
77672 logoname);
77673 }
77674
77675 static void write_footer(void)
77676 {
77677 fputs("\n};\n\n", out);
77678 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
77679 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
77680 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
77681 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
77682 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
77683 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
77684 fputs("\n};\n\n", out);
77685
77686 /* write logo clut */
77687 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
77688 + fprintf(out, "static unsigned char %s_clut[] = {\n",
77689 logoname);
77690 write_hex_cnt = 0;
77691 for (i = 0; i < logo_clutsize; i++) {
77692 diff --git a/security/Kconfig b/security/Kconfig
77693 index ccc61f8..7244cf1 100644
77694 --- a/security/Kconfig
77695 +++ b/security/Kconfig
77696 @@ -4,6 +4,861 @@
77697
77698 menu "Security options"
77699
77700 +menu "Grsecurity"
77701 +
77702 + config ARCH_TRACK_EXEC_LIMIT
77703 + bool
77704 +
77705 + config PAX_KERNEXEC_PLUGIN
77706 + bool
77707 +
77708 + config PAX_PER_CPU_PGD
77709 + bool
77710 +
77711 + config TASK_SIZE_MAX_SHIFT
77712 + int
77713 + depends on X86_64
77714 + default 47 if !PAX_PER_CPU_PGD
77715 + default 42 if PAX_PER_CPU_PGD
77716 +
77717 + config PAX_ENABLE_PAE
77718 + bool
77719 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
77720 +
77721 +config GRKERNSEC
77722 + bool "Grsecurity"
77723 + select CRYPTO
77724 + select CRYPTO_SHA256
77725 + select STOP_MACHINE
77726 + help
77727 + If you say Y here, you will be able to configure many features
77728 + that will enhance the security of your system. It is highly
77729 + recommended that you say Y here and read through the help
77730 + for each option so that you fully understand the features and
77731 + can evaluate their usefulness for your machine.
77732 +
77733 +choice
77734 + prompt "Configuration Method"
77735 + depends on GRKERNSEC
77736 + default GRKERNSEC_CONFIG_CUSTOM
77737 + help
77738 +
77739 +config GRKERNSEC_CONFIG_AUTO
77740 + bool "Automatic"
77741 + help
77742 + If you choose this configuration method, you'll be able to answer a small
77743 + number of simple questions about how you plan to use this kernel.
77744 + The settings of grsecurity and PaX will be automatically configured for
77745 + the highest commonly-used settings within the provided constraints.
77746 +
77747 + If you require additional configuration, custom changes can still be made
77748 + from the "custom configuration" menu.
77749 +
77750 +config GRKERNSEC_CONFIG_CUSTOM
77751 + bool "Custom"
77752 + help
77753 + If you choose this configuration method, you'll be able to configure all
77754 + grsecurity and PaX settings manually. Via this method, no options are
77755 + automatically enabled.
77756 +
77757 +endchoice
77758 +
77759 +choice
77760 + prompt "Usage Type"
77761 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77762 + default GRKERNSEC_CONFIG_SERVER
77763 + help
77764 +
77765 +config GRKERNSEC_CONFIG_SERVER
77766 + bool "Server"
77767 + help
77768 + Choose this option if you plan to use this kernel on a server.
77769 +
77770 +config GRKERNSEC_CONFIG_DESKTOP
77771 + bool "Desktop"
77772 + help
77773 + Choose this option if you plan to use this kernel on a desktop.
77774 +
77775 +endchoice
77776 +
77777 +choice
77778 + prompt "Virtualization Type"
77779 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
77780 + default GRKERNSEC_CONFIG_VIRT_NONE
77781 + help
77782 +
77783 +config GRKERNSEC_CONFIG_VIRT_NONE
77784 + bool "None"
77785 + help
77786 + Choose this option if this kernel will be run on bare metal.
77787 +
77788 +config GRKERNSEC_CONFIG_VIRT_GUEST
77789 + bool "Guest"
77790 + help
77791 + Choose this option if this kernel will be run as a VM guest.
77792 +
77793 +config GRKERNSEC_CONFIG_VIRT_HOST
77794 + bool "Host"
77795 + help
77796 + Choose this option if this kernel will be run as a VM host.
77797 +
77798 +endchoice
77799 +
77800 +choice
77801 + prompt "Virtualization Hardware"
77802 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
77803 + help
77804 +
77805 +config GRKERNSEC_CONFIG_VIRT_EPT
77806 + bool "EPT/RVI Processor Support"
77807 + depends on X86
77808 + help
77809 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
77810 + hardware virtualization. This allows for additional kernel hardening protections
77811 + to operate without additional performance impact.
77812 +
77813 + To see if your Intel processor supports EPT, see:
77814 + http://ark.intel.com/Products/VirtualizationTechnology
77815 + (Most Core i3/5/7 support EPT)
77816 +
77817 + To see if your AMD processor supports RVI, see:
77818 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
77819 +
77820 +config GRKERNSEC_CONFIG_VIRT_SOFT
77821 + bool "First-gen/No Hardware Virtualization"
77822 + help
77823 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
77824 + support hardware virtualization or doesn't support the EPT/RVI extensions.
77825 +
77826 +endchoice
77827 +
77828 +choice
77829 + prompt "Virtualization Software"
77830 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
77831 + help
77832 +
77833 +config GRKERNSEC_CONFIG_VIRT_XEN
77834 + bool "Xen"
77835 + help
77836 + Choose this option if this kernel is running as a Xen guest or host.
77837 +
77838 +config GRKERNSEC_CONFIG_VIRT_VMWARE
77839 + bool "VMWare"
77840 + help
77841 + Choose this option if this kernel is running as a VMWare guest or host.
77842 +
77843 +config GRKERNSEC_CONFIG_VIRT_KVM
77844 + bool "KVM"
77845 + help
77846 + Choose this option if this kernel is running as a KVM guest or host.
77847 +
77848 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
77849 + bool "VirtualBox"
77850 + help
77851 + Choose this option if this kernel is running as a VirtualBox guest or host.
77852 +
77853 +endchoice
77854 +
77855 +choice
77856 + prompt "Required Priorities"
77857 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77858 + default GRKERNSEC_CONFIG_PRIORITY_PERF
77859 + help
77860 +
77861 +config GRKERNSEC_CONFIG_PRIORITY_PERF
77862 + bool "Performance"
77863 + help
77864 + Choose this option if performance is of highest priority for this deployment
77865 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
77866 + and freed memory sanitizing will be disabled.
77867 +
77868 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
77869 + bool "Security"
77870 + help
77871 + Choose this option if security is of highest priority for this deployment of
77872 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
77873 + be enabled for this kernel. In a worst-case scenario, these features can
77874 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
77875 +
77876 +endchoice
77877 +
77878 +menu "Default Special Groups"
77879 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77880 +
77881 +config GRKERNSEC_PROC_GID
77882 + int "GID exempted from /proc restrictions"
77883 + default 1001
77884 + help
77885 + Setting this GID determines which group will be exempted from
77886 + grsecurity's /proc restrictions, allowing users of the specified
77887 + group to view network statistics and the existence of other users'
77888 + processes on the system.
77889 +
77890 +config GRKERNSEC_TPE_GID
77891 + int "GID for untrusted users"
77892 + depends on GRKERNSEC_CONFIG_SERVER
77893 + default 1005
77894 + help
77895 + Setting this GID determines which group untrusted users should
77896 + be added to. These users will be placed under grsecurity's Trusted Path
77897 + Execution mechanism, preventing them from executing their own binaries.
77898 + The users will only be able to execute binaries in directories owned and
77899 + writable only by the root user.
77900 +
77901 +config GRKERNSEC_SYMLINKOWN_GID
77902 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
77903 + depends on GRKERNSEC_CONFIG_SERVER
77904 + default 1006
77905 + help
77906 + Setting this GID determines what group kernel-enforced
77907 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
77908 + is enabled, a sysctl option with name "symlinkown_gid" is created.
77909 +
77910 +
77911 +endmenu
77912 +
77913 +menu "Customize Configuration"
77914 +depends on GRKERNSEC
77915 +
77916 +menu "PaX"
77917 +
77918 +config PAX
77919 + bool "Enable various PaX features"
77920 + default y if GRKERNSEC_CONFIG_AUTO
77921 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
77922 + help
77923 + This allows you to enable various PaX features. PaX adds
77924 + intrusion prevention mechanisms to the kernel that reduce
77925 + the risks posed by exploitable memory corruption bugs.
77926 +
77927 +menu "PaX Control"
77928 + depends on PAX
77929 +
77930 +config PAX_SOFTMODE
77931 + bool 'Support soft mode'
77932 + help
77933 + Enabling this option will allow you to run PaX in soft mode, that
77934 + is, PaX features will not be enforced by default, only on executables
77935 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
77936 + support as they are the only way to mark executables for soft mode use.
77937 +
77938 + Soft mode can be activated by using the "pax_softmode=1" kernel command
77939 + line option on boot. Furthermore you can control various PaX features
77940 + at runtime via the entries in /proc/sys/kernel/pax.
77941 +
77942 +config PAX_EI_PAX
77943 + bool 'Use legacy ELF header marking'
77944 + default y if GRKERNSEC_CONFIG_AUTO
77945 + help
77946 + Enabling this option will allow you to control PaX features on
77947 + a per executable basis via the 'chpax' utility available at
77948 + http://pax.grsecurity.net/. The control flags will be read from
77949 + an otherwise reserved part of the ELF header. This marking has
77950 + numerous drawbacks (no support for soft-mode, toolchain does not
77951 + know about the non-standard use of the ELF header) therefore it
77952 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
77953 + support.
77954 +
77955 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77956 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
77957 + option otherwise they will not get any protection.
77958 +
77959 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
77960 + support as well, they will override the legacy EI_PAX marks.
77961 +
77962 +config PAX_PT_PAX_FLAGS
77963 + bool 'Use ELF program header marking'
77964 + default y if GRKERNSEC_CONFIG_AUTO
77965 + help
77966 + Enabling this option will allow you to control PaX features on
77967 + a per executable basis via the 'paxctl' utility available at
77968 + http://pax.grsecurity.net/. The control flags will be read from
77969 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
77970 + has the benefits of supporting both soft mode and being fully
77971 + integrated into the toolchain (the binutils patch is available
77972 + from http://pax.grsecurity.net).
77973 +
77974 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77975 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77976 + support otherwise they will not get any protection.
77977 +
77978 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77979 + must make sure that the marks are the same if a binary has both marks.
77980 +
77981 + Note that if you enable the legacy EI_PAX marking support as well,
77982 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
77983 +
77984 +config PAX_XATTR_PAX_FLAGS
77985 + bool 'Use filesystem extended attributes marking'
77986 + default y if GRKERNSEC_CONFIG_AUTO
77987 + select CIFS_XATTR if CIFS
77988 + select EXT2_FS_XATTR if EXT2_FS
77989 + select EXT3_FS_XATTR if EXT3_FS
77990 + select EXT4_FS_XATTR if EXT4_FS
77991 + select JFFS2_FS_XATTR if JFFS2_FS
77992 + select REISERFS_FS_XATTR if REISERFS_FS
77993 + select SQUASHFS_XATTR if SQUASHFS
77994 + select TMPFS_XATTR if TMPFS
77995 + select UBIFS_FS_XATTR if UBIFS_FS
77996 + help
77997 + Enabling this option will allow you to control PaX features on
77998 + a per executable basis via the 'setfattr' utility. The control
77999 + flags will be read from the user.pax.flags extended attribute of
78000 + the file. This marking has the benefit of supporting binary-only
78001 + applications that self-check themselves (e.g., skype) and would
78002 + not tolerate chpax/paxctl changes. The main drawback is that
78003 + extended attributes are not supported by some filesystems (e.g.,
78004 + isofs, udf, vfat) so copying files through such filesystems will
78005 + lose the extended attributes and these PaX markings.
78006 +
78007 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78008 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78009 + support otherwise they will not get any protection.
78010 +
78011 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78012 + must make sure that the marks are the same if a binary has both marks.
78013 +
78014 + Note that if you enable the legacy EI_PAX marking support as well,
78015 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78016 +
78017 +choice
78018 + prompt 'MAC system integration'
78019 + default PAX_HAVE_ACL_FLAGS
78020 + help
78021 + Mandatory Access Control systems have the option of controlling
78022 + PaX flags on a per executable basis, choose the method supported
78023 + by your particular system.
78024 +
78025 + - "none": if your MAC system does not interact with PaX,
78026 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78027 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78028 +
78029 + NOTE: this option is for developers/integrators only.
78030 +
78031 + config PAX_NO_ACL_FLAGS
78032 + bool 'none'
78033 +
78034 + config PAX_HAVE_ACL_FLAGS
78035 + bool 'direct'
78036 +
78037 + config PAX_HOOK_ACL_FLAGS
78038 + bool 'hook'
78039 +endchoice
78040 +
78041 +endmenu
78042 +
78043 +menu "Non-executable pages"
78044 + depends on PAX
78045 +
78046 +config PAX_NOEXEC
78047 + bool "Enforce non-executable pages"
78048 + default y if GRKERNSEC_CONFIG_AUTO
78049 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78050 + help
78051 + By design some architectures do not allow for protecting memory
78052 + pages against execution or even if they do, Linux does not make
78053 + use of this feature. In practice this means that if a page is
78054 + readable (such as the stack or heap) it is also executable.
78055 +
78056 + There is a well known exploit technique that makes use of this
78057 + fact and a common programming mistake where an attacker can
78058 + introduce code of his choice somewhere in the attacked program's
78059 + memory (typically the stack or the heap) and then execute it.
78060 +
78061 + If the attacked program was running with different (typically
78062 + higher) privileges than that of the attacker, then he can elevate
78063 + his own privilege level (e.g. get a root shell, write to files for
78064 + which he does not have write access to, etc).
78065 +
78066 + Enabling this option will let you choose from various features
78067 + that prevent the injection and execution of 'foreign' code in
78068 + a program.
78069 +
78070 + This will also break programs that rely on the old behaviour and
78071 + expect that dynamically allocated memory via the malloc() family
78072 + of functions is executable (which it is not). Notable examples
78073 + are the XFree86 4.x server, the java runtime and wine.
78074 +
78075 +config PAX_PAGEEXEC
78076 + bool "Paging based non-executable pages"
78077 + default y if GRKERNSEC_CONFIG_AUTO
78078 + 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)
78079 + select S390_SWITCH_AMODE if S390
78080 + select S390_EXEC_PROTECT if S390
78081 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78082 + help
78083 + This implementation is based on the paging feature of the CPU.
78084 + On i386 without hardware non-executable bit support there is a
78085 + variable but usually low performance impact, however on Intel's
78086 + P4 core based CPUs it is very high so you should not enable this
78087 + for kernels meant to be used on such CPUs.
78088 +
78089 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78090 + with hardware non-executable bit support there is no performance
78091 + impact, on ppc the impact is negligible.
78092 +
78093 + Note that several architectures require various emulations due to
78094 + badly designed userland ABIs, this will cause a performance impact
78095 + but will disappear as soon as userland is fixed. For example, ppc
78096 + userland MUST have been built with secure-plt by a recent toolchain.
78097 +
78098 +config PAX_SEGMEXEC
78099 + bool "Segmentation based non-executable pages"
78100 + default y if GRKERNSEC_CONFIG_AUTO
78101 + depends on PAX_NOEXEC && X86_32
78102 + help
78103 + This implementation is based on the segmentation feature of the
78104 + CPU and has a very small performance impact, however applications
78105 + will be limited to a 1.5 GB address space instead of the normal
78106 + 3 GB.
78107 +
78108 +config PAX_EMUTRAMP
78109 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78110 + default y if PARISC
78111 + help
78112 + There are some programs and libraries that for one reason or
78113 + another attempt to execute special small code snippets from
78114 + non-executable memory pages. Most notable examples are the
78115 + signal handler return code generated by the kernel itself and
78116 + the GCC trampolines.
78117 +
78118 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78119 + such programs will no longer work under your kernel.
78120 +
78121 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78122 + utilities to enable trampoline emulation for the affected programs
78123 + yet still have the protection provided by the non-executable pages.
78124 +
78125 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78126 + your system will not even boot.
78127 +
78128 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78129 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78130 + for the affected files.
78131 +
78132 + NOTE: enabling this feature *may* open up a loophole in the
78133 + protection provided by non-executable pages that an attacker
78134 + could abuse. Therefore the best solution is to not have any
78135 + files on your system that would require this option. This can
78136 + be achieved by not using libc5 (which relies on the kernel
78137 + signal handler return code) and not using or rewriting programs
78138 + that make use of the nested function implementation of GCC.
78139 + Skilled users can just fix GCC itself so that it implements
78140 + nested function calls in a way that does not interfere with PaX.
78141 +
78142 +config PAX_EMUSIGRT
78143 + bool "Automatically emulate sigreturn trampolines"
78144 + depends on PAX_EMUTRAMP && PARISC
78145 + default y
78146 + help
78147 + Enabling this option will have the kernel automatically detect
78148 + and emulate signal return trampolines executing on the stack
78149 + that would otherwise lead to task termination.
78150 +
78151 + This solution is intended as a temporary one for users with
78152 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78153 + Modula-3 runtime, etc) or executables linked to such, basically
78154 + everything that does not specify its own SA_RESTORER function in
78155 + normal executable memory like glibc 2.1+ does.
78156 +
78157 + On parisc you MUST enable this option, otherwise your system will
78158 + not even boot.
78159 +
78160 + NOTE: this feature cannot be disabled on a per executable basis
78161 + and since it *does* open up a loophole in the protection provided
78162 + by non-executable pages, the best solution is to not have any
78163 + files on your system that would require this option.
78164 +
78165 +config PAX_MPROTECT
78166 + bool "Restrict mprotect()"
78167 + default y if GRKERNSEC_CONFIG_AUTO
78168 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78169 + help
78170 + Enabling this option will prevent programs from
78171 + - changing the executable status of memory pages that were
78172 + not originally created as executable,
78173 + - making read-only executable pages writable again,
78174 + - creating executable pages from anonymous memory,
78175 + - making read-only-after-relocations (RELRO) data pages writable again.
78176 +
78177 + You should say Y here to complete the protection provided by
78178 + the enforcement of non-executable pages.
78179 +
78180 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78181 + this feature on a per file basis.
78182 +
78183 +config PAX_MPROTECT_COMPAT
78184 + bool "Use legacy/compat protection demoting (read help)"
78185 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78186 + depends on PAX_MPROTECT
78187 + help
78188 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78189 + by sending the proper error code to the application. For some broken
78190 + userland, this can cause problems with Python or other applications. The
78191 + current implementation however allows for applications like clamav to
78192 + detect if JIT compilation/execution is allowed and to fall back gracefully
78193 + to an interpreter-based mode if it does not. While we encourage everyone
78194 + to use the current implementation as-is and push upstream to fix broken
78195 + userland (note that the RWX logging option can assist with this), in some
78196 + environments this may not be possible. Having to disable MPROTECT
78197 + completely on certain binaries reduces the security benefit of PaX,
78198 + so this option is provided for those environments to revert to the old
78199 + behavior.
78200 +
78201 +config PAX_ELFRELOCS
78202 + bool "Allow ELF text relocations (read help)"
78203 + depends on PAX_MPROTECT
78204 + default n
78205 + help
78206 + Non-executable pages and mprotect() restrictions are effective
78207 + in preventing the introduction of new executable code into an
78208 + attacked task's address space. There remain only two venues
78209 + for this kind of attack: if the attacker can execute already
78210 + existing code in the attacked task then he can either have it
78211 + create and mmap() a file containing his code or have it mmap()
78212 + an already existing ELF library that does not have position
78213 + independent code in it and use mprotect() on it to make it
78214 + writable and copy his code there. While protecting against
78215 + the former approach is beyond PaX, the latter can be prevented
78216 + by having only PIC ELF libraries on one's system (which do not
78217 + need to relocate their code). If you are sure this is your case,
78218 + as is the case with all modern Linux distributions, then leave
78219 + this option disabled. You should say 'n' here.
78220 +
78221 +config PAX_ETEXECRELOCS
78222 + bool "Allow ELF ET_EXEC text relocations"
78223 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78224 + select PAX_ELFRELOCS
78225 + default y
78226 + help
78227 + On some architectures there are incorrectly created applications
78228 + that require text relocations and would not work without enabling
78229 + this option. If you are an alpha, ia64 or parisc user, you should
78230 + enable this option and disable it once you have made sure that
78231 + none of your applications need it.
78232 +
78233 +config PAX_EMUPLT
78234 + bool "Automatically emulate ELF PLT"
78235 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78236 + default y
78237 + help
78238 + Enabling this option will have the kernel automatically detect
78239 + and emulate the Procedure Linkage Table entries in ELF files.
78240 + On some architectures such entries are in writable memory, and
78241 + become non-executable leading to task termination. Therefore
78242 + it is mandatory that you enable this option on alpha, parisc,
78243 + sparc and sparc64, otherwise your system would not even boot.
78244 +
78245 + NOTE: this feature *does* open up a loophole in the protection
78246 + provided by the non-executable pages, therefore the proper
78247 + solution is to modify the toolchain to produce a PLT that does
78248 + not need to be writable.
78249 +
78250 +config PAX_DLRESOLVE
78251 + bool 'Emulate old glibc resolver stub'
78252 + depends on PAX_EMUPLT && SPARC
78253 + default n
78254 + help
78255 + This option is needed if userland has an old glibc (before 2.4)
78256 + that puts a 'save' instruction into the runtime generated resolver
78257 + stub that needs special emulation.
78258 +
78259 +config PAX_KERNEXEC
78260 + bool "Enforce non-executable kernel pages"
78261 + default y if GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
78262 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
78263 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
78264 + select PAX_KERNEXEC_PLUGIN if X86_64
78265 + help
78266 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
78267 + that is, enabling this option will make it harder to inject
78268 + and execute 'foreign' code in kernel memory itself.
78269 +
78270 + Note that on x86_64 kernels there is a known regression when
78271 + this feature and KVM/VMX are both enabled in the host kernel.
78272 +
78273 +choice
78274 + prompt "Return Address Instrumentation Method"
78275 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
78276 + depends on PAX_KERNEXEC_PLUGIN
78277 + help
78278 + Select the method used to instrument function pointer dereferences.
78279 + Note that binary modules cannot be instrumented by this approach.
78280 +
78281 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
78282 + bool "bts"
78283 + help
78284 + This method is compatible with binary only modules but has
78285 + a higher runtime overhead.
78286 +
78287 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
78288 + bool "or"
78289 + depends on !PARAVIRT
78290 + help
78291 + This method is incompatible with binary only modules but has
78292 + a lower runtime overhead.
78293 +endchoice
78294 +
78295 +config PAX_KERNEXEC_PLUGIN_METHOD
78296 + string
78297 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
78298 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
78299 + default ""
78300 +
78301 +config PAX_KERNEXEC_MODULE_TEXT
78302 + int "Minimum amount of memory reserved for module code"
78303 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
78304 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78305 + depends on PAX_KERNEXEC && X86_32 && MODULES
78306 + help
78307 + Due to implementation details the kernel must reserve a fixed
78308 + amount of memory for module code at compile time that cannot be
78309 + changed at runtime. Here you can specify the minimum amount
78310 + in MB that will be reserved. Due to the same implementation
78311 + details this size will always be rounded up to the next 2/4 MB
78312 + boundary (depends on PAE) so the actually available memory for
78313 + module code will usually be more than this minimum.
78314 +
78315 + The default 4 MB should be enough for most users but if you have
78316 + an excessive number of modules (e.g., most distribution configs
78317 + compile many drivers as modules) or use huge modules such as
78318 + nvidia's kernel driver, you will need to adjust this amount.
78319 + A good rule of thumb is to look at your currently loaded kernel
78320 + modules and add up their sizes.
78321 +
78322 +endmenu
78323 +
78324 +menu "Address Space Layout Randomization"
78325 + depends on PAX
78326 +
78327 +config PAX_ASLR
78328 + bool "Address Space Layout Randomization"
78329 + default y if GRKERNSEC_CONFIG_AUTO
78330 + help
78331 + Many if not most exploit techniques rely on the knowledge of
78332 + certain addresses in the attacked program. The following options
78333 + will allow the kernel to apply a certain amount of randomization
78334 + to specific parts of the program thereby forcing an attacker to
78335 + guess them in most cases. Any failed guess will most likely crash
78336 + the attacked program which allows the kernel to detect such attempts
78337 + and react on them. PaX itself provides no reaction mechanisms,
78338 + instead it is strongly encouraged that you make use of Nergal's
78339 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
78340 + (http://www.grsecurity.net/) built-in crash detection features or
78341 + develop one yourself.
78342 +
78343 + By saying Y here you can choose to randomize the following areas:
78344 + - top of the task's kernel stack
78345 + - top of the task's userland stack
78346 + - base address for mmap() requests that do not specify one
78347 + (this includes all libraries)
78348 + - base address of the main executable
78349 +
78350 + It is strongly recommended to say Y here as address space layout
78351 + randomization has negligible impact on performance yet it provides
78352 + a very effective protection.
78353 +
78354 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78355 + this feature on a per file basis.
78356 +
78357 +config PAX_RANDKSTACK
78358 + bool "Randomize kernel stack base"
78359 + default y if GRKERNSEC_CONFIG_AUTO
78360 + depends on X86_TSC && X86
78361 + help
78362 + By saying Y here the kernel will randomize every task's kernel
78363 + stack on every system call. This will not only force an attacker
78364 + to guess it but also prevent him from making use of possible
78365 + leaked information about it.
78366 +
78367 + Since the kernel stack is a rather scarce resource, randomization
78368 + may cause unexpected stack overflows, therefore you should very
78369 + carefully test your system. Note that once enabled in the kernel
78370 + configuration, this feature cannot be disabled on a per file basis.
78371 +
78372 +config PAX_RANDUSTACK
78373 + bool "Randomize user stack base"
78374 + default y if GRKERNSEC_CONFIG_AUTO
78375 + depends on PAX_ASLR
78376 + help
78377 + By saying Y here the kernel will randomize every task's userland
78378 + stack. The randomization is done in two steps where the second
78379 + one may apply a big amount of shift to the top of the stack and
78380 + cause problems for programs that want to use lots of memory (more
78381 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
78382 + For this reason the second step can be controlled by 'chpax' or
78383 + 'paxctl' on a per file basis.
78384 +
78385 +config PAX_RANDMMAP
78386 + bool "Randomize mmap() base"
78387 + default y if GRKERNSEC_CONFIG_AUTO
78388 + depends on PAX_ASLR
78389 + help
78390 + By saying Y here the kernel will use a randomized base address for
78391 + mmap() requests that do not specify one themselves. As a result
78392 + all dynamically loaded libraries will appear at random addresses
78393 + and therefore be harder to exploit by a technique where an attacker
78394 + attempts to execute library code for his purposes (e.g. spawn a
78395 + shell from an exploited program that is running at an elevated
78396 + privilege level).
78397 +
78398 + Furthermore, if a program is relinked as a dynamic ELF file, its
78399 + base address will be randomized as well, completing the full
78400 + randomization of the address space layout. Attacking such programs
78401 + becomes a guess game. You can find an example of doing this at
78402 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
78403 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
78404 +
78405 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
78406 + feature on a per file basis.
78407 +
78408 +endmenu
78409 +
78410 +menu "Miscellaneous hardening features"
78411 +
78412 +config PAX_MEMORY_SANITIZE
78413 + bool "Sanitize all freed memory"
78414 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78415 + depends on !HIBERNATION
78416 + help
78417 + By saying Y here the kernel will erase memory pages as soon as they
78418 + are freed. This in turn reduces the lifetime of data stored in the
78419 + pages, making it less likely that sensitive information such as
78420 + passwords, cryptographic secrets, etc stay in memory for too long.
78421 +
78422 + This is especially useful for programs whose runtime is short, long
78423 + lived processes and the kernel itself benefit from this as long as
78424 + they operate on whole memory pages and ensure timely freeing of pages
78425 + that may hold sensitive information.
78426 +
78427 + The tradeoff is performance impact, on a single CPU system kernel
78428 + compilation sees a 3% slowdown, other systems and workloads may vary
78429 + and you are advised to test this feature on your expected workload
78430 + before deploying it.
78431 +
78432 + Note that this feature does not protect data stored in live pages,
78433 + e.g., process memory swapped to disk may stay there for a long time.
78434 +
78435 +config PAX_MEMORY_STACKLEAK
78436 + bool "Sanitize kernel stack"
78437 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78438 + depends on X86
78439 + help
78440 + By saying Y here the kernel will erase the kernel stack before it
78441 + returns from a system call. This in turn reduces the information
78442 + that a kernel stack leak bug can reveal.
78443 +
78444 + Note that such a bug can still leak information that was put on
78445 + the stack by the current system call (the one eventually triggering
78446 + the bug) but traces of earlier system calls on the kernel stack
78447 + cannot leak anymore.
78448 +
78449 + The tradeoff is performance impact: on a single CPU system kernel
78450 + compilation sees a 1% slowdown, other systems and workloads may vary
78451 + and you are advised to test this feature on your expected workload
78452 + before deploying it.
78453 +
78454 + Note: full support for this feature requires gcc with plugin support
78455 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
78456 + versions means that functions with large enough stack frames may
78457 + leave uninitialized memory behind that may be exposed to a later
78458 + syscall leaking the stack.
78459 +
78460 +config PAX_MEMORY_UDEREF
78461 + bool "Prevent invalid userland pointer dereference"
78462 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
78463 + depends on X86 && !UML_X86 && !XEN
78464 + select PAX_PER_CPU_PGD if X86_64
78465 + help
78466 + By saying Y here the kernel will be prevented from dereferencing
78467 + userland pointers in contexts where the kernel expects only kernel
78468 + pointers. This is both a useful runtime debugging feature and a
78469 + security measure that prevents exploiting a class of kernel bugs.
78470 +
78471 + The tradeoff is that some virtualization solutions may experience
78472 + a huge slowdown and therefore you should not enable this feature
78473 + for kernels meant to run in such environments. Whether a given VM
78474 + solution is affected or not is best determined by simply trying it
78475 + out, the performance impact will be obvious right on boot as this
78476 + mechanism engages from very early on. A good rule of thumb is that
78477 + VMs running on CPUs without hardware virtualization support (i.e.,
78478 + the majority of IA-32 CPUs) will likely experience the slowdown.
78479 +
78480 +config PAX_REFCOUNT
78481 + bool "Prevent various kernel object reference counter overflows"
78482 + default y if GRKERNSEC_CONFIG_AUTO
78483 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
78484 + help
78485 + By saying Y here the kernel will detect and prevent overflowing
78486 + various (but not all) kinds of object reference counters. Such
78487 + overflows can normally occur due to bugs only and are often, if
78488 + not always, exploitable.
78489 +
78490 + The tradeoff is that data structures protected by an overflowed
78491 + refcount will never be freed and therefore will leak memory. Note
78492 + that this leak also happens even without this protection but in
78493 + that case the overflow can eventually trigger the freeing of the
78494 + data structure while it is still being used elsewhere, resulting
78495 + in the exploitable situation that this feature prevents.
78496 +
78497 + Since this has a negligible performance impact, you should enable
78498 + this feature.
78499 +
78500 +config PAX_USERCOPY
78501 + bool "Harden heap object copies between kernel and userland"
78502 + default y if GRKERNSEC_CONFIG_AUTO
78503 + depends on X86 || PPC || SPARC || ARM
78504 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
78505 + help
78506 + By saying Y here the kernel will enforce the size of heap objects
78507 + when they are copied in either direction between the kernel and
78508 + userland, even if only a part of the heap object is copied.
78509 +
78510 + Specifically, this checking prevents information leaking from the
78511 + kernel heap during kernel to userland copies (if the kernel heap
78512 + object is otherwise fully initialized) and prevents kernel heap
78513 + overflows during userland to kernel copies.
78514 +
78515 + Note that the current implementation provides the strictest bounds
78516 + checks for the SLUB allocator.
78517 +
78518 + Enabling this option also enables per-slab cache protection against
78519 + data in a given cache being copied into/out of via userland
78520 + accessors. Though the whitelist of regions will be reduced over
78521 + time, it notably protects important data structures like task structs.
78522 +
78523 + If frame pointers are enabled on x86, this option will also restrict
78524 + copies into and out of the kernel stack to local variables within a
78525 + single frame.
78526 +
78527 + Since this has a negligible performance impact, you should enable
78528 + this feature.
78529 +
78530 +config PAX_SIZE_OVERFLOW
78531 + bool "Prevent various integer overflows in function size parameters"
78532 + default y if GRKERNSEC_CONFIG_AUTO
78533 + depends on X86
78534 + help
78535 + By saying Y here the kernel recomputes expressions of function
78536 + arguments marked by a size_overflow attribute with double integer
78537 + precision (DImode/TImode for 32/64 bit integer types).
78538 +
78539 + The recomputed argument is checked against INT_MAX and an event
78540 + is logged on overflow and the triggering process is killed.
78541 +
78542 + Homepage:
78543 + http://www.grsecurity.net/~ephox/overflow_plugin/
78544 +
78545 +endmenu
78546 +
78547 +endmenu
78548 +
78549 +source grsecurity/Kconfig
78550 +
78551 +endmenu
78552 +
78553 +endmenu
78554 +
78555 config KEYS
78556 bool "Enable access key retention support"
78557 help
78558 @@ -169,7 +1024,7 @@ config INTEL_TXT
78559 config LSM_MMAP_MIN_ADDR
78560 int "Low address space for LSM to protect from user allocation"
78561 depends on SECURITY && SECURITY_SELINUX
78562 - default 32768 if ARM
78563 + default 32768 if ALPHA || ARM || PARISC || SPARC32
78564 default 65536
78565 help
78566 This is the portion of low virtual memory which should be protected
78567 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
78568 index ad05d39..afffccb 100644
78569 --- a/security/apparmor/lsm.c
78570 +++ b/security/apparmor/lsm.c
78571 @@ -622,7 +622,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
78572 return error;
78573 }
78574
78575 -static struct security_operations apparmor_ops = {
78576 +static struct security_operations apparmor_ops __read_only = {
78577 .name = "apparmor",
78578
78579 .ptrace_access_check = apparmor_ptrace_access_check,
78580 diff --git a/security/commoncap.c b/security/commoncap.c
78581 index 71a166a..851bb3e 100644
78582 --- a/security/commoncap.c
78583 +++ b/security/commoncap.c
78584 @@ -576,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
78585 {
78586 const struct cred *cred = current_cred();
78587
78588 + if (gr_acl_enable_at_secure())
78589 + return 1;
78590 +
78591 if (cred->uid != 0) {
78592 if (bprm->cap_effective)
78593 return 1;
78594 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
78595 index 3ccf7ac..d73ad64 100644
78596 --- a/security/integrity/ima/ima.h
78597 +++ b/security/integrity/ima/ima.h
78598 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78599 extern spinlock_t ima_queue_lock;
78600
78601 struct ima_h_table {
78602 - atomic_long_t len; /* number of stored measurements in the list */
78603 - atomic_long_t violations;
78604 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
78605 + atomic_long_unchecked_t violations;
78606 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
78607 };
78608 extern struct ima_h_table ima_htable;
78609 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
78610 index 88a2788..581ab92 100644
78611 --- a/security/integrity/ima/ima_api.c
78612 +++ b/security/integrity/ima/ima_api.c
78613 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78614 int result;
78615
78616 /* can overflow, only indicator */
78617 - atomic_long_inc(&ima_htable.violations);
78618 + atomic_long_inc_unchecked(&ima_htable.violations);
78619
78620 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
78621 if (!entry) {
78622 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
78623 index e1aa2b4..52027bf 100644
78624 --- a/security/integrity/ima/ima_fs.c
78625 +++ b/security/integrity/ima/ima_fs.c
78626 @@ -28,12 +28,12 @@
78627 static int valid_policy = 1;
78628 #define TMPBUFLEN 12
78629 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
78630 - loff_t *ppos, atomic_long_t *val)
78631 + loff_t *ppos, atomic_long_unchecked_t *val)
78632 {
78633 char tmpbuf[TMPBUFLEN];
78634 ssize_t len;
78635
78636 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
78637 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
78638 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
78639 }
78640
78641 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
78642 index 55a6271..ad829c3 100644
78643 --- a/security/integrity/ima/ima_queue.c
78644 +++ b/security/integrity/ima/ima_queue.c
78645 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78646 INIT_LIST_HEAD(&qe->later);
78647 list_add_tail_rcu(&qe->later, &ima_measurements);
78648
78649 - atomic_long_inc(&ima_htable.len);
78650 + atomic_long_inc_unchecked(&ima_htable.len);
78651 key = ima_hash_key(entry->digest);
78652 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78653 return 0;
78654 diff --git a/security/keys/compat.c b/security/keys/compat.c
78655 index 4c48e13..7abdac9 100644
78656 --- a/security/keys/compat.c
78657 +++ b/security/keys/compat.c
78658 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78659 if (ret == 0)
78660 goto no_payload_free;
78661
78662 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78663 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78664
78665 if (iov != iovstack)
78666 kfree(iov);
78667 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78668 index fb767c6..b9c49c0 100644
78669 --- a/security/keys/keyctl.c
78670 +++ b/security/keys/keyctl.c
78671 @@ -935,7 +935,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78672 /*
78673 * Copy the iovec data from userspace
78674 */
78675 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78676 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78677 unsigned ioc)
78678 {
78679 for (; ioc > 0; ioc--) {
78680 @@ -957,7 +957,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78681 * If successful, 0 will be returned.
78682 */
78683 long keyctl_instantiate_key_common(key_serial_t id,
78684 - const struct iovec *payload_iov,
78685 + const struct iovec __user *payload_iov,
78686 unsigned ioc,
78687 size_t plen,
78688 key_serial_t ringid)
78689 @@ -1052,7 +1052,7 @@ long keyctl_instantiate_key(key_serial_t id,
78690 [0].iov_len = plen
78691 };
78692
78693 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
78694 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
78695 }
78696
78697 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
78698 @@ -1085,7 +1085,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
78699 if (ret == 0)
78700 goto no_payload_free;
78701
78702 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78703 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78704
78705 if (iov != iovstack)
78706 kfree(iov);
78707 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
78708 index d605f75..2bc6be9 100644
78709 --- a/security/keys/keyring.c
78710 +++ b/security/keys/keyring.c
78711 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
78712 ret = -EFAULT;
78713
78714 for (loop = 0; loop < klist->nkeys; loop++) {
78715 + key_serial_t serial;
78716 key = klist->keys[loop];
78717 + serial = key->serial;
78718
78719 tmp = sizeof(key_serial_t);
78720 if (tmp > buflen)
78721 tmp = buflen;
78722
78723 - if (copy_to_user(buffer,
78724 - &key->serial,
78725 - tmp) != 0)
78726 + if (copy_to_user(buffer, &serial, tmp))
78727 goto error;
78728
78729 buflen -= tmp;
78730 diff --git a/security/min_addr.c b/security/min_addr.c
78731 index f728728..6457a0c 100644
78732 --- a/security/min_addr.c
78733 +++ b/security/min_addr.c
78734 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
78735 */
78736 static void update_mmap_min_addr(void)
78737 {
78738 +#ifndef SPARC
78739 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
78740 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
78741 mmap_min_addr = dac_mmap_min_addr;
78742 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
78743 #else
78744 mmap_min_addr = dac_mmap_min_addr;
78745 #endif
78746 +#endif
78747 }
78748
78749 /*
78750 diff --git a/security/security.c b/security/security.c
78751 index bf619ff..8179030 100644
78752 --- a/security/security.c
78753 +++ b/security/security.c
78754 @@ -20,6 +20,7 @@
78755 #include <linux/ima.h>
78756 #include <linux/evm.h>
78757 #include <linux/fsnotify.h>
78758 +#include <linux/mm.h>
78759 #include <net/flow.h>
78760
78761 #define MAX_LSM_EVM_XATTR 2
78762 @@ -28,8 +29,8 @@
78763 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
78764 CONFIG_DEFAULT_SECURITY;
78765
78766 -static struct security_operations *security_ops;
78767 -static struct security_operations default_security_ops = {
78768 +static struct security_operations *security_ops __read_only;
78769 +static struct security_operations default_security_ops __read_only = {
78770 .name = "default",
78771 };
78772
78773 @@ -70,7 +71,9 @@ int __init security_init(void)
78774
78775 void reset_security_ops(void)
78776 {
78777 + pax_open_kernel();
78778 security_ops = &default_security_ops;
78779 + pax_close_kernel();
78780 }
78781
78782 /* Save user chosen LSM */
78783 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
78784 index d85b793..a164832 100644
78785 --- a/security/selinux/hooks.c
78786 +++ b/security/selinux/hooks.c
78787 @@ -95,8 +95,6 @@
78788
78789 #define NUM_SEL_MNT_OPTS 5
78790
78791 -extern struct security_operations *security_ops;
78792 -
78793 /* SECMARK reference count */
78794 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
78795
78796 @@ -5520,7 +5518,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
78797
78798 #endif
78799
78800 -static struct security_operations selinux_ops = {
78801 +static struct security_operations selinux_ops __read_only = {
78802 .name = "selinux",
78803
78804 .ptrace_access_check = selinux_ptrace_access_check,
78805 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
78806 index c220f31..89fab3f 100644
78807 --- a/security/selinux/include/xfrm.h
78808 +++ b/security/selinux/include/xfrm.h
78809 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
78810
78811 static inline void selinux_xfrm_notify_policyload(void)
78812 {
78813 - atomic_inc(&flow_cache_genid);
78814 + atomic_inc_unchecked(&flow_cache_genid);
78815 }
78816 #else
78817 static inline int selinux_xfrm_enabled(void)
78818 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
78819 index 45c32f0..0038be2 100644
78820 --- a/security/smack/smack_lsm.c
78821 +++ b/security/smack/smack_lsm.c
78822 @@ -3500,7 +3500,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
78823 return 0;
78824 }
78825
78826 -struct security_operations smack_ops = {
78827 +struct security_operations smack_ops __read_only = {
78828 .name = "smack",
78829
78830 .ptrace_access_check = smack_ptrace_access_check,
78831 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
78832 index 620d37c..e2ad89b 100644
78833 --- a/security/tomoyo/tomoyo.c
78834 +++ b/security/tomoyo/tomoyo.c
78835 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
78836 * tomoyo_security_ops is a "struct security_operations" which is used for
78837 * registering TOMOYO.
78838 */
78839 -static struct security_operations tomoyo_security_ops = {
78840 +static struct security_operations tomoyo_security_ops __read_only = {
78841 .name = "tomoyo",
78842 .cred_alloc_blank = tomoyo_cred_alloc_blank,
78843 .cred_prepare = tomoyo_cred_prepare,
78844 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
78845 index 51d6709..1f3dbe2 100644
78846 --- a/security/yama/Kconfig
78847 +++ b/security/yama/Kconfig
78848 @@ -1,6 +1,6 @@
78849 config SECURITY_YAMA
78850 bool "Yama support"
78851 - depends on SECURITY
78852 + depends on SECURITY && !GRKERNSEC
78853 select SECURITYFS
78854 select SECURITY_PATH
78855 default n
78856 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
78857 index 270790d..c67dfcb 100644
78858 --- a/sound/aoa/codecs/onyx.c
78859 +++ b/sound/aoa/codecs/onyx.c
78860 @@ -54,7 +54,7 @@ struct onyx {
78861 spdif_locked:1,
78862 analog_locked:1,
78863 original_mute:2;
78864 - int open_count;
78865 + local_t open_count;
78866 struct codec_info *codec_info;
78867
78868 /* mutex serializes concurrent access to the device
78869 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
78870 struct onyx *onyx = cii->codec_data;
78871
78872 mutex_lock(&onyx->mutex);
78873 - onyx->open_count++;
78874 + local_inc(&onyx->open_count);
78875 mutex_unlock(&onyx->mutex);
78876
78877 return 0;
78878 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
78879 struct onyx *onyx = cii->codec_data;
78880
78881 mutex_lock(&onyx->mutex);
78882 - onyx->open_count--;
78883 - if (!onyx->open_count)
78884 + if (local_dec_and_test(&onyx->open_count))
78885 onyx->spdif_locked = onyx->analog_locked = 0;
78886 mutex_unlock(&onyx->mutex);
78887
78888 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
78889 index ffd2025..df062c9 100644
78890 --- a/sound/aoa/codecs/onyx.h
78891 +++ b/sound/aoa/codecs/onyx.h
78892 @@ -11,6 +11,7 @@
78893 #include <linux/i2c.h>
78894 #include <asm/pmac_low_i2c.h>
78895 #include <asm/prom.h>
78896 +#include <asm/local.h>
78897
78898 /* PCM3052 register definitions */
78899
78900 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
78901 index 08fde00..0bf641a 100644
78902 --- a/sound/core/oss/pcm_oss.c
78903 +++ b/sound/core/oss/pcm_oss.c
78904 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
78905 if (in_kernel) {
78906 mm_segment_t fs;
78907 fs = snd_enter_user();
78908 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78909 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78910 snd_leave_user(fs);
78911 } else {
78912 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78913 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78914 }
78915 if (ret != -EPIPE && ret != -ESTRPIPE)
78916 break;
78917 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
78918 if (in_kernel) {
78919 mm_segment_t fs;
78920 fs = snd_enter_user();
78921 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78922 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78923 snd_leave_user(fs);
78924 } else {
78925 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78926 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78927 }
78928 if (ret == -EPIPE) {
78929 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
78930 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
78931 struct snd_pcm_plugin_channel *channels;
78932 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
78933 if (!in_kernel) {
78934 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
78935 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
78936 return -EFAULT;
78937 buf = runtime->oss.buffer;
78938 }
78939 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
78940 }
78941 } else {
78942 tmp = snd_pcm_oss_write2(substream,
78943 - (const char __force *)buf,
78944 + (const char __force_kernel *)buf,
78945 runtime->oss.period_bytes, 0);
78946 if (tmp <= 0)
78947 goto err;
78948 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
78949 struct snd_pcm_runtime *runtime = substream->runtime;
78950 snd_pcm_sframes_t frames, frames1;
78951 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
78952 - char __user *final_dst = (char __force __user *)buf;
78953 + char __user *final_dst = (char __force_user *)buf;
78954 if (runtime->oss.plugin_first) {
78955 struct snd_pcm_plugin_channel *channels;
78956 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
78957 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
78958 xfer += tmp;
78959 runtime->oss.buffer_used -= tmp;
78960 } else {
78961 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
78962 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
78963 runtime->oss.period_bytes, 0);
78964 if (tmp <= 0)
78965 goto err;
78966 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
78967 size1);
78968 size1 /= runtime->channels; /* frames */
78969 fs = snd_enter_user();
78970 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
78971 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
78972 snd_leave_user(fs);
78973 }
78974 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
78975 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
78976 index 91cdf94..4085161 100644
78977 --- a/sound/core/pcm_compat.c
78978 +++ b/sound/core/pcm_compat.c
78979 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
78980 int err;
78981
78982 fs = snd_enter_user();
78983 - err = snd_pcm_delay(substream, &delay);
78984 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
78985 snd_leave_user(fs);
78986 if (err < 0)
78987 return err;
78988 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
78989 index 3fe99e6..26952e4 100644
78990 --- a/sound/core/pcm_native.c
78991 +++ b/sound/core/pcm_native.c
78992 @@ -2770,11 +2770,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
78993 switch (substream->stream) {
78994 case SNDRV_PCM_STREAM_PLAYBACK:
78995 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
78996 - (void __user *)arg);
78997 + (void __force_user *)arg);
78998 break;
78999 case SNDRV_PCM_STREAM_CAPTURE:
79000 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79001 - (void __user *)arg);
79002 + (void __force_user *)arg);
79003 break;
79004 default:
79005 result = -EINVAL;
79006 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79007 index 5cf8d65..912a79c 100644
79008 --- a/sound/core/seq/seq_device.c
79009 +++ b/sound/core/seq/seq_device.c
79010 @@ -64,7 +64,7 @@ struct ops_list {
79011 int argsize; /* argument size */
79012
79013 /* operators */
79014 - struct snd_seq_dev_ops ops;
79015 + struct snd_seq_dev_ops *ops;
79016
79017 /* registred devices */
79018 struct list_head dev_list; /* list of devices */
79019 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79020
79021 mutex_lock(&ops->reg_mutex);
79022 /* copy driver operators */
79023 - ops->ops = *entry;
79024 + ops->ops = entry;
79025 ops->driver |= DRIVER_LOADED;
79026 ops->argsize = argsize;
79027
79028 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79029 dev->name, ops->id, ops->argsize, dev->argsize);
79030 return -EINVAL;
79031 }
79032 - if (ops->ops.init_device(dev) >= 0) {
79033 + if (ops->ops->init_device(dev) >= 0) {
79034 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79035 ops->num_init_devices++;
79036 } else {
79037 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79038 dev->name, ops->id, ops->argsize, dev->argsize);
79039 return -EINVAL;
79040 }
79041 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79042 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79043 dev->status = SNDRV_SEQ_DEVICE_FREE;
79044 dev->driver_data = NULL;
79045 ops->num_init_devices--;
79046 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79047 index 621e60e..f4543f5 100644
79048 --- a/sound/drivers/mts64.c
79049 +++ b/sound/drivers/mts64.c
79050 @@ -29,6 +29,7 @@
79051 #include <sound/initval.h>
79052 #include <sound/rawmidi.h>
79053 #include <sound/control.h>
79054 +#include <asm/local.h>
79055
79056 #define CARD_NAME "Miditerminal 4140"
79057 #define DRIVER_NAME "MTS64"
79058 @@ -67,7 +68,7 @@ struct mts64 {
79059 struct pardevice *pardev;
79060 int pardev_claimed;
79061
79062 - int open_count;
79063 + local_t open_count;
79064 int current_midi_output_port;
79065 int current_midi_input_port;
79066 u8 mode[MTS64_NUM_INPUT_PORTS];
79067 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79068 {
79069 struct mts64 *mts = substream->rmidi->private_data;
79070
79071 - if (mts->open_count == 0) {
79072 + if (local_read(&mts->open_count) == 0) {
79073 /* We don't need a spinlock here, because this is just called
79074 if the device has not been opened before.
79075 So there aren't any IRQs from the device */
79076 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79077
79078 msleep(50);
79079 }
79080 - ++(mts->open_count);
79081 + local_inc(&mts->open_count);
79082
79083 return 0;
79084 }
79085 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79086 struct mts64 *mts = substream->rmidi->private_data;
79087 unsigned long flags;
79088
79089 - --(mts->open_count);
79090 - if (mts->open_count == 0) {
79091 + if (local_dec_return(&mts->open_count) == 0) {
79092 /* We need the spinlock_irqsave here because we can still
79093 have IRQs at this point */
79094 spin_lock_irqsave(&mts->lock, flags);
79095 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79096
79097 msleep(500);
79098
79099 - } else if (mts->open_count < 0)
79100 - mts->open_count = 0;
79101 + } else if (local_read(&mts->open_count) < 0)
79102 + local_set(&mts->open_count, 0);
79103
79104 return 0;
79105 }
79106 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79107 index b953fb4..1999c01 100644
79108 --- a/sound/drivers/opl4/opl4_lib.c
79109 +++ b/sound/drivers/opl4/opl4_lib.c
79110 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79111 MODULE_DESCRIPTION("OPL4 driver");
79112 MODULE_LICENSE("GPL");
79113
79114 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79115 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79116 {
79117 int timeout = 10;
79118 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79119 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79120 index 3e32bd3..46fc152 100644
79121 --- a/sound/drivers/portman2x4.c
79122 +++ b/sound/drivers/portman2x4.c
79123 @@ -48,6 +48,7 @@
79124 #include <sound/initval.h>
79125 #include <sound/rawmidi.h>
79126 #include <sound/control.h>
79127 +#include <asm/local.h>
79128
79129 #define CARD_NAME "Portman 2x4"
79130 #define DRIVER_NAME "portman"
79131 @@ -85,7 +86,7 @@ struct portman {
79132 struct pardevice *pardev;
79133 int pardev_claimed;
79134
79135 - int open_count;
79136 + local_t open_count;
79137 int mode[PORTMAN_NUM_INPUT_PORTS];
79138 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79139 };
79140 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79141 index 87657dd..a8268d4 100644
79142 --- a/sound/firewire/amdtp.c
79143 +++ b/sound/firewire/amdtp.c
79144 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79145 ptr = s->pcm_buffer_pointer + data_blocks;
79146 if (ptr >= pcm->runtime->buffer_size)
79147 ptr -= pcm->runtime->buffer_size;
79148 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79149 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79150
79151 s->pcm_period_pointer += data_blocks;
79152 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79153 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79154 */
79155 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79156 {
79157 - ACCESS_ONCE(s->source_node_id_field) =
79158 + ACCESS_ONCE_RW(s->source_node_id_field) =
79159 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79160 }
79161 EXPORT_SYMBOL(amdtp_out_stream_update);
79162 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79163 index 537a9cb..8e8c8e9 100644
79164 --- a/sound/firewire/amdtp.h
79165 +++ b/sound/firewire/amdtp.h
79166 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79167 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79168 struct snd_pcm_substream *pcm)
79169 {
79170 - ACCESS_ONCE(s->pcm) = pcm;
79171 + ACCESS_ONCE_RW(s->pcm) = pcm;
79172 }
79173
79174 /**
79175 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79176 index d428ffe..751ef78 100644
79177 --- a/sound/firewire/isight.c
79178 +++ b/sound/firewire/isight.c
79179 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79180 ptr += count;
79181 if (ptr >= runtime->buffer_size)
79182 ptr -= runtime->buffer_size;
79183 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79184 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79185
79186 isight->period_counter += count;
79187 if (isight->period_counter >= runtime->period_size) {
79188 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79189 if (err < 0)
79190 return err;
79191
79192 - ACCESS_ONCE(isight->pcm_active) = true;
79193 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79194
79195 return 0;
79196 }
79197 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79198 {
79199 struct isight *isight = substream->private_data;
79200
79201 - ACCESS_ONCE(isight->pcm_active) = false;
79202 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79203
79204 mutex_lock(&isight->mutex);
79205 isight_stop_streaming(isight);
79206 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79207
79208 switch (cmd) {
79209 case SNDRV_PCM_TRIGGER_START:
79210 - ACCESS_ONCE(isight->pcm_running) = true;
79211 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79212 break;
79213 case SNDRV_PCM_TRIGGER_STOP:
79214 - ACCESS_ONCE(isight->pcm_running) = false;
79215 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79216 break;
79217 default:
79218 return -EINVAL;
79219 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79220 index 7bd5e33..1fcab12 100644
79221 --- a/sound/isa/cmi8330.c
79222 +++ b/sound/isa/cmi8330.c
79223 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79224
79225 struct snd_pcm *pcm;
79226 struct snd_cmi8330_stream {
79227 - struct snd_pcm_ops ops;
79228 + snd_pcm_ops_no_const ops;
79229 snd_pcm_open_callback_t open;
79230 void *private_data; /* sb or wss */
79231 } streams[2];
79232 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79233 index 733b014..56ce96f 100644
79234 --- a/sound/oss/sb_audio.c
79235 +++ b/sound/oss/sb_audio.c
79236 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79237 buf16 = (signed short *)(localbuf + localoffs);
79238 while (c)
79239 {
79240 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79241 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79242 if (copy_from_user(lbuf8,
79243 userbuf+useroffs + p,
79244 locallen))
79245 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79246 index 09d4648..cf234c7 100644
79247 --- a/sound/oss/swarm_cs4297a.c
79248 +++ b/sound/oss/swarm_cs4297a.c
79249 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79250 {
79251 struct cs4297a_state *s;
79252 u32 pwr, id;
79253 - mm_segment_t fs;
79254 int rval;
79255 #ifndef CONFIG_BCM_CS4297A_CSWARM
79256 u64 cfg;
79257 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79258 if (!rval) {
79259 char *sb1250_duart_present;
79260
79261 +#if 0
79262 + mm_segment_t fs;
79263 fs = get_fs();
79264 set_fs(KERNEL_DS);
79265 -#if 0
79266 val = SOUND_MASK_LINE;
79267 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79268 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79269 val = initvol[i].vol;
79270 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79271 }
79272 + set_fs(fs);
79273 // cs4297a_write_ac97(s, 0x18, 0x0808);
79274 #else
79275 // cs4297a_write_ac97(s, 0x5e, 0x180);
79276 cs4297a_write_ac97(s, 0x02, 0x0808);
79277 cs4297a_write_ac97(s, 0x18, 0x0808);
79278 #endif
79279 - set_fs(fs);
79280
79281 list_add(&s->list, &cs4297a_devs);
79282
79283 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
79284 index 56b4f74..7cfd41a 100644
79285 --- a/sound/pci/hda/hda_codec.h
79286 +++ b/sound/pci/hda/hda_codec.h
79287 @@ -611,7 +611,7 @@ struct hda_bus_ops {
79288 /* notify power-up/down from codec to controller */
79289 void (*pm_notify)(struct hda_bus *bus);
79290 #endif
79291 -};
79292 +} __no_const;
79293
79294 /* template to pass to the bus constructor */
79295 struct hda_bus_template {
79296 @@ -713,6 +713,7 @@ struct hda_codec_ops {
79297 #endif
79298 void (*reboot_notify)(struct hda_codec *codec);
79299 };
79300 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
79301
79302 /* record for amp information cache */
79303 struct hda_cache_head {
79304 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
79305 struct snd_pcm_substream *substream);
79306 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
79307 struct snd_pcm_substream *substream);
79308 -};
79309 +} __no_const;
79310
79311 /* PCM information for each substream */
79312 struct hda_pcm_stream {
79313 @@ -801,7 +802,7 @@ struct hda_codec {
79314 const char *modelname; /* model name for preset */
79315
79316 /* set by patch */
79317 - struct hda_codec_ops patch_ops;
79318 + hda_codec_ops_no_const patch_ops;
79319
79320 /* PCM to create, set by patch_ops.build_pcms callback */
79321 unsigned int num_pcms;
79322 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
79323 index 0da778a..bc38b84 100644
79324 --- a/sound/pci/ice1712/ice1712.h
79325 +++ b/sound/pci/ice1712/ice1712.h
79326 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
79327 unsigned int mask_flags; /* total mask bits */
79328 struct snd_akm4xxx_ops {
79329 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
79330 - } ops;
79331 + } __no_const ops;
79332 };
79333
79334 struct snd_ice1712_spdif {
79335 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
79336 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79337 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79338 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79339 - } ops;
79340 + } __no_const ops;
79341 };
79342
79343
79344 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
79345 index a8159b81..5f006a5 100644
79346 --- a/sound/pci/ymfpci/ymfpci_main.c
79347 +++ b/sound/pci/ymfpci/ymfpci_main.c
79348 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
79349 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
79350 break;
79351 }
79352 - if (atomic_read(&chip->interrupt_sleep_count)) {
79353 - atomic_set(&chip->interrupt_sleep_count, 0);
79354 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79355 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79356 wake_up(&chip->interrupt_sleep);
79357 }
79358 __end:
79359 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
79360 continue;
79361 init_waitqueue_entry(&wait, current);
79362 add_wait_queue(&chip->interrupt_sleep, &wait);
79363 - atomic_inc(&chip->interrupt_sleep_count);
79364 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
79365 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
79366 remove_wait_queue(&chip->interrupt_sleep, &wait);
79367 }
79368 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
79369 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
79370 spin_unlock(&chip->reg_lock);
79371
79372 - if (atomic_read(&chip->interrupt_sleep_count)) {
79373 - atomic_set(&chip->interrupt_sleep_count, 0);
79374 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79375 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79376 wake_up(&chip->interrupt_sleep);
79377 }
79378 }
79379 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
79380 spin_lock_init(&chip->reg_lock);
79381 spin_lock_init(&chip->voice_lock);
79382 init_waitqueue_head(&chip->interrupt_sleep);
79383 - atomic_set(&chip->interrupt_sleep_count, 0);
79384 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79385 chip->card = card;
79386 chip->pci = pci;
79387 chip->irq = -1;
79388 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
79389 index 0ad8dca..7186339 100644
79390 --- a/sound/soc/soc-pcm.c
79391 +++ b/sound/soc/soc-pcm.c
79392 @@ -641,7 +641,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
79393 struct snd_soc_platform *platform = rtd->platform;
79394 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79395 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79396 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
79397 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
79398 struct snd_pcm *pcm;
79399 char new_name[64];
79400 int ret = 0, playback = 0, capture = 0;
79401 diff --git a/sound/usb/card.h b/sound/usb/card.h
79402 index da5fa1a..113cd02 100644
79403 --- a/sound/usb/card.h
79404 +++ b/sound/usb/card.h
79405 @@ -45,6 +45,7 @@ struct snd_urb_ops {
79406 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79407 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79408 };
79409 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
79410
79411 struct snd_usb_substream {
79412 struct snd_usb_stream *stream;
79413 @@ -94,7 +95,7 @@ struct snd_usb_substream {
79414 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
79415 spinlock_t lock;
79416
79417 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
79418 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
79419 int last_frame_number; /* stored frame number */
79420 int last_delay; /* stored delay */
79421 };
79422 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
79423 new file mode 100644
79424 index 0000000..f4f9986
79425 --- /dev/null
79426 +++ b/tools/gcc/Makefile
79427 @@ -0,0 +1,41 @@
79428 +#CC := gcc
79429 +#PLUGIN_SOURCE_FILES := pax_plugin.c
79430 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
79431 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
79432 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
79433 +
79434 +ifeq ($(PLUGINCC),$(HOSTCC))
79435 +HOSTLIBS := hostlibs
79436 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
79437 +else
79438 +HOSTLIBS := hostcxxlibs
79439 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
79440 +endif
79441 +
79442 +$(HOSTLIBS)-y := constify_plugin.so
79443 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
79444 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
79445 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
79446 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
79447 +$(HOSTLIBS)-y += colorize_plugin.so
79448 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
79449 +
79450 +always := $($(HOSTLIBS)-y)
79451 +
79452 +constify_plugin-objs := constify_plugin.o
79453 +stackleak_plugin-objs := stackleak_plugin.o
79454 +kallocstat_plugin-objs := kallocstat_plugin.o
79455 +kernexec_plugin-objs := kernexec_plugin.o
79456 +checker_plugin-objs := checker_plugin.o
79457 +colorize_plugin-objs := colorize_plugin.o
79458 +size_overflow_plugin-objs := size_overflow_plugin.o
79459 +
79460 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
79461 +
79462 +quiet_cmd_build_size_overflow_hash = GENHASH $@
79463 + cmd_build_size_overflow_hash = \
79464 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
79465 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
79466 + $(call if_changed,build_size_overflow_hash)
79467 +
79468 +targets += size_overflow_hash.h
79469 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
79470 new file mode 100644
79471 index 0000000..d41b5af
79472 --- /dev/null
79473 +++ b/tools/gcc/checker_plugin.c
79474 @@ -0,0 +1,171 @@
79475 +/*
79476 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79477 + * Licensed under the GPL v2
79478 + *
79479 + * Note: the choice of the license means that the compilation process is
79480 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79481 + * but for the kernel it doesn't matter since it doesn't link against
79482 + * any of the gcc libraries
79483 + *
79484 + * gcc plugin to implement various sparse (source code checker) features
79485 + *
79486 + * TODO:
79487 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
79488 + *
79489 + * BUGS:
79490 + * - none known
79491 + */
79492 +#include "gcc-plugin.h"
79493 +#include "config.h"
79494 +#include "system.h"
79495 +#include "coretypes.h"
79496 +#include "tree.h"
79497 +#include "tree-pass.h"
79498 +#include "flags.h"
79499 +#include "intl.h"
79500 +#include "toplev.h"
79501 +#include "plugin.h"
79502 +//#include "expr.h" where are you...
79503 +#include "diagnostic.h"
79504 +#include "plugin-version.h"
79505 +#include "tm.h"
79506 +#include "function.h"
79507 +#include "basic-block.h"
79508 +#include "gimple.h"
79509 +#include "rtl.h"
79510 +#include "emit-rtl.h"
79511 +#include "tree-flow.h"
79512 +#include "target.h"
79513 +
79514 +extern void c_register_addr_space (const char *str, addr_space_t as);
79515 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
79516 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
79517 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
79518 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
79519 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
79520 +
79521 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79522 +extern rtx emit_move_insn(rtx x, rtx y);
79523 +
79524 +int plugin_is_GPL_compatible;
79525 +
79526 +static struct plugin_info checker_plugin_info = {
79527 + .version = "201111150100",
79528 +};
79529 +
79530 +#define ADDR_SPACE_KERNEL 0
79531 +#define ADDR_SPACE_FORCE_KERNEL 1
79532 +#define ADDR_SPACE_USER 2
79533 +#define ADDR_SPACE_FORCE_USER 3
79534 +#define ADDR_SPACE_IOMEM 0
79535 +#define ADDR_SPACE_FORCE_IOMEM 0
79536 +#define ADDR_SPACE_PERCPU 0
79537 +#define ADDR_SPACE_FORCE_PERCPU 0
79538 +#define ADDR_SPACE_RCU 0
79539 +#define ADDR_SPACE_FORCE_RCU 0
79540 +
79541 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
79542 +{
79543 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
79544 +}
79545 +
79546 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
79547 +{
79548 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
79549 +}
79550 +
79551 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
79552 +{
79553 + return default_addr_space_valid_pointer_mode(mode, as);
79554 +}
79555 +
79556 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
79557 +{
79558 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
79559 +}
79560 +
79561 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
79562 +{
79563 + return default_addr_space_legitimize_address(x, oldx, mode, as);
79564 +}
79565 +
79566 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
79567 +{
79568 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
79569 + return true;
79570 +
79571 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
79572 + return true;
79573 +
79574 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
79575 + return true;
79576 +
79577 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
79578 + return true;
79579 +
79580 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
79581 + return true;
79582 +
79583 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
79584 + return true;
79585 +
79586 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
79587 + return true;
79588 +
79589 + return subset == superset;
79590 +}
79591 +
79592 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
79593 +{
79594 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
79595 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
79596 +
79597 + return op;
79598 +}
79599 +
79600 +static void register_checker_address_spaces(void *event_data, void *data)
79601 +{
79602 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
79603 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
79604 + c_register_addr_space("__user", ADDR_SPACE_USER);
79605 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
79606 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
79607 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
79608 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
79609 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
79610 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
79611 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
79612 +
79613 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
79614 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
79615 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
79616 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
79617 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
79618 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
79619 + targetm.addr_space.convert = checker_addr_space_convert;
79620 +}
79621 +
79622 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79623 +{
79624 + const char * const plugin_name = plugin_info->base_name;
79625 + const int argc = plugin_info->argc;
79626 + const struct plugin_argument * const argv = plugin_info->argv;
79627 + int i;
79628 +
79629 + if (!plugin_default_version_check(version, &gcc_version)) {
79630 + error(G_("incompatible gcc/plugin versions"));
79631 + return 1;
79632 + }
79633 +
79634 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
79635 +
79636 + for (i = 0; i < argc; ++i)
79637 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79638 +
79639 + if (TARGET_64BIT == 0)
79640 + return 0;
79641 +
79642 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
79643 +
79644 + return 0;
79645 +}
79646 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
79647 new file mode 100644
79648 index 0000000..7a5e311
79649 --- /dev/null
79650 +++ b/tools/gcc/colorize_plugin.c
79651 @@ -0,0 +1,148 @@
79652 +/*
79653 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
79654 + * Licensed under the GPL v2
79655 + *
79656 + * Note: the choice of the license means that the compilation process is
79657 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79658 + * but for the kernel it doesn't matter since it doesn't link against
79659 + * any of the gcc libraries
79660 + *
79661 + * gcc plugin to colorize diagnostic output
79662 + *
79663 + */
79664 +
79665 +#include "gcc-plugin.h"
79666 +#include "config.h"
79667 +#include "system.h"
79668 +#include "coretypes.h"
79669 +#include "tree.h"
79670 +#include "tree-pass.h"
79671 +#include "flags.h"
79672 +#include "intl.h"
79673 +#include "toplev.h"
79674 +#include "plugin.h"
79675 +#include "diagnostic.h"
79676 +#include "plugin-version.h"
79677 +#include "tm.h"
79678 +
79679 +int plugin_is_GPL_compatible;
79680 +
79681 +static struct plugin_info colorize_plugin_info = {
79682 + .version = "201203092200",
79683 + .help = NULL,
79684 +};
79685 +
79686 +#define GREEN "\033[32m\033[2m"
79687 +#define LIGHTGREEN "\033[32m\033[1m"
79688 +#define YELLOW "\033[33m\033[2m"
79689 +#define LIGHTYELLOW "\033[33m\033[1m"
79690 +#define RED "\033[31m\033[2m"
79691 +#define LIGHTRED "\033[31m\033[1m"
79692 +#define BLUE "\033[34m\033[2m"
79693 +#define LIGHTBLUE "\033[34m\033[1m"
79694 +#define BRIGHT "\033[m\033[1m"
79695 +#define NORMAL "\033[m"
79696 +
79697 +static diagnostic_starter_fn old_starter;
79698 +static diagnostic_finalizer_fn old_finalizer;
79699 +
79700 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79701 +{
79702 + const char *color;
79703 + char *newprefix;
79704 +
79705 + switch (diagnostic->kind) {
79706 + case DK_NOTE:
79707 + color = LIGHTBLUE;
79708 + break;
79709 +
79710 + case DK_PEDWARN:
79711 + case DK_WARNING:
79712 + color = LIGHTYELLOW;
79713 + break;
79714 +
79715 + case DK_ERROR:
79716 + case DK_FATAL:
79717 + case DK_ICE:
79718 + case DK_PERMERROR:
79719 + case DK_SORRY:
79720 + color = LIGHTRED;
79721 + break;
79722 +
79723 + default:
79724 + color = NORMAL;
79725 + }
79726 +
79727 + old_starter(context, diagnostic);
79728 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
79729 + return;
79730 + pp_destroy_prefix(context->printer);
79731 + pp_set_prefix(context->printer, newprefix);
79732 +}
79733 +
79734 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79735 +{
79736 + old_finalizer(context, diagnostic);
79737 +}
79738 +
79739 +static void colorize_arm(void)
79740 +{
79741 + old_starter = diagnostic_starter(global_dc);
79742 + old_finalizer = diagnostic_finalizer(global_dc);
79743 +
79744 + diagnostic_starter(global_dc) = start_colorize;
79745 + diagnostic_finalizer(global_dc) = finalize_colorize;
79746 +}
79747 +
79748 +static unsigned int execute_colorize_rearm(void)
79749 +{
79750 + if (diagnostic_starter(global_dc) == start_colorize)
79751 + return 0;
79752 +
79753 + colorize_arm();
79754 + return 0;
79755 +}
79756 +
79757 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
79758 + .pass = {
79759 + .type = SIMPLE_IPA_PASS,
79760 + .name = "colorize_rearm",
79761 + .gate = NULL,
79762 + .execute = execute_colorize_rearm,
79763 + .sub = NULL,
79764 + .next = NULL,
79765 + .static_pass_number = 0,
79766 + .tv_id = TV_NONE,
79767 + .properties_required = 0,
79768 + .properties_provided = 0,
79769 + .properties_destroyed = 0,
79770 + .todo_flags_start = 0,
79771 + .todo_flags_finish = 0
79772 + }
79773 +};
79774 +
79775 +static void colorize_start_unit(void *gcc_data, void *user_data)
79776 +{
79777 + colorize_arm();
79778 +}
79779 +
79780 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79781 +{
79782 + const char * const plugin_name = plugin_info->base_name;
79783 + struct register_pass_info colorize_rearm_pass_info = {
79784 + .pass = &pass_ipa_colorize_rearm.pass,
79785 + .reference_pass_name = "*free_lang_data",
79786 + .ref_pass_instance_number = 0,
79787 + .pos_op = PASS_POS_INSERT_AFTER
79788 + };
79789 +
79790 + if (!plugin_default_version_check(version, &gcc_version)) {
79791 + error(G_("incompatible gcc/plugin versions"));
79792 + return 1;
79793 + }
79794 +
79795 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
79796 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
79797 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
79798 + return 0;
79799 +}
79800 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
79801 new file mode 100644
79802 index 0000000..89b7f56
79803 --- /dev/null
79804 +++ b/tools/gcc/constify_plugin.c
79805 @@ -0,0 +1,328 @@
79806 +/*
79807 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
79808 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
79809 + * Licensed under the GPL v2, or (at your option) v3
79810 + *
79811 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
79812 + *
79813 + * Homepage:
79814 + * http://www.grsecurity.net/~ephox/const_plugin/
79815 + *
79816 + * Usage:
79817 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
79818 + * $ gcc -fplugin=constify_plugin.so test.c -O2
79819 + */
79820 +
79821 +#include "gcc-plugin.h"
79822 +#include "config.h"
79823 +#include "system.h"
79824 +#include "coretypes.h"
79825 +#include "tree.h"
79826 +#include "tree-pass.h"
79827 +#include "flags.h"
79828 +#include "intl.h"
79829 +#include "toplev.h"
79830 +#include "plugin.h"
79831 +#include "diagnostic.h"
79832 +#include "plugin-version.h"
79833 +#include "tm.h"
79834 +#include "function.h"
79835 +#include "basic-block.h"
79836 +#include "gimple.h"
79837 +#include "rtl.h"
79838 +#include "emit-rtl.h"
79839 +#include "tree-flow.h"
79840 +
79841 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
79842 +
79843 +int plugin_is_GPL_compatible;
79844 +
79845 +static struct plugin_info const_plugin_info = {
79846 + .version = "201205300030",
79847 + .help = "no-constify\tturn off constification\n",
79848 +};
79849 +
79850 +static void deconstify_tree(tree node);
79851 +
79852 +static void deconstify_type(tree type)
79853 +{
79854 + tree field;
79855 +
79856 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
79857 + tree type = TREE_TYPE(field);
79858 +
79859 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
79860 + continue;
79861 + if (!TYPE_READONLY(type))
79862 + continue;
79863 +
79864 + deconstify_tree(field);
79865 + }
79866 + TYPE_READONLY(type) = 0;
79867 + C_TYPE_FIELDS_READONLY(type) = 0;
79868 +}
79869 +
79870 +static void deconstify_tree(tree node)
79871 +{
79872 + tree old_type, new_type, field;
79873 +
79874 + old_type = TREE_TYPE(node);
79875 +
79876 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
79877 +
79878 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
79879 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
79880 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
79881 + DECL_FIELD_CONTEXT(field) = new_type;
79882 +
79883 + deconstify_type(new_type);
79884 +
79885 + TREE_READONLY(node) = 0;
79886 + TREE_TYPE(node) = new_type;
79887 +}
79888 +
79889 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79890 +{
79891 + tree type;
79892 +
79893 + *no_add_attrs = true;
79894 + if (TREE_CODE(*node) == FUNCTION_DECL) {
79895 + error("%qE attribute does not apply to functions", name);
79896 + return NULL_TREE;
79897 + }
79898 +
79899 + if (TREE_CODE(*node) == VAR_DECL) {
79900 + error("%qE attribute does not apply to variables", name);
79901 + return NULL_TREE;
79902 + }
79903 +
79904 + if (TYPE_P(*node)) {
79905 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
79906 + *no_add_attrs = false;
79907 + else
79908 + error("%qE attribute applies to struct and union types only", name);
79909 + return NULL_TREE;
79910 + }
79911 +
79912 + type = TREE_TYPE(*node);
79913 +
79914 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
79915 + error("%qE attribute applies to struct and union types only", name);
79916 + return NULL_TREE;
79917 + }
79918 +
79919 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
79920 + error("%qE attribute is already applied to the type", name);
79921 + return NULL_TREE;
79922 + }
79923 +
79924 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
79925 + error("%qE attribute used on type that is not constified", name);
79926 + return NULL_TREE;
79927 + }
79928 +
79929 + if (TREE_CODE(*node) == TYPE_DECL) {
79930 + deconstify_tree(*node);
79931 + return NULL_TREE;
79932 + }
79933 +
79934 + return NULL_TREE;
79935 +}
79936 +
79937 +static void constify_type(tree type)
79938 +{
79939 + TYPE_READONLY(type) = 1;
79940 + C_TYPE_FIELDS_READONLY(type) = 1;
79941 +}
79942 +
79943 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79944 +{
79945 + *no_add_attrs = true;
79946 + if (!TYPE_P(*node)) {
79947 + error("%qE attribute applies to types only", name);
79948 + return NULL_TREE;
79949 + }
79950 +
79951 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
79952 + error("%qE attribute applies to struct and union types only", name);
79953 + return NULL_TREE;
79954 + }
79955 +
79956 + *no_add_attrs = false;
79957 + constify_type(*node);
79958 + return NULL_TREE;
79959 +}
79960 +
79961 +static struct attribute_spec no_const_attr = {
79962 + .name = "no_const",
79963 + .min_length = 0,
79964 + .max_length = 0,
79965 + .decl_required = false,
79966 + .type_required = false,
79967 + .function_type_required = false,
79968 + .handler = handle_no_const_attribute,
79969 +#if BUILDING_GCC_VERSION >= 4007
79970 + .affects_type_identity = true
79971 +#endif
79972 +};
79973 +
79974 +static struct attribute_spec do_const_attr = {
79975 + .name = "do_const",
79976 + .min_length = 0,
79977 + .max_length = 0,
79978 + .decl_required = false,
79979 + .type_required = false,
79980 + .function_type_required = false,
79981 + .handler = handle_do_const_attribute,
79982 +#if BUILDING_GCC_VERSION >= 4007
79983 + .affects_type_identity = true
79984 +#endif
79985 +};
79986 +
79987 +static void register_attributes(void *event_data, void *data)
79988 +{
79989 + register_attribute(&no_const_attr);
79990 + register_attribute(&do_const_attr);
79991 +}
79992 +
79993 +static bool is_fptr(tree field)
79994 +{
79995 + tree ptr = TREE_TYPE(field);
79996 +
79997 + if (TREE_CODE(ptr) != POINTER_TYPE)
79998 + return false;
79999 +
80000 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80001 +}
80002 +
80003 +static bool walk_struct(tree node)
80004 +{
80005 + tree field;
80006 +
80007 + if (TYPE_FIELDS(node) == NULL_TREE)
80008 + return false;
80009 +
80010 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
80011 + gcc_assert(!TYPE_READONLY(node));
80012 + deconstify_type(node);
80013 + return false;
80014 + }
80015 +
80016 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80017 + tree type = TREE_TYPE(field);
80018 + enum tree_code code = TREE_CODE(type);
80019 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80020 + if (!(walk_struct(type)))
80021 + return false;
80022 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80023 + return false;
80024 + }
80025 + return true;
80026 +}
80027 +
80028 +static void finish_type(void *event_data, void *data)
80029 +{
80030 + tree type = (tree)event_data;
80031 +
80032 + if (type == NULL_TREE)
80033 + return;
80034 +
80035 + if (TYPE_READONLY(type))
80036 + return;
80037 +
80038 + if (walk_struct(type))
80039 + constify_type(type);
80040 +}
80041 +
80042 +static unsigned int check_local_variables(void);
80043 +
80044 +struct gimple_opt_pass pass_local_variable = {
80045 + {
80046 + .type = GIMPLE_PASS,
80047 + .name = "check_local_variables",
80048 + .gate = NULL,
80049 + .execute = check_local_variables,
80050 + .sub = NULL,
80051 + .next = NULL,
80052 + .static_pass_number = 0,
80053 + .tv_id = TV_NONE,
80054 + .properties_required = 0,
80055 + .properties_provided = 0,
80056 + .properties_destroyed = 0,
80057 + .todo_flags_start = 0,
80058 + .todo_flags_finish = 0
80059 + }
80060 +};
80061 +
80062 +static unsigned int check_local_variables(void)
80063 +{
80064 + tree var;
80065 + referenced_var_iterator rvi;
80066 +
80067 +#if BUILDING_GCC_VERSION == 4005
80068 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80069 +#else
80070 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80071 +#endif
80072 + tree type = TREE_TYPE(var);
80073 +
80074 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80075 + continue;
80076 +
80077 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80078 + continue;
80079 +
80080 + if (!TYPE_READONLY(type))
80081 + continue;
80082 +
80083 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80084 +// continue;
80085 +
80086 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80087 +// continue;
80088 +
80089 + if (walk_struct(type)) {
80090 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
80091 + return 1;
80092 + }
80093 + }
80094 + return 0;
80095 +}
80096 +
80097 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80098 +{
80099 + const char * const plugin_name = plugin_info->base_name;
80100 + const int argc = plugin_info->argc;
80101 + const struct plugin_argument * const argv = plugin_info->argv;
80102 + int i;
80103 + bool constify = true;
80104 +
80105 + struct register_pass_info local_variable_pass_info = {
80106 + .pass = &pass_local_variable.pass,
80107 + .reference_pass_name = "*referenced_vars",
80108 + .ref_pass_instance_number = 0,
80109 + .pos_op = PASS_POS_INSERT_AFTER
80110 + };
80111 +
80112 + if (!plugin_default_version_check(version, &gcc_version)) {
80113 + error(G_("incompatible gcc/plugin versions"));
80114 + return 1;
80115 + }
80116 +
80117 + for (i = 0; i < argc; ++i) {
80118 + if (!(strcmp(argv[i].key, "no-constify"))) {
80119 + constify = false;
80120 + continue;
80121 + }
80122 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80123 + }
80124 +
80125 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80126 + if (constify) {
80127 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80128 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80129 + }
80130 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80131 +
80132 + return 0;
80133 +}
80134 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
80135 new file mode 100644
80136 index 0000000..a0fe8b2
80137 --- /dev/null
80138 +++ b/tools/gcc/generate_size_overflow_hash.sh
80139 @@ -0,0 +1,94 @@
80140 +#!/bin/bash
80141 +
80142 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
80143 +
80144 +header1="size_overflow_hash.h"
80145 +database="size_overflow_hash.data"
80146 +n=65536
80147 +
80148 +usage() {
80149 +cat <<EOF
80150 +usage: $0 options
80151 +OPTIONS:
80152 + -h|--help help
80153 + -o header file
80154 + -d database file
80155 + -n hash array size
80156 +EOF
80157 + return 0
80158 +}
80159 +
80160 +while true
80161 +do
80162 + case "$1" in
80163 + -h|--help) usage && exit 0;;
80164 + -n) n=$2; shift 2;;
80165 + -o) header1="$2"; shift 2;;
80166 + -d) database="$2"; shift 2;;
80167 + --) shift 1; break ;;
80168 + *) break ;;
80169 + esac
80170 +done
80171 +
80172 +create_defines() {
80173 + for i in `seq 1 10`
80174 + do
80175 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
80176 + done
80177 + echo >> "$header1"
80178 +}
80179 +
80180 +create_structs () {
80181 + rm -f "$header1"
80182 +
80183 + create_defines
80184 +
80185 + cat "$database" | while read data
80186 + do
80187 + data_array=($data)
80188 + struct_hash_name="${data_array[0]}"
80189 + funcn="${data_array[1]}"
80190 + params="${data_array[2]}"
80191 + next="${data_array[5]}"
80192 +
80193 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
80194 +
80195 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
80196 + echo -en "\t.param\t= " >> "$header1"
80197 + line=
80198 + for param_num in ${params//-/ };
80199 + do
80200 + line="${line}PARAM"$param_num"|"
80201 + done
80202 +
80203 + echo -e "${line%?},\n};\n" >> "$header1"
80204 + done
80205 +}
80206 +
80207 +create_headers () {
80208 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
80209 +}
80210 +
80211 +create_array_elements () {
80212 + index=0
80213 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
80214 + do
80215 + data_array=($data)
80216 + i="${data_array[3]}"
80217 + hash="${data_array[4]}"
80218 + while [[ $index -lt $i ]]
80219 + do
80220 + echo -e "\t["$index"]\t= NULL," >> "$header1"
80221 + index=$(($index + 1))
80222 + done
80223 + index=$(($index + 1))
80224 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
80225 + done
80226 + echo '};' >> $header1
80227 +}
80228 +
80229 +create_structs
80230 +create_headers
80231 +create_array_elements
80232 +
80233 +exit 0
80234 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80235 new file mode 100644
80236 index 0000000..a5eabce
80237 --- /dev/null
80238 +++ b/tools/gcc/kallocstat_plugin.c
80239 @@ -0,0 +1,167 @@
80240 +/*
80241 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80242 + * Licensed under the GPL v2
80243 + *
80244 + * Note: the choice of the license means that the compilation process is
80245 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80246 + * but for the kernel it doesn't matter since it doesn't link against
80247 + * any of the gcc libraries
80248 + *
80249 + * gcc plugin to find the distribution of k*alloc sizes
80250 + *
80251 + * TODO:
80252 + *
80253 + * BUGS:
80254 + * - none known
80255 + */
80256 +#include "gcc-plugin.h"
80257 +#include "config.h"
80258 +#include "system.h"
80259 +#include "coretypes.h"
80260 +#include "tree.h"
80261 +#include "tree-pass.h"
80262 +#include "flags.h"
80263 +#include "intl.h"
80264 +#include "toplev.h"
80265 +#include "plugin.h"
80266 +//#include "expr.h" where are you...
80267 +#include "diagnostic.h"
80268 +#include "plugin-version.h"
80269 +#include "tm.h"
80270 +#include "function.h"
80271 +#include "basic-block.h"
80272 +#include "gimple.h"
80273 +#include "rtl.h"
80274 +#include "emit-rtl.h"
80275 +
80276 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80277 +
80278 +int plugin_is_GPL_compatible;
80279 +
80280 +static const char * const kalloc_functions[] = {
80281 + "__kmalloc",
80282 + "kmalloc",
80283 + "kmalloc_large",
80284 + "kmalloc_node",
80285 + "kmalloc_order",
80286 + "kmalloc_order_trace",
80287 + "kmalloc_slab",
80288 + "kzalloc",
80289 + "kzalloc_node",
80290 +};
80291 +
80292 +static struct plugin_info kallocstat_plugin_info = {
80293 + .version = "201111150100",
80294 +};
80295 +
80296 +static unsigned int execute_kallocstat(void);
80297 +
80298 +static struct gimple_opt_pass kallocstat_pass = {
80299 + .pass = {
80300 + .type = GIMPLE_PASS,
80301 + .name = "kallocstat",
80302 + .gate = NULL,
80303 + .execute = execute_kallocstat,
80304 + .sub = NULL,
80305 + .next = NULL,
80306 + .static_pass_number = 0,
80307 + .tv_id = TV_NONE,
80308 + .properties_required = 0,
80309 + .properties_provided = 0,
80310 + .properties_destroyed = 0,
80311 + .todo_flags_start = 0,
80312 + .todo_flags_finish = 0
80313 + }
80314 +};
80315 +
80316 +static bool is_kalloc(const char *fnname)
80317 +{
80318 + size_t i;
80319 +
80320 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80321 + if (!strcmp(fnname, kalloc_functions[i]))
80322 + return true;
80323 + return false;
80324 +}
80325 +
80326 +static unsigned int execute_kallocstat(void)
80327 +{
80328 + basic_block bb;
80329 +
80330 + // 1. loop through BBs and GIMPLE statements
80331 + FOR_EACH_BB(bb) {
80332 + gimple_stmt_iterator gsi;
80333 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80334 + // gimple match:
80335 + tree fndecl, size;
80336 + gimple call_stmt;
80337 + const char *fnname;
80338 +
80339 + // is it a call
80340 + call_stmt = gsi_stmt(gsi);
80341 + if (!is_gimple_call(call_stmt))
80342 + continue;
80343 + fndecl = gimple_call_fndecl(call_stmt);
80344 + if (fndecl == NULL_TREE)
80345 + continue;
80346 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80347 + continue;
80348 +
80349 + // is it a call to k*alloc
80350 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80351 + if (!is_kalloc(fnname))
80352 + continue;
80353 +
80354 + // is the size arg the result of a simple const assignment
80355 + size = gimple_call_arg(call_stmt, 0);
80356 + while (true) {
80357 + gimple def_stmt;
80358 + expanded_location xloc;
80359 + size_t size_val;
80360 +
80361 + if (TREE_CODE(size) != SSA_NAME)
80362 + break;
80363 + def_stmt = SSA_NAME_DEF_STMT(size);
80364 + if (!def_stmt || !is_gimple_assign(def_stmt))
80365 + break;
80366 + if (gimple_num_ops(def_stmt) != 2)
80367 + break;
80368 + size = gimple_assign_rhs1(def_stmt);
80369 + if (!TREE_CONSTANT(size))
80370 + continue;
80371 + xloc = expand_location(gimple_location(def_stmt));
80372 + if (!xloc.file)
80373 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80374 + size_val = TREE_INT_CST_LOW(size);
80375 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80376 + break;
80377 + }
80378 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80379 +//debug_tree(gimple_call_fn(call_stmt));
80380 +//print_node(stderr, "pax", fndecl, 4);
80381 + }
80382 + }
80383 +
80384 + return 0;
80385 +}
80386 +
80387 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80388 +{
80389 + const char * const plugin_name = plugin_info->base_name;
80390 + struct register_pass_info kallocstat_pass_info = {
80391 + .pass = &kallocstat_pass.pass,
80392 + .reference_pass_name = "ssa",
80393 + .ref_pass_instance_number = 0,
80394 + .pos_op = PASS_POS_INSERT_AFTER
80395 + };
80396 +
80397 + if (!plugin_default_version_check(version, &gcc_version)) {
80398 + error(G_("incompatible gcc/plugin versions"));
80399 + return 1;
80400 + }
80401 +
80402 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80403 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80404 +
80405 + return 0;
80406 +}
80407 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80408 new file mode 100644
80409 index 0000000..d8a8da2
80410 --- /dev/null
80411 +++ b/tools/gcc/kernexec_plugin.c
80412 @@ -0,0 +1,427 @@
80413 +/*
80414 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80415 + * Licensed under the GPL v2
80416 + *
80417 + * Note: the choice of the license means that the compilation process is
80418 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80419 + * but for the kernel it doesn't matter since it doesn't link against
80420 + * any of the gcc libraries
80421 + *
80422 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
80423 + *
80424 + * TODO:
80425 + *
80426 + * BUGS:
80427 + * - none known
80428 + */
80429 +#include "gcc-plugin.h"
80430 +#include "config.h"
80431 +#include "system.h"
80432 +#include "coretypes.h"
80433 +#include "tree.h"
80434 +#include "tree-pass.h"
80435 +#include "flags.h"
80436 +#include "intl.h"
80437 +#include "toplev.h"
80438 +#include "plugin.h"
80439 +//#include "expr.h" where are you...
80440 +#include "diagnostic.h"
80441 +#include "plugin-version.h"
80442 +#include "tm.h"
80443 +#include "function.h"
80444 +#include "basic-block.h"
80445 +#include "gimple.h"
80446 +#include "rtl.h"
80447 +#include "emit-rtl.h"
80448 +#include "tree-flow.h"
80449 +
80450 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80451 +extern rtx emit_move_insn(rtx x, rtx y);
80452 +
80453 +int plugin_is_GPL_compatible;
80454 +
80455 +static struct plugin_info kernexec_plugin_info = {
80456 + .version = "201111291120",
80457 + .help = "method=[bts|or]\tinstrumentation method\n"
80458 +};
80459 +
80460 +static unsigned int execute_kernexec_reload(void);
80461 +static unsigned int execute_kernexec_fptr(void);
80462 +static unsigned int execute_kernexec_retaddr(void);
80463 +static bool kernexec_cmodel_check(void);
80464 +
80465 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
80466 +static void (*kernexec_instrument_retaddr)(rtx);
80467 +
80468 +static struct gimple_opt_pass kernexec_reload_pass = {
80469 + .pass = {
80470 + .type = GIMPLE_PASS,
80471 + .name = "kernexec_reload",
80472 + .gate = kernexec_cmodel_check,
80473 + .execute = execute_kernexec_reload,
80474 + .sub = NULL,
80475 + .next = NULL,
80476 + .static_pass_number = 0,
80477 + .tv_id = TV_NONE,
80478 + .properties_required = 0,
80479 + .properties_provided = 0,
80480 + .properties_destroyed = 0,
80481 + .todo_flags_start = 0,
80482 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80483 + }
80484 +};
80485 +
80486 +static struct gimple_opt_pass kernexec_fptr_pass = {
80487 + .pass = {
80488 + .type = GIMPLE_PASS,
80489 + .name = "kernexec_fptr",
80490 + .gate = kernexec_cmodel_check,
80491 + .execute = execute_kernexec_fptr,
80492 + .sub = NULL,
80493 + .next = NULL,
80494 + .static_pass_number = 0,
80495 + .tv_id = TV_NONE,
80496 + .properties_required = 0,
80497 + .properties_provided = 0,
80498 + .properties_destroyed = 0,
80499 + .todo_flags_start = 0,
80500 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80501 + }
80502 +};
80503 +
80504 +static struct rtl_opt_pass kernexec_retaddr_pass = {
80505 + .pass = {
80506 + .type = RTL_PASS,
80507 + .name = "kernexec_retaddr",
80508 + .gate = kernexec_cmodel_check,
80509 + .execute = execute_kernexec_retaddr,
80510 + .sub = NULL,
80511 + .next = NULL,
80512 + .static_pass_number = 0,
80513 + .tv_id = TV_NONE,
80514 + .properties_required = 0,
80515 + .properties_provided = 0,
80516 + .properties_destroyed = 0,
80517 + .todo_flags_start = 0,
80518 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
80519 + }
80520 +};
80521 +
80522 +static bool kernexec_cmodel_check(void)
80523 +{
80524 + tree section;
80525 +
80526 + if (ix86_cmodel != CM_KERNEL)
80527 + return false;
80528 +
80529 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
80530 + if (!section || !TREE_VALUE(section))
80531 + return true;
80532 +
80533 + section = TREE_VALUE(TREE_VALUE(section));
80534 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
80535 + return true;
80536 +
80537 + return false;
80538 +}
80539 +
80540 +/*
80541 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
80542 + */
80543 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
80544 +{
80545 + gimple asm_movabs_stmt;
80546 +
80547 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
80548 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
80549 + gimple_asm_set_volatile(asm_movabs_stmt, true);
80550 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
80551 + update_stmt(asm_movabs_stmt);
80552 +}
80553 +
80554 +/*
80555 + * find all asm() stmts that clobber r10 and add a reload of r10
80556 + */
80557 +static unsigned int execute_kernexec_reload(void)
80558 +{
80559 + basic_block bb;
80560 +
80561 + // 1. loop through BBs and GIMPLE statements
80562 + FOR_EACH_BB(bb) {
80563 + gimple_stmt_iterator gsi;
80564 +
80565 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80566 + // gimple match: __asm__ ("" : : : "r10");
80567 + gimple asm_stmt;
80568 + size_t nclobbers;
80569 +
80570 + // is it an asm ...
80571 + asm_stmt = gsi_stmt(gsi);
80572 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
80573 + continue;
80574 +
80575 + // ... clobbering r10
80576 + nclobbers = gimple_asm_nclobbers(asm_stmt);
80577 + while (nclobbers--) {
80578 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
80579 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
80580 + continue;
80581 + kernexec_reload_fptr_mask(&gsi);
80582 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
80583 + break;
80584 + }
80585 + }
80586 + }
80587 +
80588 + return 0;
80589 +}
80590 +
80591 +/*
80592 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
80593 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
80594 + */
80595 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
80596 +{
80597 + gimple assign_intptr, assign_new_fptr, call_stmt;
80598 + tree intptr, old_fptr, new_fptr, kernexec_mask;
80599 +
80600 + call_stmt = gsi_stmt(*gsi);
80601 + old_fptr = gimple_call_fn(call_stmt);
80602 +
80603 + // create temporary unsigned long variable used for bitops and cast fptr to it
80604 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
80605 + add_referenced_var(intptr);
80606 + mark_sym_for_renaming(intptr);
80607 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
80608 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80609 + update_stmt(assign_intptr);
80610 +
80611 + // apply logical or to temporary unsigned long and bitmask
80612 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
80613 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
80614 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
80615 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80616 + update_stmt(assign_intptr);
80617 +
80618 + // cast temporary unsigned long back to a temporary fptr variable
80619 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
80620 + add_referenced_var(new_fptr);
80621 + mark_sym_for_renaming(new_fptr);
80622 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
80623 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
80624 + update_stmt(assign_new_fptr);
80625 +
80626 + // replace call stmt fn with the new fptr
80627 + gimple_call_set_fn(call_stmt, new_fptr);
80628 + update_stmt(call_stmt);
80629 +}
80630 +
80631 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
80632 +{
80633 + gimple asm_or_stmt, call_stmt;
80634 + tree old_fptr, new_fptr, input, output;
80635 + VEC(tree, gc) *inputs = NULL;
80636 + VEC(tree, gc) *outputs = NULL;
80637 +
80638 + call_stmt = gsi_stmt(*gsi);
80639 + old_fptr = gimple_call_fn(call_stmt);
80640 +
80641 + // create temporary fptr variable
80642 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
80643 + add_referenced_var(new_fptr);
80644 + mark_sym_for_renaming(new_fptr);
80645 +
80646 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
80647 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
80648 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
80649 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
80650 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
80651 + VEC_safe_push(tree, gc, inputs, input);
80652 + VEC_safe_push(tree, gc, outputs, output);
80653 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
80654 + gimple_asm_set_volatile(asm_or_stmt, true);
80655 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
80656 + update_stmt(asm_or_stmt);
80657 +
80658 + // replace call stmt fn with the new fptr
80659 + gimple_call_set_fn(call_stmt, new_fptr);
80660 + update_stmt(call_stmt);
80661 +}
80662 +
80663 +/*
80664 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
80665 + */
80666 +static unsigned int execute_kernexec_fptr(void)
80667 +{
80668 + basic_block bb;
80669 +
80670 + // 1. loop through BBs and GIMPLE statements
80671 + FOR_EACH_BB(bb) {
80672 + gimple_stmt_iterator gsi;
80673 +
80674 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80675 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
80676 + tree fn;
80677 + gimple call_stmt;
80678 +
80679 + // is it a call ...
80680 + call_stmt = gsi_stmt(gsi);
80681 + if (!is_gimple_call(call_stmt))
80682 + continue;
80683 + fn = gimple_call_fn(call_stmt);
80684 + if (TREE_CODE(fn) == ADDR_EXPR)
80685 + continue;
80686 + if (TREE_CODE(fn) != SSA_NAME)
80687 + gcc_unreachable();
80688 +
80689 + // ... through a function pointer
80690 + fn = SSA_NAME_VAR(fn);
80691 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
80692 + continue;
80693 + fn = TREE_TYPE(fn);
80694 + if (TREE_CODE(fn) != POINTER_TYPE)
80695 + continue;
80696 + fn = TREE_TYPE(fn);
80697 + if (TREE_CODE(fn) != FUNCTION_TYPE)
80698 + continue;
80699 +
80700 + kernexec_instrument_fptr(&gsi);
80701 +
80702 +//debug_tree(gimple_call_fn(call_stmt));
80703 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80704 + }
80705 + }
80706 +
80707 + return 0;
80708 +}
80709 +
80710 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
80711 +static void kernexec_instrument_retaddr_bts(rtx insn)
80712 +{
80713 + rtx btsq;
80714 + rtvec argvec, constraintvec, labelvec;
80715 + int line;
80716 +
80717 + // create asm volatile("btsq $63,(%%rsp)":::)
80718 + argvec = rtvec_alloc(0);
80719 + constraintvec = rtvec_alloc(0);
80720 + labelvec = rtvec_alloc(0);
80721 + line = expand_location(RTL_LOCATION(insn)).line;
80722 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80723 + MEM_VOLATILE_P(btsq) = 1;
80724 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
80725 + emit_insn_before(btsq, insn);
80726 +}
80727 +
80728 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
80729 +static void kernexec_instrument_retaddr_or(rtx insn)
80730 +{
80731 + rtx orq;
80732 + rtvec argvec, constraintvec, labelvec;
80733 + int line;
80734 +
80735 + // create asm volatile("orq %%r10,(%%rsp)":::)
80736 + argvec = rtvec_alloc(0);
80737 + constraintvec = rtvec_alloc(0);
80738 + labelvec = rtvec_alloc(0);
80739 + line = expand_location(RTL_LOCATION(insn)).line;
80740 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80741 + MEM_VOLATILE_P(orq) = 1;
80742 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
80743 + emit_insn_before(orq, insn);
80744 +}
80745 +
80746 +/*
80747 + * find all asm level function returns and forcibly set the highest bit of the return address
80748 + */
80749 +static unsigned int execute_kernexec_retaddr(void)
80750 +{
80751 + rtx insn;
80752 +
80753 + // 1. find function returns
80754 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80755 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
80756 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
80757 + rtx body;
80758 +
80759 + // is it a retn
80760 + if (!JUMP_P(insn))
80761 + continue;
80762 + body = PATTERN(insn);
80763 + if (GET_CODE(body) == PARALLEL)
80764 + body = XVECEXP(body, 0, 0);
80765 + if (GET_CODE(body) != RETURN)
80766 + continue;
80767 + kernexec_instrument_retaddr(insn);
80768 + }
80769 +
80770 +// print_simple_rtl(stderr, get_insns());
80771 +// print_rtl(stderr, get_insns());
80772 +
80773 + return 0;
80774 +}
80775 +
80776 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80777 +{
80778 + const char * const plugin_name = plugin_info->base_name;
80779 + const int argc = plugin_info->argc;
80780 + const struct plugin_argument * const argv = plugin_info->argv;
80781 + int i;
80782 + struct register_pass_info kernexec_reload_pass_info = {
80783 + .pass = &kernexec_reload_pass.pass,
80784 + .reference_pass_name = "ssa",
80785 + .ref_pass_instance_number = 0,
80786 + .pos_op = PASS_POS_INSERT_AFTER
80787 + };
80788 + struct register_pass_info kernexec_fptr_pass_info = {
80789 + .pass = &kernexec_fptr_pass.pass,
80790 + .reference_pass_name = "ssa",
80791 + .ref_pass_instance_number = 0,
80792 + .pos_op = PASS_POS_INSERT_AFTER
80793 + };
80794 + struct register_pass_info kernexec_retaddr_pass_info = {
80795 + .pass = &kernexec_retaddr_pass.pass,
80796 + .reference_pass_name = "pro_and_epilogue",
80797 + .ref_pass_instance_number = 0,
80798 + .pos_op = PASS_POS_INSERT_AFTER
80799 + };
80800 +
80801 + if (!plugin_default_version_check(version, &gcc_version)) {
80802 + error(G_("incompatible gcc/plugin versions"));
80803 + return 1;
80804 + }
80805 +
80806 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
80807 +
80808 + if (TARGET_64BIT == 0)
80809 + return 0;
80810 +
80811 + for (i = 0; i < argc; ++i) {
80812 + if (!strcmp(argv[i].key, "method")) {
80813 + if (!argv[i].value) {
80814 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80815 + continue;
80816 + }
80817 + if (!strcmp(argv[i].value, "bts")) {
80818 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
80819 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
80820 + } else if (!strcmp(argv[i].value, "or")) {
80821 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
80822 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
80823 + fix_register("r10", 1, 1);
80824 + } else
80825 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80826 + continue;
80827 + }
80828 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80829 + }
80830 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
80831 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
80832 +
80833 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
80834 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
80835 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
80836 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
80837 +
80838 + return 0;
80839 +}
80840 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
80841 new file mode 100644
80842 index 0000000..daaa86c
80843 --- /dev/null
80844 +++ b/tools/gcc/size_overflow_hash.data
80845 @@ -0,0 +1,2486 @@
80846 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
80847 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
80848 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
80849 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
80850 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
80851 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
80852 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
80853 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
80854 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
80855 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
80856 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
80857 +_000013_hash kmemdup 2 64015 _000013_hash NULL
80858 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
80859 +_000015_hash memdup_user 2 59590 _000015_hash NULL
80860 +_000016_hash module_alloc 1 63630 _000016_hash NULL
80861 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
80862 +_000018_hash read_kcore 3 63488 _000018_hash NULL
80863 +_000019_hash read_ldt 2 47570 _000019_hash NULL
80864 +_000020_hash read_zero 3 19366 _000020_hash NULL
80865 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
80866 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
80867 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
80868 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
80869 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
80870 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
80871 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
80872 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
80873 +_000029_hash adu_write 3 30487 _000029_hash NULL
80874 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
80875 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
80876 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
80877 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
80878 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
80879 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
80880 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
80881 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
80882 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
80883 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
80884 +_000041_hash alloc_context 1 3194 _000041_hash NULL
80885 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
80886 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
80887 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
80888 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
80889 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
80890 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
80891 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
80892 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
80893 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
80894 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
80895 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
80896 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
80897 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
80898 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
80899 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
80900 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
80901 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
80902 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
80903 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
80904 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
80905 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
80906 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
80907 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
80908 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
80909 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
80910 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
80911 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
80912 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
80913 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
80914 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
80915 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
80916 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
80917 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
80918 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
80919 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
80920 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
80921 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
80922 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
80923 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
80924 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
80925 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
80926 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
80927 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
80928 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
80929 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
80930 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
80931 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
80932 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
80933 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
80934 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
80935 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
80936 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
80937 +_000096_hash capi_write 3 35104 _000096_hash NULL
80938 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
80939 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
80940 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
80941 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
80942 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
80943 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
80944 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
80945 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
80946 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
80947 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
80948 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
80949 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
80950 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
80951 +_000111_hash change_xattr 5 61390 _000111_hash NULL
80952 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
80953 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
80954 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
80955 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
80956 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
80957 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
80958 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
80959 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
80960 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
80961 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
80962 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
80963 +_000123_hash cmm_write 3 2896 _000123_hash NULL
80964 +_000124_hash cm_write 3 36858 _000124_hash NULL
80965 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
80966 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
80967 +_000127_hash command_file_write 3 31318 _000127_hash NULL
80968 +_000128_hash command_write 3 58841 _000128_hash NULL
80969 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
80970 +_000130_hash concat_writev 3 21451 _000130_hash NULL
80971 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
80972 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
80973 +_000133_hash copy_items 6 50140 _000133_hash NULL
80974 +_000134_hash copy_macs 4 45534 _000134_hash NULL
80975 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
80976 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
80977 +_000137_hash cosa_write 3 1774 _000137_hash NULL
80978 +_000138_hash create_entry 2 33479 _000138_hash NULL
80979 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
80980 +_000141_hash create_xattr 5 54106 _000141_hash NULL
80981 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
80982 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
80983 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
80984 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
80985 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
80986 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
80987 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
80988 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
80989 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
80990 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
80991 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
80992 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
80993 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
80994 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
80995 +_000158_hash dev_config 3 8506 _000158_hash NULL
80996 +_000159_hash device_write 3 45156 _000159_hash NULL
80997 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
80998 +_000161_hash devres_alloc 2 551 _000161_hash NULL
80999 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
81000 +_000163_hash direct_entry 3 38836 _000163_hash NULL
81001 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
81002 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
81003 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
81004 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
81005 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
81006 +_000169_hash dm_read 3 15674 _000169_hash NULL
81007 +_000170_hash dm_write 3 2513 _000170_hash NULL
81008 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
81009 +_000172_hash dns_query 3 9676 _000172_hash NULL
81010 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
81011 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
81012 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
81013 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
81014 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
81015 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
81016 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
81017 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
81018 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
81019 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
81020 +_000183_hash dsp_write 2 46218 _000183_hash NULL
81021 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
81022 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
81023 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
81024 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
81025 +_000188_hash dvb_play 3 50814 _000188_hash NULL
81026 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
81027 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
81028 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
81029 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
81030 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
81031 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
81032 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
81033 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
81034 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
81035 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
81036 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
81037 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
81038 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
81039 +_000202_hash ep_read 3 58813 _000202_hash NULL
81040 +_000203_hash ep_write 3 59008 _000203_hash NULL
81041 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
81042 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
81043 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
81044 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
81045 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
81046 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
81047 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
81048 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
81049 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
81050 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
81051 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
81052 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
81053 +_000216_hash fl_create 5 56435 _000216_hash NULL
81054 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
81055 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
81056 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
81057 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
81058 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
81059 +_000222_hash get_arg 3 5694 _000222_hash NULL
81060 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
81061 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
81062 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
81063 +_000226_hash get_registers 3 26187 _000226_hash NULL
81064 +_000227_hash get_scq 2 10897 _000227_hash NULL
81065 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
81066 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
81067 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
81068 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
81069 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
81070 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
81071 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
81072 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
81073 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
81074 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
81075 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
81076 +_000239_hash handle_request 9 10024 _000239_hash NULL
81077 +_000240_hash hash_new 1 62224 _000240_hash NULL
81078 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
81079 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
81080 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
81081 +_000244_hash heap_init 2 49617 _000244_hash NULL
81082 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
81083 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
81084 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
81085 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
81086 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
81087 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
81088 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
81089 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
81090 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
81091 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
81092 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
81093 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
81094 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
81095 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
81096 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
81097 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
81098 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
81099 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
81100 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
81101 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
81102 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
81103 +_000266_hash ieee80211_build_probe_req 7 27660 _000266_hash NULL
81104 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
81105 +_000268_hash if_write 3 51756 _000268_hash NULL
81106 +_000269_hash ilo_write 3 64378 _000269_hash NULL
81107 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
81108 +_000271_hash init_data_container 1 60709 _000271_hash NULL
81109 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
81110 +_000273_hash insert_dent 7 65034 _000273_hash NULL
81111 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
81112 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
81113 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
81114 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
81115 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
81116 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
81117 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
81118 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
81119 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
81120 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
81121 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
81122 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
81123 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
81124 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
81125 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
81126 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
81127 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
81128 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
81129 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
81130 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
81131 +_000294_hash isdn_read 3 50021 _000294_hash NULL
81132 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
81133 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
81134 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
81135 +_000298_hash iso_callback 3 43208 _000298_hash NULL
81136 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
81137 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
81138 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
81139 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
81140 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
81141 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
81142 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
81143 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
81144 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
81145 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
81146 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
81147 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
81148 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
81149 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
81150 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
81151 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
81152 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
81153 +_000319_hash kone_receive 4 4690 _000319_hash NULL
81154 +_000320_hash kone_send 4 63435 _000320_hash NULL
81155 +_000321_hash krealloc 2 14908 _000321_hash NULL
81156 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
81157 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
81158 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
81159 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
81160 +_000326_hash kzalloc 1 54740 _000326_hash NULL
81161 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
81162 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
81163 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
81164 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
81165 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
81166 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
81167 +_000333_hash __lgread 4 31668 _000333_hash NULL
81168 +_000334_hash libipw_alloc_txb 1 27579 _000334_hash NULL
81169 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
81170 +_000336_hash listxattr 3 12769 _000336_hash NULL
81171 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
81172 +_000338_hash load_msg 2 95 _000338_hash NULL
81173 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
81174 +_000340_hash lp_write 3 9511 _000340_hash NULL
81175 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
81176 +_000342_hash mce_write 3 26201 _000342_hash NULL
81177 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
81178 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
81179 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
81180 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
81181 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
81182 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
81183 +_000350_hash mem_rw 3 22085 _000350_hash NULL
81184 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
81185 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
81186 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
81187 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
81188 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
81189 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
81190 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
81191 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
81192 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
81193 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
81194 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
81195 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
81196 +_000363_hash mtdchar_write 3 56831 _000363_hash NULL
81197 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
81198 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
81199 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
81200 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
81201 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
81202 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
81203 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
81204 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
81205 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
81206 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
81207 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
81208 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
81209 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
81210 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
81211 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
81212 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
81213 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
81214 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
81215 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
81216 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
81217 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
81218 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
81219 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
81220 +_000391_hash nvram_write 3 3894 _000391_hash NULL
81221 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
81222 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
81223 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
81224 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
81225 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
81226 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
81227 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
81228 +_000399_hash opticon_write 4 60775 _000399_hash NULL
81229 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
81230 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
81231 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
81232 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
81233 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
81234 +_000405_hash parse_command 2 37079 _000405_hash NULL
81235 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
81236 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
81237 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
81238 +_000409_hash pg_write 3 40766 _000409_hash NULL
81239 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
81240 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
81241 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
81242 +_000413_hash pkt_add 3 39897 _000413_hash NULL
81243 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
81244 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
81245 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
81246 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
81247 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
81248 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
81249 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
81250 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
81251 +_000422_hash ppp_write 3 34034 _000422_hash NULL
81252 +_000423_hash pp_read 3 33210 _000423_hash NULL
81253 +_000424_hash pp_write 3 39554 _000424_hash NULL
81254 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
81255 +_000426_hash printer_write 3 60276 _000426_hash NULL
81256 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
81257 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
81258 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
81259 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
81260 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
81261 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
81262 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
81263 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
81264 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
81265 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
81266 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
81267 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
81268 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
81269 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
81270 +_000442_hash pt_write 3 40159 _000442_hash NULL
81271 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
81272 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
81273 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
81274 +_000446_hash r3964_write 4 57662 _000446_hash NULL
81275 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
81276 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
81277 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
81278 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
81279 +_000451_hash rbd_add 3 16366 _000451_hash NULL
81280 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
81281 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
81282 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
81283 +_000455_hash read 3 9397 _000455_hash NULL
81284 +_000456_hash read_buf 2 20469 _000456_hash NULL
81285 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
81286 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
81287 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
81288 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
81289 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
81290 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
81291 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
81292 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
81293 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
81294 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
81295 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
81296 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
81297 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
81298 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
81299 +_000471_hash revalidate 2 19043 _000471_hash NULL
81300 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
81301 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
81302 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
81303 +_000475_hash rngapi_reset 3 34366 _000475_hash NULL
81304 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
81305 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
81306 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
81307 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
81308 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
81309 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
81310 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
81311 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
81312 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
81313 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
81314 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
81315 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
81316 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
81317 +_000489_hash savemem 3 58129 _000489_hash NULL
81318 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
81319 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
81320 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
81321 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
81322 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
81323 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
81324 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
81325 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
81326 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
81327 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
81328 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
81329 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
81330 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
81331 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
81332 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
81333 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
81334 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
81335 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
81336 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
81337 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
81338 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
81339 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
81340 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
81341 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
81342 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
81343 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
81344 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
81345 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
81346 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
81347 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
81348 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
81349 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
81350 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
81351 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
81352 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
81353 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
81354 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
81355 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
81356 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
81357 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
81358 +_000532_hash set_registers 3 53582 _000532_hash NULL
81359 +_000533_hash setsockopt 5 54539 _000533_hash NULL
81360 +_000534_hash setup_req 3 5848 _000534_hash NULL
81361 +_000535_hash setup_window 7 59178 _000535_hash NULL
81362 +_000536_hash setxattr 4 37006 _000536_hash NULL
81363 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
81364 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
81365 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
81366 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
81367 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
81368 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
81369 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
81370 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
81371 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
81372 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
81373 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
81374 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
81375 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
81376 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
81377 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
81378 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
81379 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
81380 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
81381 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
81382 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
81383 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
81384 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
81385 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
81386 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
81387 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
81388 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
81389 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
81390 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
81391 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
81392 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
81393 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
81394 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
81395 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
81396 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
81397 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
81398 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
81399 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
81400 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
81401 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
81402 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
81403 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
81404 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
81405 +_000581_hash spidev_write 3 44510 _000581_hash NULL
81406 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
81407 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
81408 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
81409 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
81410 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
81411 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
81412 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
81413 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
81414 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
81415 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
81416 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
81417 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
81418 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
81419 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
81420 +_000597_hash tower_write 3 8580 _000597_hash NULL
81421 +_000598_hash tpm_write 3 50798 _000598_hash NULL
81422 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
81423 +_000600_hash trusted_update 3 12664 _000600_hash NULL
81424 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
81425 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
81426 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
81427 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
81428 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
81429 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
81430 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
81431 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
81432 +_000609_hash uea_request 4 47613 _000609_hash NULL
81433 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
81434 +_000611_hash uio_write 3 43202 _000611_hash NULL
81435 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
81436 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
81437 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
81438 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
81439 +_000616_hash usblp_write 3 23178 _000616_hash NULL
81440 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
81441 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
81442 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
81443 +_000621_hash user_update 3 41332 _000621_hash NULL
81444 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
81445 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
81446 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
81447 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
81448 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
81449 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
81450 +_000629_hash vcs_write 3 3910 _000629_hash NULL
81451 +_000630_hash vfd_write 3 14717 _000630_hash NULL
81452 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
81453 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
81454 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
81455 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
81456 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
81457 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
81458 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
81459 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
81460 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
81461 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
81462 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
81463 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
81464 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
81465 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
81466 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
81467 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
81468 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
81469 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
81470 +_000651_hash wdm_write 3 53735 _000651_hash NULL
81471 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
81472 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
81473 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
81474 +_000655_hash write 3 62671 _000655_hash NULL
81475 +_000656_hash write_flush 3 50803 _000656_hash NULL
81476 +_000657_hash write_rio 3 54837 _000657_hash NULL
81477 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
81478 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
81479 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
81480 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
81481 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
81482 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
81483 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
81484 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
81485 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
81486 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
81487 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
81488 +_000669_hash zoran_write 3 22404 _000669_hash NULL
81489 +_000671_hash acpi_ex_allocate_name_string 2 7685 _000671_hash NULL
81490 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
81491 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
81492 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
81493 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
81494 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
81495 +_000677_hash add_res_range 4 21310 _000677_hash NULL
81496 +_000678_hash addtgt 3 54703 _000678_hash NULL
81497 +_000679_hash add_uuid 4 49831 _000679_hash NULL
81498 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
81499 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
81500 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
81501 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
81502 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
81503 +_000685_hash alloc_async 1 14208 _000685_hash NULL
81504 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
81505 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
81506 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
81507 +_000689_hash alloc_context 1 41283 _000689_hash NULL
81508 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
81509 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
81510 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
81511 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
81512 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
81513 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
81514 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
81515 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
81516 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
81517 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
81518 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
81519 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
81520 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
81521 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
81522 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
81523 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
81524 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
81525 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
81526 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
81527 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
81528 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
81529 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
81530 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
81531 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
81532 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
81533 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
81534 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
81535 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
81536 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
81537 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
81538 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
81539 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
81540 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
81541 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
81542 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
81543 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
81544 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
81545 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
81546 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
81547 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
81548 +_000736_hash ati_create_gatt_pages 1 4722 _000736_hash NULL
81549 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
81550 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
81551 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
81552 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
81553 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
81554 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
81555 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
81556 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
81557 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
81558 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
81559 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
81560 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
81561 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
81562 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
81563 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
81564 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
81565 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
81566 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
81567 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
81568 +_000759_hash ca_extend 2 64541 _000759_hash NULL
81569 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
81570 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
81571 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
81572 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
81573 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
81574 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
81575 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
81576 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
81577 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
81578 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
81579 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
81580 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
81581 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
81582 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
81583 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
81584 +_000778_hash cifs_writedata_alloc 1 32880 _000778_hash NULL
81585 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
81586 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
81587 +_000781_hash construct_key 3 11329 _000781_hash NULL
81588 +_000782_hash context_alloc 3 24645 _000782_hash NULL
81589 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
81590 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
81591 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
81592 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
81593 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
81594 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
81595 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
81596 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
81597 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
81598 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
81599 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
81600 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
81601 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
81602 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
81603 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
81604 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
81605 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
81606 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
81607 +_000805_hash depth_write 3 3021 _000805_hash NULL
81608 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
81609 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
81610 +_000808_hash dev_write 3 7708 _000808_hash NULL
81611 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
81612 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
81613 +_000811_hash disconnect 4 32521 _000811_hash NULL
81614 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
81615 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
81616 +_000815_hash do_dccp_setsockopt 5 54377 _000815_hash NULL
81617 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
81618 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
81619 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
81620 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
81621 +_000820_hash do_sync 1 9604 _000820_hash NULL
81622 +_000821_hash dup_array 3 33551 _000821_hash NULL
81623 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
81624 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
81625 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
81626 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
81627 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
81628 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
81629 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
81630 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
81631 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
81632 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
81633 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
81634 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
81635 +_000834_hash enable_write 3 30456 _000834_hash NULL
81636 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
81637 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
81638 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
81639 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
81640 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
81641 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
81642 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
81643 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
81644 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
81645 +_000844_hash fillonedir 3 41746 _000844_hash NULL
81646 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
81647 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
81648 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
81649 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
81650 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
81651 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
81652 +_000851_hash get_entry 4 16003 _000851_hash NULL
81653 +_000852_hash get_free_de 2 33714 _000852_hash NULL
81654 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
81655 +_000854_hash getxattr 4 24398 _000854_hash NULL
81656 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
81657 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
81658 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
81659 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
81660 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
81661 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
81662 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
81663 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
81664 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
81665 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
81666 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
81667 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
81668 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
81669 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
81670 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
81671 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
81672 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
81673 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
81674 +_000876_hash ieee80211_send_probe_req 6 6924 _000876_hash NULL
81675 +_000877_hash if_writecmd 2 815 _000877_hash NULL
81676 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
81677 +_000880_hash init_ipath 1 48187 _000880_hash NULL
81678 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
81679 +_000883_hash init_q 4 132 _000883_hash NULL
81680 +_000884_hash init_state 2 60165 _000884_hash NULL
81681 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
81682 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
81683 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
81684 +_000888_hash interfaces 2 38859 _000888_hash NULL
81685 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
81686 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
81687 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
81688 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
81689 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
81690 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
81691 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
81692 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
81693 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
81694 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
81695 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
81696 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
81697 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
81698 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
81699 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
81700 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
81701 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
81702 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
81703 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
81704 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
81705 +_000911_hash isdn_write 3 45863 _000911_hash NULL
81706 +_000912_hash isku_receive 4 54130 _000912_hash NULL
81707 +_000913_hash isku_send 4 41542 _000913_hash NULL
81708 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
81709 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
81710 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
81711 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
81712 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
81713 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
81714 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
81715 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
81716 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
81717 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
81718 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
81719 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
81720 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
81721 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
81722 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
81723 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
81724 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
81725 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
81726 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
81727 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
81728 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
81729 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
81730 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
81731 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
81732 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
81733 +_000940_hash kvm_write_guest_page 5 63555 _000940_hash NULL
81734 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
81735 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
81736 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
81737 +_000945_hash lc_create 3 48662 _000945_hash NULL
81738 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
81739 +_000947_hash linear_conf 2 23485 _000947_hash NULL
81740 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
81741 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
81742 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
81743 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
81744 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
81745 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
81746 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
81747 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
81748 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
81749 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
81750 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
81751 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
81752 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
81753 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
81754 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
81755 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
81756 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
81757 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
81758 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
81759 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
81760 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
81761 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
81762 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
81763 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
81764 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
81765 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
81766 +_000977_hash new_dir 3 31919 _000977_hash NULL
81767 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
81768 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
81769 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
81770 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
81771 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
81772 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
81773 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
81774 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
81775 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
81776 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
81777 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
81778 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
81779 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
81780 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
81781 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
81782 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
81783 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
81784 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
81785 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
81786 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
81787 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
81788 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
81789 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
81790 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
81791 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
81792 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
81793 +_001008_hash osst_write 3 31581 _001008_hash NULL
81794 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
81795 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
81796 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
81797 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
81798 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
81799 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
81800 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
81801 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
81802 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
81803 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
81804 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
81805 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
81806 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
81807 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
81808 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
81809 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
81810 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
81811 +_001030_hash play_iframe 3 8219 _001030_hash NULL
81812 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
81813 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
81814 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
81815 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
81816 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
81817 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
81818 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
81819 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
81820 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
81821 +_001042_hash proc_write 3 51003 _001042_hash NULL
81822 +_001043_hash profile_load 3 58267 _001043_hash NULL
81823 +_001044_hash profile_remove 3 8556 _001044_hash NULL
81824 +_001045_hash profile_replace 3 14652 _001045_hash NULL
81825 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
81826 +_001047_hash pyra_send 4 12061 _001047_hash NULL
81827 +_001048_hash qc_capture 3 19298 _001048_hash NULL
81828 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
81829 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
81830 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
81831 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
81832 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
81833 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
81834 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
81835 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
81836 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
81837 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
81838 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
81839 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
81840 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
81841 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
81842 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
81843 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
81844 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
81845 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
81846 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
81847 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
81848 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
81849 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
81850 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
81851 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
81852 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
81853 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
81854 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
81855 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
81856 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
81857 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
81858 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
81859 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
81860 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
81861 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
81862 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
81863 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
81864 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
81865 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
81866 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
81867 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
81868 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
81869 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
81870 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
81871 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
81872 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
81873 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
81874 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
81875 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
81876 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
81877 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
81878 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
81879 +_001102_hash set_connectable 4 56458 _001102_hash NULL
81880 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
81881 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
81882 +_001105_hash setkey 3 14987 _001105_hash NULL
81883 +_001106_hash set_le 4 30581 _001106_hash NULL
81884 +_001107_hash set_link_security 4 4502 _001107_hash NULL
81885 +_001108_hash set_local_name 4 55757 _001108_hash NULL
81886 +_001109_hash set_powered 4 12129 _001109_hash NULL
81887 +_001110_hash set_ssp 4 62411 _001110_hash NULL
81888 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
81889 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
81890 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
81891 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
81892 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
81893 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
81894 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
81895 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
81896 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
81897 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
81898 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
81899 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
81900 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
81901 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
81902 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
81903 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
81904 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
81905 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
81906 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
81907 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
81908 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
81909 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
81910 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
81911 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
81912 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
81913 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
81914 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
81915 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
81916 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
81917 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
81918 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
81919 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
81920 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
81921 +_001148_hash sound_write 3 5102 _001148_hash NULL
81922 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
81923 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
81924 +_001151_hash spidev_message 3 5518 _001151_hash NULL
81925 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
81926 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
81927 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
81928 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
81929 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
81930 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
81931 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
81932 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
81933 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
81934 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
81935 +_001163_hash st_write 3 16874 _001163_hash NULL
81936 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
81937 +_001165_hash symtab_init 2 61050 _001165_hash NULL
81938 +_001166_hash sys_bind 3 10799 _001166_hash NULL
81939 +_001167_hash sys_connect 3 15291 _001167_hash NULL
81940 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
81941 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
81942 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
81943 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
81944 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
81945 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
81946 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
81947 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
81948 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
81949 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
81950 +_001178_hash sys_semop 3 39457 _001178_hash NULL
81951 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
81952 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
81953 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
81954 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
81955 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
81956 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
81957 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
81958 +_001186_hash timeout_write 3 50991 _001186_hash NULL
81959 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
81960 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
81961 +_001189_hash tm6000_read_write_usb 7 50774 _001189_hash NULL
81962 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
81963 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
81964 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
81965 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
81966 +_001195_hash ts_write 3 64336 _001195_hash NULL
81967 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
81968 +_001197_hash tty_write 3 5494 _001197_hash NULL
81969 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
81970 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
81971 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
81972 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
81973 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
81974 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
81975 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
81976 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
81977 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
81978 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
81979 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
81980 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
81981 +_001211_hash uvc_alloc_entity 3 20836 _001211_hash NULL
81982 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
81983 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
81984 +_001214_hash vb2_read 3 42703 _001214_hash NULL
81985 +_001215_hash vb2_write 3 31948 _001215_hash NULL
81986 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
81987 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
81988 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
81989 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
81990 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
81991 +_001223_hash vmalloc 1 15464 _001223_hash NULL
81992 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
81993 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
81994 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
81995 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
81996 +_001228_hash vzalloc 1 47421 _001228_hash NULL
81997 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
81998 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
81999 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
82000 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
82001 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
82002 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
82003 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
82004 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
82005 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
82006 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
82007 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
82008 +_001240_hash xfs_dir_cilookup_result 3 64288 _001240_hash NULL
82009 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
82010 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
82011 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
82012 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
82013 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
82014 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
82015 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
82016 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
82017 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
82018 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
82019 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
82020 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
82021 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
82022 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
82023 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
82024 +_001256_hash add_child 4 45201 _001256_hash NULL
82025 +_001257_hash add_port 2 54941 _001257_hash NULL
82026 +_001258_hash adu_read 3 24177 _001258_hash NULL
82027 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
82028 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
82029 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
82030 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
82031 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
82032 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
82033 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
82034 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
82035 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
82036 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
82037 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
82038 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
82039 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
82040 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
82041 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
82042 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
82043 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
82044 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
82045 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
82046 +_001280_hash async_setkey 3 35521 _001280_hash NULL
82047 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
82048 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
82049 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
82050 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
82051 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
82052 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
82053 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
82054 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
82055 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
82056 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
82057 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
82058 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
82059 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
82060 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
82061 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
82062 +_001298_hash bm_init 2 13529 _001298_hash NULL
82063 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
82064 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
82065 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
82066 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
82067 +_001303_hash cache_read 3 24790 _001303_hash NULL
82068 +_001304_hash cache_write 3 13589 _001304_hash NULL
82069 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
82070 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
82071 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
82072 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
82073 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
82074 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
82075 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
82076 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
82077 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
82078 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
82079 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
82080 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
82081 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
82082 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
82083 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
82084 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
82085 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
82086 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
82087 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
82088 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
82089 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
82090 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
82091 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
82092 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
82093 +_001331_hash dev_read 3 56369 _001331_hash NULL
82094 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
82095 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
82096 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
82097 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
82098 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
82099 +_001338_hash do_readlink 2 43518 _001338_hash NULL
82100 +_001339_hash __do_replace 5 37227 _001339_hash NULL
82101 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
82102 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
82103 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
82104 +_001343_hash dump_midi 3 51040 _001343_hash NULL
82105 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
82106 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
82107 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5 4303 _001346_hash NULL
82108 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
82109 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
82110 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
82111 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
82112 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
82113 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
82114 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
82115 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
82116 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
82117 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
82118 +_001358_hash filldir 3 55137 _001358_hash NULL
82119 +_001359_hash filldir64 3 46469 _001359_hash NULL
82120 +_001360_hash fops_read 3 40672 _001360_hash NULL
82121 +_001361_hash from_buffer 3 18625 _001361_hash NULL
82122 +_001362_hash fsm_init 2 16134 _001362_hash NULL
82123 +_001363_hash get_subdir 3 62581 _001363_hash NULL
82124 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
82125 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
82126 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
82127 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
82128 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
82129 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
82130 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
82131 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
82132 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
82133 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
82134 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
82135 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
82136 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
82137 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
82138 +_001379_hash ilo_read 3 32531 _001379_hash NULL
82139 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
82140 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
82141 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
82142 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
82143 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
82144 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
82145 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
82146 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
82147 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
82148 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
82149 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
82150 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
82151 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
82152 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
82153 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
82154 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
82155 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
82156 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
82157 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
82158 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
82159 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
82160 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
82161 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
82162 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
82163 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
82164 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
82165 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
82166 +_001412_hash keyring_read 3 13438 _001412_hash NULL
82167 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
82168 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
82169 +_001415_hash kmp_init 2 41373 _001415_hash NULL
82170 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
82171 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
82172 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
82173 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
82174 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
82175 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
82176 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
82177 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
82178 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
82179 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
82180 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
82181 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
82182 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
82183 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
82184 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
82185 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
82186 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
82187 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
82188 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
82189 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
82190 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
82191 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
82192 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
82193 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
82194 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
82195 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
82196 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
82197 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
82198 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
82199 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
82200 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
82201 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
82202 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
82203 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
82204 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
82205 +_001454_hash override_release 2 52032 _001454_hash NULL
82206 +_001455_hash packet_snd 3 13634 _001455_hash NULL
82207 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
82208 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
82209 +_001458_hash pg_read 3 17276 _001458_hash NULL
82210 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
82211 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
82212 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
82213 +_001462_hash pms_capture 4 27142 _001462_hash NULL
82214 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
82215 +_001464_hash printer_read 3 54851 _001464_hash NULL
82216 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
82217 +_001466_hash pt_read 3 49136 _001466_hash NULL
82218 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
82219 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
82220 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
82221 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
82222 +_001471_hash qcam_read 3 13977 _001471_hash NULL
82223 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
82224 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
82225 +_001474_hash read_flush 3 43851 _001474_hash NULL
82226 +_001475_hash read_profile 3 27859 _001475_hash NULL
82227 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
82228 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
82229 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
82230 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
82231 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
82232 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
82233 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
82234 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
82235 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
82236 +_001486_hash roccat_read 3 41093 _001486_hash NULL
82237 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
82238 +_001488_hash scsi_register 2 49094 _001488_hash NULL
82239 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
82240 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
82241 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
82242 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
82243 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
82244 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
82245 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
82246 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
82247 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
82248 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
82249 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
82250 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
82251 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
82252 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
82253 +_001503_hash set_arg 3 42824 _001503_hash NULL
82254 +_001504_hash sg_read 3 25799 _001504_hash NULL
82255 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
82256 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
82257 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
82258 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
82259 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
82260 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
82261 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
82262 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
82263 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
82264 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
82265 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
82266 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
82267 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
82268 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
82269 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
82270 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
82271 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
82272 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
82273 +_001525_hash store_msg 3 56417 _001525_hash NULL
82274 +_001526_hash str_to_user 2 11411 _001526_hash NULL
82275 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
82276 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
82277 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
82278 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
82279 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
82280 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
82281 +_001533_hash sys_process_vm_readv 3-5 19090 _001533_hash NULL
82282 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
82283 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
82284 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
82285 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
82286 +_001540_hash team_options_register 3 20091 _001540_hash NULL
82287 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
82288 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
82289 +_001543_hash tipc_send 4 51238 _001543_hash NULL
82290 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
82291 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
82292 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
82293 +_001547_hash tnode_new 3 44757 _001547_hash NULL
82294 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
82295 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
82296 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
82297 +_001551_hash tpm_read 3 50344 _001551_hash NULL
82298 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
82299 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
82300 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
82301 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
82302 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
82303 +_001558_hash uio_read 3 49300 _001558_hash NULL
82304 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
82305 +_001560_hash unlink1 3 63059 _001560_hash NULL
82306 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
82307 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
82308 +_001564_hash usblp_read 3 57342 _001564_hash NULL
82309 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
82310 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
82311 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
82312 +_001568_hash user_read 3 51881 _001568_hash NULL
82313 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
82314 +_001570_hash vcs_read 3 8017 _001570_hash NULL
82315 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
82316 +_001572_hash venus_create 4 20555 _001572_hash NULL
82317 +_001573_hash venus_link 5 32165 _001573_hash NULL
82318 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
82319 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
82320 +_001576_hash venus_remove 4 59781 _001576_hash NULL
82321 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
82322 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
82323 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
82324 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
82325 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
82326 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
82327 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
82328 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
82329 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
82330 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
82331 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
82332 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
82333 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
82334 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
82335 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
82336 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
82337 +_001596_hash wdm_read 3 6549 _001596_hash NULL
82338 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
82339 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
82340 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
82341 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
82342 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
82343 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
82344 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
82345 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
82346 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
82347 +_001606_hash xz_dec_lzma2_create 2 36353 _001606_hash NULL
82348 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
82349 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
82350 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
82351 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
82352 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
82353 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
82354 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
82355 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
82356 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
82357 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
82358 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
82359 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
82360 +_001619_hash __alloc_bootmem_low 1 43423 _001619_hash NULL
82361 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
82362 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
82363 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
82364 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
82365 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
82366 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
82367 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
82368 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
82369 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
82370 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
82371 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
82372 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
82373 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
82374 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
82375 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
82376 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
82377 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
82378 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
82379 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
82380 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
82381 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
82382 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
82383 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
82384 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
82385 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
82386 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
82387 +_001648_hash blk_queue_init_tags 2 44355 _001648_hash NULL
82388 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
82389 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
82390 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
82391 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
82392 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
82393 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
82394 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
82395 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
82396 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
82397 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
82398 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
82399 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
82400 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
82401 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
82402 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
82403 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
82404 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
82405 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
82406 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
82407 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
82408 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
82409 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
82410 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
82411 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
82412 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
82413 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
82414 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
82415 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
82416 +_001677_hash create_subvol 4 2347 _001677_hash NULL
82417 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
82418 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
82419 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
82420 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
82421 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
82422 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
82423 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
82424 +_001687_hash debug_output 3 18575 _001687_hash NULL
82425 +_001688_hash debug_read 3 19322 _001688_hash NULL
82426 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
82427 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
82428 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
82429 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
82430 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
82431 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
82432 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
82433 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
82434 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
82435 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
82436 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
82437 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
82438 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
82439 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
82440 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
82441 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
82442 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
82443 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
82444 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
82445 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
82446 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
82447 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
82448 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
82449 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
82450 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
82451 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
82452 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
82453 +_001716_hash filter_read 3 61692 _001716_hash NULL
82454 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
82455 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
82456 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
82457 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
82458 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
82459 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
82460 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
82461 +_001724_hash ht40allow_map_read 3 55209 _001724_hash NULL
82462 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
82463 +_001726_hash hysdn_conf_read 3 42324 _001726_hash NULL
82464 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
82465 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
82466 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
82467 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
82468 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
82469 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
82470 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
82471 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
82472 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
82473 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
82474 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
82475 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
82476 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
82477 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
82478 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
82479 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
82480 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
82481 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
82482 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
82483 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
82484 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
82485 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
82486 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
82487 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
82488 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
82489 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
82490 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
82491 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
82492 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
82493 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
82494 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
82495 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
82496 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
82497 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
82498 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
82499 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
82500 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
82501 +_001765_hash ipw_write 3 59807 _001765_hash NULL
82502 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
82503 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
82504 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
82505 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
82506 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
82507 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
82508 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
82509 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
82510 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
82511 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
82512 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
82513 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
82514 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
82515 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
82516 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
82517 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
82518 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
82519 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
82520 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
82521 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
82522 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
82523 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
82524 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
82525 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
82526 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
82527 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
82528 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
82529 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
82530 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
82531 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
82532 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
82533 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
82534 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
82535 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
82536 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
82537 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
82538 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
82539 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
82540 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
82541 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
82542 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
82543 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
82544 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _001808_hash NULL
82545 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
82546 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
82547 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
82548 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
82549 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
82550 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
82551 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
82552 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
82553 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
82554 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
82555 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
82556 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
82557 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
82558 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
82559 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
82560 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
82561 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
82562 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
82563 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
82564 +_001828_hash key_key_read 3 3241 _001828_hash NULL
82565 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
82566 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
82567 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
82568 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
82569 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
82570 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
82571 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
82572 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
82573 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
82574 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
82575 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
82576 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
82577 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
82578 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
82579 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
82580 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
82581 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
82582 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
82583 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
82584 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
82585 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
82586 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
82587 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
82588 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
82589 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
82590 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
82591 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
82592 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
82593 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
82594 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
82595 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
82596 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
82597 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
82598 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
82599 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
82600 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
82601 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
82602 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
82603 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
82604 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
82605 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
82606 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
82607 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
82608 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
82609 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
82610 +_001876_hash nfsd_vfs_read 6 62605 _001876_hash NULL
82611 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
82612 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
82613 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
82614 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
82615 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
82616 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
82617 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
82618 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
82619 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
82620 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
82621 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
82622 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
82623 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
82624 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
82625 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
82626 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
82627 +_001893_hash page_readlink 3 23346 _001893_hash NULL
82628 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
82629 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
82630 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
82631 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
82632 +_001898_hash pms_read 3 53873 _001898_hash NULL
82633 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
82634 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
82635 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
82636 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
82637 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
82638 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
82639 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
82640 +_001906_hash proc_read 3 43614 _001906_hash NULL
82641 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
82642 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
82643 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
82644 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
82645 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
82646 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
82647 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
82648 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
82649 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
82650 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
82651 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
82652 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
82653 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
82654 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
82655 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
82656 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
82657 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
82658 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
82659 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
82660 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
82661 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
82662 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
82663 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
82664 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
82665 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
82666 +_001932_hash queues_read 3 24877 _001932_hash NULL
82667 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
82668 +_001934_hash rcname_read 3 25919 _001934_hash NULL
82669 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
82670 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
82671 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
82672 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
82673 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
82674 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
82675 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
82676 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
82677 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
82678 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
82679 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
82680 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
82681 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
82682 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
82683 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
82684 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
82685 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
82686 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
82687 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
82688 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
82689 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
82690 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
82691 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
82692 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
82693 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
82694 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
82695 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
82696 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
82697 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
82698 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
82699 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
82700 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
82701 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
82702 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
82703 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
82704 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
82705 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
82706 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
82707 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
82708 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
82709 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
82710 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
82711 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
82712 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
82713 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
82714 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
82715 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
82716 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
82717 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
82718 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
82719 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
82720 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
82721 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
82722 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
82723 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _001989_hash NULL
82724 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
82725 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
82726 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
82727 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
82728 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
82729 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
82730 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
82731 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
82732 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
82733 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
82734 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
82735 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
82736 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
82737 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
82738 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
82739 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
82740 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
82741 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
82742 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
82743 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
82744 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
82745 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
82746 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
82747 +_002014_hash send_msg 4 37323 _002014_hash NULL
82748 +_002015_hash send_packet 4 52960 _002015_hash NULL
82749 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
82750 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
82751 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
82752 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
82753 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
82754 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
82755 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
82756 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
82757 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
82758 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
82759 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
82760 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
82761 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
82762 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
82763 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
82764 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
82765 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
82766 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
82767 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
82768 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
82769 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
82770 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
82771 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
82772 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
82773 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
82774 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
82775 +_002045_hash st_read 3 51251 _002045_hash NULL
82776 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
82777 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
82778 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
82779 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
82780 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
82781 +_002051_hash sys_readv 3 50664 _002051_hash NULL
82782 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
82783 +_002053_hash sys_writev 3 28384 _002053_hash NULL
82784 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
82785 +_002055_hash ts_read 3 44687 _002055_hash NULL
82786 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
82787 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
82788 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
82789 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
82790 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
82791 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
82792 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
82793 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
82794 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
82795 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
82796 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
82797 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
82798 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
82799 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
82800 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
82801 +_002074_hash waiters_read 3 40902 _002074_hash NULL
82802 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
82803 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
82804 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
82805 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
82806 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
82807 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
82808 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
82809 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
82810 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
82811 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
82812 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
82813 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
82814 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
82815 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
82816 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
82817 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
82818 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
82819 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
82820 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
82821 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
82822 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
82823 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
82824 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
82825 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
82826 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
82827 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
82828 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
82829 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
82830 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
82831 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
82832 +_002106_hash cx18_read 3 23699 _002106_hash NULL
82833 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
82834 +_002108_hash depth_read 3 31112 _002108_hash NULL
82835 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
82836 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
82837 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
82838 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
82839 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
82840 +_002115_hash enable_read 3 2117 _002115_hash NULL
82841 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
82842 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
82843 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
82844 +_002119_hash frequency_read 3 64031 _002119_hash NULL
82845 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
82846 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
82847 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
82848 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
82849 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
82850 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
82851 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
82852 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
82853 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
82854 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
82855 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
82856 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
82857 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
82858 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
82859 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
82860 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
82861 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
82862 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
82863 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
82864 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
82865 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
82866 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
82867 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
82868 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
82869 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
82870 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
82871 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
82872 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
82873 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
82874 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
82875 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
82876 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
82877 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
82878 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
82879 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
82880 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
82881 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
82882 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002157_hash NULL
82883 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
82884 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
82885 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
82886 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
82887 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
82888 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
82889 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
82890 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
82891 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
82892 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
82893 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
82894 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
82895 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
82896 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
82897 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
82898 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
82899 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
82900 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
82901 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
82902 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
82903 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
82904 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
82905 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
82906 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
82907 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
82908 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
82909 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
82910 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
82911 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
82912 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
82913 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
82914 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
82915 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
82916 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
82917 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
82918 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
82919 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
82920 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
82921 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
82922 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
82923 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
82924 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
82925 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
82926 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
82927 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
82928 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
82929 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
82930 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
82931 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
82932 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
82933 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
82934 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
82935 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
82936 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
82937 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
82938 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
82939 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
82940 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
82941 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
82942 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
82943 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
82944 +_002220_hash power_read 3 15939 _002220_hash NULL
82945 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
82946 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
82947 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
82948 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
82949 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
82950 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
82951 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
82952 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
82953 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
82954 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
82955 +_002231_hash read_tree_block 3 841 _002231_hash NULL
82956 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
82957 +_002234_hash recv_msg 4 48709 _002234_hash NULL
82958 +_002235_hash recv_stream 4 30138 _002235_hash NULL
82959 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
82960 +_002237_hash request_key_async 4 6990 _002237_hash NULL
82961 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
82962 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
82963 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
82964 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
82965 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
82966 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
82967 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
82968 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
82969 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
82970 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
82971 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
82972 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
82973 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
82974 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
82975 +_002252_hash send_stream 4 3397 _002252_hash NULL
82976 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
82977 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
82978 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
82979 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
82980 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
82981 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
82982 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
82983 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
82984 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
82985 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
82986 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
82987 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
82988 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
82989 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
82990 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
82991 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
82992 +_002270_hash timeout_read 3 47915 _002270_hash NULL
82993 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
82994 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
82995 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
82996 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
82997 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
82998 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
82999 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
83000 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
83001 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
83002 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
83003 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
83004 +_002283_hash user_power_read 3 39414 _002283_hash NULL
83005 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
83006 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
83007 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
83008 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
83009 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
83010 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
83011 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
83012 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
83013 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
83014 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
83015 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
83016 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
83017 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
83018 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
83019 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
83020 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
83021 +_002300_hash spi_execute 5 28736 _002300_hash NULL
83022 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
83023 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
83024 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
83025 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
83026 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
83027 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
83028 +_002308_hash write_leb 5 36957 _002308_hash NULL
83029 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
83030 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
83031 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
83032 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
83033 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
83034 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
83035 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
83036 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
83037 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
83038 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
83039 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
83040 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
83041 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
83042 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
83043 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
83044 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
83045 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
83046 +_002329_hash recover_head 3 17904 _002329_hash NULL
83047 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
83048 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
83049 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
83050 +_002334_hash amthi_read 4 45831 _002334_hash NULL
83051 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
83052 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
83053 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
83054 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
83055 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
83056 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
83057 +_002341_hash card_send_command 3 40757 _002341_hash NULL
83058 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
83059 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
83060 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
83061 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
83062 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
83063 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
83064 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
83065 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
83066 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
83067 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
83068 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
83069 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
83070 +_002354_hash fir16_create 3 5574 _002354_hash NULL
83071 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
83072 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
83073 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
83074 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
83075 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
83076 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
83077 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
83078 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
83079 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
83080 +_002365_hash keymap_store 4 45406 _002365_hash NULL
83081 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
83082 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
83083 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
83084 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
83085 +_002370_hash lirc_write 3 20604 _002370_hash NULL
83086 +_002371_hash _malloc 1 54077 _002371_hash NULL
83087 +_002372_hash mei_read 3 6507 _002372_hash NULL
83088 +_002373_hash mei_write 3 4005 _002373_hash NULL
83089 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
83090 +_002375_hash msg_set 3 51725 _002375_hash NULL
83091 +_002376_hash newpart 6 47485 _002376_hash NULL
83092 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
83093 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
83094 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
83095 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
83096 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
83097 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
83098 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
83099 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
83100 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
83101 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
83102 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
83103 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
83104 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
83105 +_002393_hash sep_read 3 17161 _002393_hash NULL
83106 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
83107 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
83108 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
83109 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
83110 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
83111 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
83112 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
83113 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
83114 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
83115 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
83116 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
83117 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
83118 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
83119 +_002411_hash mempool_create 1 29437 _002411_hash NULL
83120 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
83121 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
83122 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
83123 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
83124 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
83125 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
83126 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
83127 +_002419_hash add_partition 2 55588 _002419_hash NULL
83128 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
83129 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
83130 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
83131 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
83132 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
83133 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
83134 +_002427_hash bioset_create 1 5580 _002427_hash NULL
83135 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
83136 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
83137 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
83138 +_002431_hash prison_create 1 43623 _002431_hash NULL
83139 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
83140 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
83141 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
83142 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
83143 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
83144 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
83145 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
83146 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
83147 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
83148 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
83149 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
83150 +_002443_hash comedi_read 3 13199 _002443_hash NULL
83151 +_002444_hash comedi_write 3 47926 _002444_hash NULL
83152 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
83153 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
83154 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
83155 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
83156 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
83157 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
83158 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
83159 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
83160 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
83161 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
83162 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
83163 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
83164 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
83165 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
83166 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
83167 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
83168 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
83169 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
83170 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
83171 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
83172 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
83173 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
83174 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
83175 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
83176 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
83177 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
83178 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
83179 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
83180 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
83181 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
83182 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
83183 +_002476_hash flash_read 3 57843 _002476_hash NULL
83184 +_002477_hash flash_write 3 62354 _002477_hash NULL
83185 +_002478_hash gather_array 3 56641 _002478_hash NULL
83186 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
83187 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
83188 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
83189 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
83190 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
83191 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
83192 +_002486_hash ieee80211_alloc_txb 1 52477 _002486_hash NULL
83193 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
83194 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
83195 +_002489_hash init_cdev 1 8274 _002489_hash NULL
83196 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
83197 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
83198 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
83199 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
83200 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
83201 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
83202 +_002496_hash options_write 3 47243 _002496_hash NULL
83203 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
83204 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
83205 +_002499_hash portnames_read 3 41958 _002499_hash NULL
83206 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
83207 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
83208 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
83209 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
83210 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
83211 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
83212 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
83213 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
83214 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
83215 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
83216 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
83217 +_002511_hash queue_reply 3 22416 _002511_hash NULL
83218 +_002512_hash Realloc 2 34961 _002512_hash NULL
83219 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
83220 +_002514_hash rtllib_alloc_txb 1 21687 _002514_hash NULL
83221 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
83222 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
83223 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
83224 +_002518_hash split 2 11691 _002518_hash NULL
83225 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
83226 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
83227 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
83228 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
83229 +_002523_hash tunables_read 3 36385 _002523_hash NULL
83230 +_002524_hash tunables_write 3 59563 _002524_hash NULL
83231 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
83232 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
83233 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
83234 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
83235 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
83236 +_002530_hash xsd_read 3 15653 _002530_hash NULL
83237 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
83238 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _002532_hash NULL
83239 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
83240 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
83241 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
83242 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
83243 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
83244 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
83245 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
83246 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
83247 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
83248 +_002546_hash compat_readv 3 30273 _002546_hash NULL
83249 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
83250 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
83251 +_002551_hash compat_writev 3 60063 _002551_hash NULL
83252 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
83253 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
83254 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
83255 +_002555_hash xd_rw 4 49020 _002555_hash NULL
83256 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
83257 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
83258 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
83259 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
83260 +_002560_hash ms_rw 4 17220 _002560_hash NULL
83261 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
83262 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
83263 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
83264 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
83265 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
83266 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
83267 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
83268 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
83269 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
83270 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
83271 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
83272 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
83273 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
83274 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
83275 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
83276 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
83277 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
83278 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
83279 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
83280 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
83281 +_002584_hash fb_read 3 33506 _002584_hash NULL
83282 +_002585_hash fb_write 3 46924 _002585_hash NULL
83283 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
83284 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
83285 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
83286 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
83287 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
83288 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
83289 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
83290 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
83291 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
83292 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
83293 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
83294 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
83295 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
83296 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
83297 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
83298 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
83299 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
83300 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
83301 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
83302 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
83303 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
83304 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
83305 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
83306 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
83307 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
83308 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
83309 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
83310 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
83311 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
83312 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
83313 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
83314 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
83315 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
83316 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
83317 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
83318 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
83319 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
83320 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
83321 +_002626_hash create_table 2 16213 _002626_hash NULL
83322 +_002627_hash mem_read 3 57631 _002627_hash NULL
83323 +_002628_hash mem_write 3 22232 _002628_hash NULL
83324 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
83325 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
83326 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
83327 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
83328 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
83329 +_002634_hash acl_alloc 1 35979 _002634_hash NULL
83330 +_002635_hash acl_alloc_stack_init 1 60630 _002635_hash NULL
83331 +_002636_hash acl_alloc_num 1-2 60778 _002636_hash NULL
83332 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
83333 new file mode 100644
83334 index 0000000..cc96254
83335 --- /dev/null
83336 +++ b/tools/gcc/size_overflow_plugin.c
83337 @@ -0,0 +1,1204 @@
83338 +/*
83339 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
83340 + * Licensed under the GPL v2, or (at your option) v3
83341 + *
83342 + * Homepage:
83343 + * http://www.grsecurity.net/~ephox/overflow_plugin/
83344 + *
83345 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
83346 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
83347 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
83348 + *
83349 + * Usage:
83350 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -Wno-missing-field-initializers -o size_overflow_plugin.so size_overflow_plugin.c
83351 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
83352 + */
83353 +
83354 +#include "gcc-plugin.h"
83355 +#include "config.h"
83356 +#include "system.h"
83357 +#include "coretypes.h"
83358 +#include "tree.h"
83359 +#include "tree-pass.h"
83360 +#include "intl.h"
83361 +#include "plugin-version.h"
83362 +#include "tm.h"
83363 +#include "toplev.h"
83364 +#include "function.h"
83365 +#include "tree-flow.h"
83366 +#include "plugin.h"
83367 +#include "gimple.h"
83368 +#include "c-common.h"
83369 +#include "diagnostic.h"
83370 +#include "cfgloop.h"
83371 +
83372 +struct size_overflow_hash {
83373 + struct size_overflow_hash *next;
83374 + const char *name;
83375 + unsigned int param;
83376 +};
83377 +
83378 +#include "size_overflow_hash.h"
83379 +
83380 +#define __unused __attribute__((__unused__))
83381 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
83382 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
83383 +#define BEFORE_STMT true
83384 +#define AFTER_STMT false
83385 +#define CREATE_NEW_VAR NULL_TREE
83386 +#define CODES_LIMIT 32
83387 +#define MAX_PARAM 10
83388 +
83389 +#if BUILDING_GCC_VERSION == 4005
83390 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
83391 +#endif
83392 +
83393 +int plugin_is_GPL_compatible;
83394 +void debug_gimple_stmt(gimple gs);
83395 +
83396 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
83397 +static tree signed_size_overflow_type;
83398 +static tree unsigned_size_overflow_type;
83399 +static tree report_size_overflow_decl;
83400 +static tree const_char_ptr_type_node;
83401 +static unsigned int handle_function(void);
83402 +
83403 +static struct plugin_info size_overflow_plugin_info = {
83404 + .version = "20120618beta",
83405 + .help = "no-size-overflow\tturn off size overflow checking\n",
83406 +};
83407 +
83408 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
83409 +{
83410 + unsigned int arg_count = type_num_arguments(*node);
83411 +
83412 + for (; args; args = TREE_CHAIN(args)) {
83413 + tree position = TREE_VALUE(args);
83414 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
83415 + error("handle_size_overflow_attribute: overflow parameter outside range.");
83416 + *no_add_attrs = true;
83417 + }
83418 + }
83419 + return NULL_TREE;
83420 +}
83421 +
83422 +static struct attribute_spec no_size_overflow_attr = {
83423 + .name = "size_overflow",
83424 + .min_length = 1,
83425 + .max_length = -1,
83426 + .decl_required = false,
83427 + .type_required = true,
83428 + .function_type_required = true,
83429 + .handler = handle_size_overflow_attribute,
83430 +#if BUILDING_GCC_VERSION >= 4007
83431 + .affects_type_identity = false
83432 +#endif
83433 +};
83434 +
83435 +static void register_attributes(void __unused *event_data, void __unused *data)
83436 +{
83437 + register_attribute(&no_size_overflow_attr);
83438 +}
83439 +
83440 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
83441 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
83442 +{
83443 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
83444 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
83445 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
83446 +
83447 + const unsigned int m = 0x57559429;
83448 + const unsigned int n = 0x5052acdb;
83449 + const unsigned int *key4 = (const unsigned int *)key;
83450 + unsigned int h = len;
83451 + unsigned int k = len + seed + n;
83452 + unsigned long long p;
83453 +
83454 + while (len >= 8) {
83455 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
83456 + len -= 8;
83457 + }
83458 + if (len >= 4) {
83459 + cwmixb(key4[0]) key4 += 1;
83460 + len -= 4;
83461 + }
83462 + if (len)
83463 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
83464 + cwmixb(h ^ (k + n));
83465 + return k ^ h;
83466 +
83467 +#undef cwfold
83468 +#undef cwmixa
83469 +#undef cwmixb
83470 +}
83471 +
83472 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
83473 +{
83474 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
83475 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
83476 + return fn ^ codes;
83477 +}
83478 +
83479 +static inline tree get_original_function_decl(tree fndecl)
83480 +{
83481 + if (DECL_ABSTRACT_ORIGIN(fndecl))
83482 + return DECL_ABSTRACT_ORIGIN(fndecl);
83483 + return fndecl;
83484 +}
83485 +
83486 +static inline gimple get_def_stmt(tree node)
83487 +{
83488 + gcc_assert(TREE_CODE(node) == SSA_NAME);
83489 + return SSA_NAME_DEF_STMT(node);
83490 +}
83491 +
83492 +static unsigned char get_tree_code(tree type)
83493 +{
83494 + switch (TREE_CODE(type)) {
83495 + case ARRAY_TYPE:
83496 + return 0;
83497 + case BOOLEAN_TYPE:
83498 + return 1;
83499 + case ENUMERAL_TYPE:
83500 + return 2;
83501 + case FUNCTION_TYPE:
83502 + return 3;
83503 + case INTEGER_TYPE:
83504 + return 4;
83505 + case POINTER_TYPE:
83506 + return 5;
83507 + case RECORD_TYPE:
83508 + return 6;
83509 + case UNION_TYPE:
83510 + return 7;
83511 + case VOID_TYPE:
83512 + return 8;
83513 + case REAL_TYPE:
83514 + return 9;
83515 + case VECTOR_TYPE:
83516 + return 10;
83517 + case REFERENCE_TYPE:
83518 + return 11;
83519 + default:
83520 + debug_tree(type);
83521 + gcc_unreachable();
83522 + }
83523 +}
83524 +
83525 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
83526 +{
83527 + gcc_assert(type != NULL_TREE);
83528 +
83529 + while (type && len < CODES_LIMIT) {
83530 + tree_codes[len] = get_tree_code(type);
83531 + len++;
83532 + type = TREE_TYPE(type);
83533 + }
83534 + return len;
83535 +}
83536 +
83537 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
83538 +{
83539 + tree arg, result, type = TREE_TYPE(fndecl);
83540 + enum tree_code code = TREE_CODE(type);
83541 + size_t len = 0;
83542 +
83543 + gcc_assert(code == FUNCTION_TYPE);
83544 +
83545 + arg = TYPE_ARG_TYPES(type);
83546 + // skip builtins __builtin_constant_p
83547 + if (!arg && DECL_BUILT_IN(fndecl))
83548 + return 0;
83549 + gcc_assert(arg != NULL_TREE);
83550 +
83551 + if (TREE_CODE_CLASS(code) == tcc_type)
83552 + result = type;
83553 + else
83554 + result = DECL_RESULT(fndecl);
83555 +
83556 + gcc_assert(result != NULL_TREE);
83557 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
83558 +
83559 + while (arg && len < CODES_LIMIT) {
83560 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
83561 + arg = TREE_CHAIN(arg);
83562 + }
83563 +
83564 + gcc_assert(len != 0);
83565 + return len;
83566 +}
83567 +
83568 +static struct size_overflow_hash *get_function_hash(tree fndecl)
83569 +{
83570 + unsigned int hash;
83571 + struct size_overflow_hash *entry;
83572 + unsigned char tree_codes[CODES_LIMIT];
83573 + size_t len;
83574 + const char *func_name = NAME(fndecl);
83575 +
83576 + len = get_function_decl(fndecl, tree_codes);
83577 + if (len == 0)
83578 + return NULL;
83579 +
83580 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
83581 +
83582 + entry = size_overflow_hash[hash];
83583 + while (entry) {
83584 + if (!strcmp(entry->name, func_name))
83585 + return entry;
83586 + entry = entry->next;
83587 + }
83588 +
83589 + return NULL;
83590 +}
83591 +
83592 +static void check_arg_type(tree var)
83593 +{
83594 + tree type = TREE_TYPE(var);
83595 + enum tree_code code = TREE_CODE(type);
83596 +
83597 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
83598 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
83599 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
83600 +}
83601 +
83602 +static int find_arg_number(tree arg, tree func)
83603 +{
83604 + tree var;
83605 + bool match = false;
83606 + unsigned int argnum = 1;
83607 +
83608 + if (TREE_CODE(arg) == SSA_NAME)
83609 + arg = SSA_NAME_VAR(arg);
83610 +
83611 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
83612 + if (strcmp(NAME(arg), NAME(var))) {
83613 + argnum++;
83614 + continue;
83615 + }
83616 + check_arg_type(var);
83617 +
83618 + match = true;
83619 + break;
83620 + }
83621 + if (!match) {
83622 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
83623 + return 0;
83624 + }
83625 + return argnum;
83626 +}
83627 +
83628 +static void print_missing_msg(tree func, unsigned int argnum)
83629 +{
83630 + unsigned int new_hash;
83631 + size_t len;
83632 + unsigned char tree_codes[CODES_LIMIT];
83633 + location_t loc = DECL_SOURCE_LOCATION(func);
83634 + const char *curfunc = NAME(func);
83635 +
83636 + len = get_function_decl(func, tree_codes);
83637 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
83638 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
83639 +}
83640 +
83641 +static void check_missing_attribute(tree arg)
83642 +{
83643 + tree type, func = get_original_function_decl(current_function_decl);
83644 + unsigned int argnum;
83645 + struct size_overflow_hash *hash;
83646 +
83647 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
83648 +
83649 + type = TREE_TYPE(arg);
83650 + // skip function pointers
83651 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
83652 + return;
83653 +
83654 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
83655 + return;
83656 +
83657 + argnum = find_arg_number(arg, func);
83658 + if (argnum == 0)
83659 + return;
83660 +
83661 + hash = get_function_hash(func);
83662 + if (!hash || !(hash->param & (1U << argnum)))
83663 + print_missing_msg(func, argnum);
83664 +}
83665 +
83666 +static tree create_new_var(tree type)
83667 +{
83668 + tree new_var = create_tmp_var(type, "cicus");
83669 +
83670 + add_referenced_var(new_var);
83671 + mark_sym_for_renaming(new_var);
83672 + return new_var;
83673 +}
83674 +
83675 +static bool is_bool(tree node)
83676 +{
83677 + tree type;
83678 +
83679 + if (node == NULL_TREE)
83680 + return false;
83681 +
83682 + type = TREE_TYPE(node);
83683 + if (!INTEGRAL_TYPE_P(type))
83684 + return false;
83685 + if (TREE_CODE(type) == BOOLEAN_TYPE)
83686 + return true;
83687 + if (TYPE_PRECISION(type) == 1)
83688 + return true;
83689 + return false;
83690 +}
83691 +
83692 +static tree cast_a_tree(tree type, tree var)
83693 +{
83694 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
83695 + gcc_assert(fold_convertible_p(type, var));
83696 +
83697 + return fold_convert(type, var);
83698 +}
83699 +
83700 +static tree signed_cast(tree var)
83701 +{
83702 + return cast_a_tree(signed_size_overflow_type, var);
83703 +}
83704 +
83705 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
83706 +{
83707 + gimple assign;
83708 +
83709 + if (new_var == CREATE_NEW_VAR)
83710 + new_var = create_new_var(type);
83711 +
83712 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
83713 + gimple_set_location(assign, loc);
83714 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
83715 +
83716 + return assign;
83717 +}
83718 +
83719 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
83720 +{
83721 + tree oldstmt_rhs1;
83722 + enum tree_code code;
83723 + gimple stmt;
83724 + gimple_stmt_iterator gsi;
83725 +
83726 + if (!*potentionally_overflowed)
83727 + return NULL_TREE;
83728 +
83729 + if (rhs1 == NULL_TREE) {
83730 + debug_gimple_stmt(oldstmt);
83731 + error("create_assign: rhs1 is NULL_TREE");
83732 + gcc_unreachable();
83733 + }
83734 +
83735 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
83736 + code = TREE_CODE(oldstmt_rhs1);
83737 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
83738 + check_missing_attribute(oldstmt_rhs1);
83739 +
83740 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
83741 + gsi = gsi_for_stmt(oldstmt);
83742 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
83743 + basic_block next_bb, cur_bb;
83744 + edge e;
83745 +
83746 + gcc_assert(before == false);
83747 + gcc_assert(stmt_can_throw_internal(oldstmt));
83748 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
83749 + gcc_assert(!gsi_end_p(gsi));
83750 +
83751 + cur_bb = gimple_bb(oldstmt);
83752 + next_bb = cur_bb->next_bb;
83753 + e = find_edge(cur_bb, next_bb);
83754 + gcc_assert(e != NULL);
83755 + gcc_assert(e->flags & EDGE_FALLTHRU);
83756 +
83757 + gsi = gsi_after_labels(next_bb);
83758 + gcc_assert(!gsi_end_p(gsi));
83759 + before = true;
83760 + }
83761 + if (before)
83762 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
83763 + else
83764 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
83765 + update_stmt(stmt);
83766 + pointer_set_insert(visited, oldstmt);
83767 + return gimple_get_lhs(stmt);
83768 +}
83769 +
83770 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
83771 +{
83772 + tree new_var, lhs = gimple_get_lhs(oldstmt);
83773 + gimple stmt;
83774 + gimple_stmt_iterator gsi;
83775 +
83776 + if (!*potentionally_overflowed)
83777 + return NULL_TREE;
83778 +
83779 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
83780 + rhs1 = gimple_assign_rhs1(oldstmt);
83781 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
83782 + }
83783 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
83784 + rhs2 = gimple_assign_rhs2(oldstmt);
83785 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
83786 + }
83787 +
83788 + stmt = gimple_copy(oldstmt);
83789 + gimple_set_location(stmt, gimple_location(oldstmt));
83790 +
83791 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
83792 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
83793 +
83794 + if (is_bool(lhs))
83795 + new_var = SSA_NAME_VAR(lhs);
83796 + else
83797 + new_var = create_new_var(signed_size_overflow_type);
83798 + new_var = make_ssa_name(new_var, stmt);
83799 + gimple_set_lhs(stmt, new_var);
83800 +
83801 + if (rhs1 != NULL_TREE) {
83802 + if (!gimple_assign_cast_p(oldstmt))
83803 + rhs1 = signed_cast(rhs1);
83804 + gimple_assign_set_rhs1(stmt, rhs1);
83805 + }
83806 +
83807 + if (rhs2 != NULL_TREE)
83808 + gimple_assign_set_rhs2(stmt, rhs2);
83809 +#if BUILDING_GCC_VERSION >= 4007
83810 + if (rhs3 != NULL_TREE)
83811 + gimple_assign_set_rhs3(stmt, rhs3);
83812 +#endif
83813 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
83814 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
83815 +
83816 + gsi = gsi_for_stmt(oldstmt);
83817 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
83818 + update_stmt(stmt);
83819 + pointer_set_insert(visited, oldstmt);
83820 + return gimple_get_lhs(stmt);
83821 +}
83822 +
83823 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
83824 +{
83825 + basic_block bb;
83826 + gimple phi;
83827 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
83828 +
83829 + bb = gsi_bb(gsi);
83830 +
83831 + phi = create_phi_node(var, bb);
83832 + gsi = gsi_last(phi_nodes(bb));
83833 + gsi_remove(&gsi, false);
83834 +
83835 + gsi = gsi_for_stmt(oldstmt);
83836 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
83837 + gimple_set_bb(phi, bb);
83838 + return phi;
83839 +}
83840 +
83841 +static basic_block create_a_first_bb(void)
83842 +{
83843 + basic_block first_bb;
83844 +
83845 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83846 + if (dom_info_available_p(CDI_DOMINATORS))
83847 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
83848 + return first_bb;
83849 +}
83850 +
83851 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
83852 +{
83853 + basic_block bb;
83854 + gimple newstmt, def_stmt;
83855 + gimple_stmt_iterator gsi;
83856 +
83857 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
83858 + if (TREE_CODE(arg) == SSA_NAME) {
83859 + def_stmt = get_def_stmt(arg);
83860 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
83861 + gsi = gsi_for_stmt(def_stmt);
83862 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
83863 + return newstmt;
83864 + }
83865 + }
83866 +
83867 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
83868 + if (bb->index == 0)
83869 + bb = create_a_first_bb();
83870 + gsi = gsi_after_labels(bb);
83871 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
83872 + return newstmt;
83873 +}
83874 +
83875 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
83876 +{
83877 + gimple newstmt;
83878 + gimple_stmt_iterator gsi;
83879 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
83880 + gimple def_newstmt = get_def_stmt(new_rhs);
83881 +
83882 + gsi_insert = gsi_insert_after;
83883 + gsi = gsi_for_stmt(def_newstmt);
83884 +
83885 + switch (gimple_code(get_def_stmt(arg))) {
83886 + case GIMPLE_PHI:
83887 + newstmt = gimple_build_assign(new_var, new_rhs);
83888 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
83889 + gsi_insert = gsi_insert_before;
83890 + break;
83891 + case GIMPLE_ASM:
83892 + case GIMPLE_CALL:
83893 + newstmt = gimple_build_assign(new_var, new_rhs);
83894 + break;
83895 + case GIMPLE_ASSIGN:
83896 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
83897 + break;
83898 + default:
83899 + /* unknown gimple_code (handle_build_new_phi_arg) */
83900 + gcc_unreachable();
83901 + }
83902 +
83903 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
83904 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
83905 + update_stmt(newstmt);
83906 + return newstmt;
83907 +}
83908 +
83909 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
83910 +{
83911 + gimple newstmt;
83912 + tree new_rhs;
83913 +
83914 + new_rhs = expand(visited, potentionally_overflowed, arg);
83915 +
83916 + if (new_rhs == NULL_TREE)
83917 + return NULL_TREE;
83918 +
83919 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
83920 + return gimple_get_lhs(newstmt);
83921 +}
83922 +
83923 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
83924 +{
83925 + gimple phi;
83926 + tree new_var = create_new_var(signed_size_overflow_type);
83927 + unsigned int i, n = gimple_phi_num_args(oldstmt);
83928 +
83929 + pointer_set_insert(visited, oldstmt);
83930 + phi = overflow_create_phi_node(oldstmt, new_var);
83931 + for (i = 0; i < n; i++) {
83932 + tree arg, lhs;
83933 +
83934 + arg = gimple_phi_arg_def(oldstmt, i);
83935 + if (is_gimple_constant(arg))
83936 + arg = signed_cast(arg);
83937 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
83938 + if (lhs == NULL_TREE)
83939 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
83940 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
83941 + }
83942 +
83943 + update_stmt(phi);
83944 + return gimple_phi_result(phi);
83945 +}
83946 +
83947 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
83948 +{
83949 + gimple def_stmt = get_def_stmt(var);
83950 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
83951 +
83952 + *potentionally_overflowed = true;
83953 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
83954 + if (new_rhs1 == NULL_TREE) {
83955 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
83956 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
83957 + else
83958 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
83959 + }
83960 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
83961 +}
83962 +
83963 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
83964 +{
83965 + gimple def_stmt = get_def_stmt(var);
83966 + tree rhs1 = gimple_assign_rhs1(def_stmt);
83967 +
83968 + if (is_gimple_constant(rhs1))
83969 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast(rhs1), NULL_TREE, NULL_TREE);
83970 +
83971 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
83972 + switch (TREE_CODE(rhs1)) {
83973 + case SSA_NAME:
83974 + return handle_unary_rhs(visited, potentionally_overflowed, var);
83975 +
83976 + case ARRAY_REF:
83977 + case BIT_FIELD_REF:
83978 + case ADDR_EXPR:
83979 + case COMPONENT_REF:
83980 + case INDIRECT_REF:
83981 +#if BUILDING_GCC_VERSION >= 4006
83982 + case MEM_REF:
83983 +#endif
83984 + case PARM_DECL:
83985 + case TARGET_MEM_REF:
83986 + case VAR_DECL:
83987 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
83988 +
83989 + default:
83990 + debug_gimple_stmt(def_stmt);
83991 + debug_tree(rhs1);
83992 + gcc_unreachable();
83993 + }
83994 +}
83995 +
83996 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
83997 +{
83998 + gimple cond_stmt;
83999 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
84000 +
84001 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
84002 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
84003 + update_stmt(cond_stmt);
84004 +}
84005 +
84006 +static tree create_string_param(tree string)
84007 +{
84008 + tree i_type, a_type;
84009 + int length = TREE_STRING_LENGTH(string);
84010 +
84011 + gcc_assert(length > 0);
84012 +
84013 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
84014 + a_type = build_array_type(char_type_node, i_type);
84015 +
84016 + TREE_TYPE(string) = a_type;
84017 + TREE_CONSTANT(string) = 1;
84018 + TREE_READONLY(string) = 1;
84019 +
84020 + return build1(ADDR_EXPR, ptr_type_node, string);
84021 +}
84022 +
84023 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
84024 +{
84025 + gimple func_stmt, def_stmt;
84026 + tree current_func, loc_file, loc_line;
84027 + expanded_location xloc;
84028 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
84029 +
84030 + def_stmt = get_def_stmt(arg);
84031 + xloc = expand_location(gimple_location(def_stmt));
84032 +
84033 + if (!gimple_has_location(def_stmt)) {
84034 + xloc = expand_location(gimple_location(stmt));
84035 + if (!gimple_has_location(stmt))
84036 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
84037 + }
84038 +
84039 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
84040 +
84041 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
84042 + loc_file = create_string_param(loc_file);
84043 +
84044 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
84045 + current_func = create_string_param(current_func);
84046 +
84047 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
84048 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
84049 +
84050 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
84051 +}
84052 +
84053 +static void __unused print_the_code_insertions(gimple stmt)
84054 +{
84055 + location_t loc = gimple_location(stmt);
84056 +
84057 + inform(loc, "Integer size_overflow check applied here.");
84058 +}
84059 +
84060 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
84061 +{
84062 + basic_block cond_bb, join_bb, bb_true;
84063 + edge e;
84064 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84065 +
84066 + cond_bb = gimple_bb(stmt);
84067 + gsi_prev(&gsi);
84068 + if (gsi_end_p(gsi))
84069 + e = split_block_after_labels(cond_bb);
84070 + else
84071 + e = split_block(cond_bb, gsi_stmt(gsi));
84072 + cond_bb = e->src;
84073 + join_bb = e->dest;
84074 + e->flags = EDGE_FALSE_VALUE;
84075 + e->probability = REG_BR_PROB_BASE;
84076 +
84077 + bb_true = create_empty_bb(cond_bb);
84078 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
84079 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
84080 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
84081 +
84082 + if (dom_info_available_p(CDI_DOMINATORS)) {
84083 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
84084 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
84085 + }
84086 +
84087 + if (current_loops != NULL) {
84088 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
84089 + add_bb_to_loop(bb_true, cond_bb->loop_father);
84090 + }
84091 +
84092 + insert_cond(cond_bb, arg, cond_code, type_value);
84093 + insert_cond_result(bb_true, stmt, arg);
84094 +
84095 +// print_the_code_insertions(stmt);
84096 +}
84097 +
84098 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
84099 +{
84100 + gimple ucast_stmt;
84101 + gimple_stmt_iterator gsi;
84102 + location_t loc = gimple_location(stmt);
84103 +
84104 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
84105 + gsi = gsi_for_stmt(stmt);
84106 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
84107 + return ucast_stmt;
84108 +}
84109 +
84110 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
84111 +{
84112 + tree type_max, type_min, rhs_type = TREE_TYPE(rhs);
84113 + gimple ucast_stmt;
84114 +
84115 + if (!*potentionally_overflowed)
84116 + return;
84117 +
84118 + if (TYPE_UNSIGNED(rhs_type)) {
84119 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
84120 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
84121 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
84122 + } else {
84123 + type_max = signed_cast(TYPE_MAX_VALUE(rhs_type));
84124 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
84125 +
84126 + type_min = signed_cast(TYPE_MIN_VALUE(rhs_type));
84127 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
84128 + }
84129 +}
84130 +
84131 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
84132 +{
84133 + gimple assign;
84134 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84135 + tree origtype = TREE_TYPE(orig_rhs);
84136 +
84137 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
84138 +
84139 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
84140 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84141 + update_stmt(assign);
84142 + return gimple_get_lhs(assign);
84143 +}
84144 +
84145 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var, tree orig_rhs, tree var_rhs, tree new_rhs1, tree new_rhs2, void (*gimple_assign_set_rhs)(gimple, tree))
84146 +{
84147 + tree new_rhs;
84148 +
84149 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
84150 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84151 +
84152 + if (var_rhs == NULL_TREE)
84153 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84154 +
84155 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
84156 + gimple_assign_set_rhs(def_stmt, new_rhs);
84157 + update_stmt(def_stmt);
84158 +
84159 + check_size_overflow(def_stmt, var_rhs, orig_rhs, potentionally_overflowed);
84160 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84161 +}
84162 +
84163 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84164 +{
84165 + tree rhs1, rhs2;
84166 + gimple def_stmt = get_def_stmt(var);
84167 + tree new_rhs1 = NULL_TREE;
84168 + tree new_rhs2 = NULL_TREE;
84169 +
84170 + rhs1 = gimple_assign_rhs1(def_stmt);
84171 + rhs2 = gimple_assign_rhs2(def_stmt);
84172 +
84173 + /* no DImode/TImode division in the 32/64 bit kernel */
84174 + switch (gimple_assign_rhs_code(def_stmt)) {
84175 + case RDIV_EXPR:
84176 + case TRUNC_DIV_EXPR:
84177 + case CEIL_DIV_EXPR:
84178 + case FLOOR_DIV_EXPR:
84179 + case ROUND_DIV_EXPR:
84180 + case TRUNC_MOD_EXPR:
84181 + case CEIL_MOD_EXPR:
84182 + case FLOOR_MOD_EXPR:
84183 + case ROUND_MOD_EXPR:
84184 + case EXACT_DIV_EXPR:
84185 + case POINTER_PLUS_EXPR:
84186 + case BIT_AND_EXPR:
84187 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84188 + default:
84189 + break;
84190 + }
84191 +
84192 + *potentionally_overflowed = true;
84193 +
84194 + if (TREE_CODE(rhs1) == SSA_NAME)
84195 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
84196 + if (TREE_CODE(rhs2) == SSA_NAME)
84197 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
84198 +
84199 + if (is_gimple_constant(rhs2))
84200 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, new_rhs1, signed_cast(rhs2), &gimple_assign_set_rhs1);
84201 +
84202 + if (is_gimple_constant(rhs1))
84203 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, new_rhs2, signed_cast(rhs1), new_rhs2, &gimple_assign_set_rhs2);
84204 +
84205 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84206 +}
84207 +
84208 +#if BUILDING_GCC_VERSION >= 4007
84209 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
84210 +{
84211 + if (is_gimple_constant(rhs))
84212 + return signed_cast(rhs);
84213 + if (TREE_CODE(rhs) != SSA_NAME)
84214 + return NULL_TREE;
84215 + return expand(visited, potentionally_overflowed, rhs);
84216 +}
84217 +
84218 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84219 +{
84220 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
84221 + gimple def_stmt = get_def_stmt(var);
84222 +
84223 + *potentionally_overflowed = true;
84224 +
84225 + rhs1 = gimple_assign_rhs1(def_stmt);
84226 + rhs2 = gimple_assign_rhs2(def_stmt);
84227 + rhs3 = gimple_assign_rhs3(def_stmt);
84228 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
84229 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
84230 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
84231 +
84232 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
84233 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
84234 + error("handle_ternary_ops: unknown rhs");
84235 + gcc_unreachable();
84236 +}
84237 +#endif
84238 +
84239 +static void set_size_overflow_type(tree node)
84240 +{
84241 + switch (TYPE_MODE(TREE_TYPE(node))) {
84242 + case SImode:
84243 + signed_size_overflow_type = intDI_type_node;
84244 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84245 + break;
84246 + case DImode:
84247 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
84248 + signed_size_overflow_type = intDI_type_node;
84249 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84250 + } else {
84251 + signed_size_overflow_type = intTI_type_node;
84252 + unsigned_size_overflow_type = unsigned_intTI_type_node;
84253 + }
84254 + break;
84255 + default:
84256 + error("set_size_overflow_type: unsupported gcc configuration.");
84257 + gcc_unreachable();
84258 + }
84259 +}
84260 +
84261 +static tree expand_visited(gimple def_stmt)
84262 +{
84263 + gimple tmp;
84264 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
84265 +
84266 + gsi_next(&gsi);
84267 + tmp = gsi_stmt(gsi);
84268 + switch (gimple_code(tmp)) {
84269 + case GIMPLE_ASSIGN:
84270 + return gimple_get_lhs(tmp);
84271 + case GIMPLE_PHI:
84272 + return gimple_phi_result(tmp);
84273 + case GIMPLE_CALL:
84274 + return gimple_call_lhs(tmp);
84275 + default:
84276 + return NULL_TREE;
84277 + }
84278 +}
84279 +
84280 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84281 +{
84282 + gimple def_stmt;
84283 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
84284 +
84285 + if (is_gimple_constant(var))
84286 + return NULL_TREE;
84287 +
84288 + if (TREE_CODE(var) == ADDR_EXPR)
84289 + return NULL_TREE;
84290 +
84291 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
84292 + if (code != INTEGER_TYPE)
84293 + return NULL_TREE;
84294 +
84295 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
84296 + check_missing_attribute(var);
84297 + return NULL_TREE;
84298 + }
84299 +
84300 + def_stmt = get_def_stmt(var);
84301 +
84302 + if (!def_stmt)
84303 + return NULL_TREE;
84304 +
84305 + if (pointer_set_contains(visited, def_stmt))
84306 + return expand_visited(def_stmt);
84307 +
84308 + switch (gimple_code(def_stmt)) {
84309 + case GIMPLE_NOP:
84310 + check_missing_attribute(var);
84311 + return NULL_TREE;
84312 + case GIMPLE_PHI:
84313 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
84314 + case GIMPLE_CALL:
84315 + case GIMPLE_ASM:
84316 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84317 + case GIMPLE_ASSIGN:
84318 + switch (gimple_num_ops(def_stmt)) {
84319 + case 2:
84320 + return handle_unary_ops(visited, potentionally_overflowed, var);
84321 + case 3:
84322 + return handle_binary_ops(visited, potentionally_overflowed, var);
84323 +#if BUILDING_GCC_VERSION >= 4007
84324 + case 4:
84325 + return handle_ternary_ops(visited, potentionally_overflowed, var);
84326 +#endif
84327 + }
84328 + default:
84329 + debug_gimple_stmt(def_stmt);
84330 + error("expand: unknown gimple code");
84331 + gcc_unreachable();
84332 + }
84333 +}
84334 +
84335 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
84336 +{
84337 + gimple assign;
84338 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84339 + tree origtype = TREE_TYPE(origarg);
84340 +
84341 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
84342 +
84343 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
84344 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84345 + update_stmt(assign);
84346 +
84347 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
84348 + update_stmt(stmt);
84349 +}
84350 +
84351 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
84352 +{
84353 + const char *origid;
84354 + tree arg, origarg;
84355 +
84356 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
84357 + gcc_assert(gimple_call_num_args(stmt) > argnum);
84358 + return gimple_call_arg(stmt, argnum);
84359 + }
84360 +
84361 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
84362 + while (origarg && argnum) {
84363 + argnum--;
84364 + origarg = TREE_CHAIN(origarg);
84365 + }
84366 +
84367 + gcc_assert(argnum == 0);
84368 +
84369 + gcc_assert(origarg != NULL_TREE);
84370 + origid = NAME(origarg);
84371 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
84372 + if (!strcmp(origid, NAME(arg)))
84373 + return arg;
84374 + }
84375 + return NULL_TREE;
84376 +}
84377 +
84378 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
84379 +{
84380 + struct pointer_set_t *visited;
84381 + tree arg, newarg;
84382 + bool potentionally_overflowed;
84383 +
84384 + arg = get_function_arg(argnum, stmt, fndecl);
84385 + if (arg == NULL_TREE)
84386 + return;
84387 +
84388 + if (is_gimple_constant(arg))
84389 + return;
84390 + if (TREE_CODE(arg) != SSA_NAME)
84391 + return;
84392 +
84393 + check_arg_type(arg);
84394 +
84395 + set_size_overflow_type(arg);
84396 +
84397 + visited = pointer_set_create();
84398 + potentionally_overflowed = false;
84399 + newarg = expand(visited, &potentionally_overflowed, arg);
84400 + pointer_set_destroy(visited);
84401 +
84402 + if (newarg == NULL_TREE || !potentionally_overflowed)
84403 + return;
84404 +
84405 + change_function_arg(stmt, arg, argnum, newarg);
84406 +
84407 + check_size_overflow(stmt, newarg, arg, &potentionally_overflowed);
84408 +}
84409 +
84410 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
84411 +{
84412 + tree p = TREE_VALUE(attr);
84413 + do {
84414 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
84415 + p = TREE_CHAIN(p);
84416 + } while (p);
84417 +}
84418 +
84419 +static void handle_function_by_hash(gimple stmt, tree fndecl)
84420 +{
84421 + tree orig_fndecl;
84422 + unsigned int num;
84423 + struct size_overflow_hash *hash;
84424 +
84425 + orig_fndecl = get_original_function_decl(fndecl);
84426 + hash = get_function_hash(orig_fndecl);
84427 + if (!hash)
84428 + return;
84429 +
84430 + for (num = 1; num <= MAX_PARAM; num++)
84431 + if (hash->param & (1U << num))
84432 + handle_function_arg(stmt, fndecl, num - 1);
84433 +}
84434 +
84435 +static unsigned int handle_function(void)
84436 +{
84437 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
84438 + int saved_last_basic_block = last_basic_block;
84439 +
84440 + do {
84441 + gimple_stmt_iterator gsi;
84442 + basic_block next = bb->next_bb;
84443 +
84444 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84445 + tree fndecl, attr;
84446 + gimple stmt = gsi_stmt(gsi);
84447 +
84448 + if (!(is_gimple_call(stmt)))
84449 + continue;
84450 + fndecl = gimple_call_fndecl(stmt);
84451 + if (fndecl == NULL_TREE)
84452 + continue;
84453 + if (gimple_call_num_args(stmt) == 0)
84454 + continue;
84455 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
84456 + if (!attr || !TREE_VALUE(attr))
84457 + handle_function_by_hash(stmt, fndecl);
84458 + else
84459 + handle_function_by_attribute(stmt, attr, fndecl);
84460 + gsi = gsi_for_stmt(stmt);
84461 + }
84462 + bb = next;
84463 + } while (bb && bb->index <= saved_last_basic_block);
84464 + return 0;
84465 +}
84466 +
84467 +static struct gimple_opt_pass size_overflow_pass = {
84468 + .pass = {
84469 + .type = GIMPLE_PASS,
84470 + .name = "size_overflow",
84471 + .gate = NULL,
84472 + .execute = handle_function,
84473 + .sub = NULL,
84474 + .next = NULL,
84475 + .static_pass_number = 0,
84476 + .tv_id = TV_NONE,
84477 + .properties_required = PROP_cfg | PROP_referenced_vars,
84478 + .properties_provided = 0,
84479 + .properties_destroyed = 0,
84480 + .todo_flags_start = 0,
84481 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
84482 + }
84483 +};
84484 +
84485 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
84486 +{
84487 + tree fntype;
84488 +
84489 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
84490 +
84491 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
84492 + fntype = build_function_type_list(void_type_node,
84493 + const_char_ptr_type_node,
84494 + unsigned_type_node,
84495 + const_char_ptr_type_node,
84496 + NULL_TREE);
84497 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
84498 +
84499 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
84500 + TREE_PUBLIC(report_size_overflow_decl) = 1;
84501 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
84502 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
84503 +}
84504 +
84505 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84506 +{
84507 + int i;
84508 + const char * const plugin_name = plugin_info->base_name;
84509 + const int argc = plugin_info->argc;
84510 + const struct plugin_argument * const argv = plugin_info->argv;
84511 + bool enable = true;
84512 +
84513 + struct register_pass_info size_overflow_pass_info = {
84514 + .pass = &size_overflow_pass.pass,
84515 + .reference_pass_name = "ssa",
84516 + .ref_pass_instance_number = 1,
84517 + .pos_op = PASS_POS_INSERT_AFTER
84518 + };
84519 +
84520 + if (!plugin_default_version_check(version, &gcc_version)) {
84521 + error(G_("incompatible gcc/plugin versions"));
84522 + return 1;
84523 + }
84524 +
84525 + for (i = 0; i < argc; ++i) {
84526 + if (!strcmp(argv[i].key, "no-size-overflow")) {
84527 + enable = false;
84528 + continue;
84529 + }
84530 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84531 + }
84532 +
84533 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
84534 + if (enable) {
84535 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84536 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
84537 + }
84538 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84539 +
84540 + return 0;
84541 +}
84542 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
84543 new file mode 100644
84544 index 0000000..b87ec9d
84545 --- /dev/null
84546 +++ b/tools/gcc/stackleak_plugin.c
84547 @@ -0,0 +1,313 @@
84548 +/*
84549 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84550 + * Licensed under the GPL v2
84551 + *
84552 + * Note: the choice of the license means that the compilation process is
84553 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84554 + * but for the kernel it doesn't matter since it doesn't link against
84555 + * any of the gcc libraries
84556 + *
84557 + * gcc plugin to help implement various PaX features
84558 + *
84559 + * - track lowest stack pointer
84560 + *
84561 + * TODO:
84562 + * - initialize all local variables
84563 + *
84564 + * BUGS:
84565 + * - none known
84566 + */
84567 +#include "gcc-plugin.h"
84568 +#include "config.h"
84569 +#include "system.h"
84570 +#include "coretypes.h"
84571 +#include "tree.h"
84572 +#include "tree-pass.h"
84573 +#include "flags.h"
84574 +#include "intl.h"
84575 +#include "toplev.h"
84576 +#include "plugin.h"
84577 +//#include "expr.h" where are you...
84578 +#include "diagnostic.h"
84579 +#include "plugin-version.h"
84580 +#include "tm.h"
84581 +#include "function.h"
84582 +#include "basic-block.h"
84583 +#include "gimple.h"
84584 +#include "rtl.h"
84585 +#include "emit-rtl.h"
84586 +
84587 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84588 +
84589 +int plugin_is_GPL_compatible;
84590 +
84591 +static int track_frame_size = -1;
84592 +static const char track_function[] = "pax_track_stack";
84593 +static const char check_function[] = "pax_check_alloca";
84594 +static bool init_locals;
84595 +
84596 +static struct plugin_info stackleak_plugin_info = {
84597 + .version = "201203140940",
84598 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
84599 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
84600 +};
84601 +
84602 +static bool gate_stackleak_track_stack(void);
84603 +static unsigned int execute_stackleak_tree_instrument(void);
84604 +static unsigned int execute_stackleak_final(void);
84605 +
84606 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
84607 + .pass = {
84608 + .type = GIMPLE_PASS,
84609 + .name = "stackleak_tree_instrument",
84610 + .gate = gate_stackleak_track_stack,
84611 + .execute = execute_stackleak_tree_instrument,
84612 + .sub = NULL,
84613 + .next = NULL,
84614 + .static_pass_number = 0,
84615 + .tv_id = TV_NONE,
84616 + .properties_required = PROP_gimple_leh | PROP_cfg,
84617 + .properties_provided = 0,
84618 + .properties_destroyed = 0,
84619 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84620 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84621 + }
84622 +};
84623 +
84624 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
84625 + .pass = {
84626 + .type = RTL_PASS,
84627 + .name = "stackleak_final",
84628 + .gate = gate_stackleak_track_stack,
84629 + .execute = execute_stackleak_final,
84630 + .sub = NULL,
84631 + .next = NULL,
84632 + .static_pass_number = 0,
84633 + .tv_id = TV_NONE,
84634 + .properties_required = 0,
84635 + .properties_provided = 0,
84636 + .properties_destroyed = 0,
84637 + .todo_flags_start = 0,
84638 + .todo_flags_finish = TODO_dump_func
84639 + }
84640 +};
84641 +
84642 +static bool gate_stackleak_track_stack(void)
84643 +{
84644 + return track_frame_size >= 0;
84645 +}
84646 +
84647 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
84648 +{
84649 + gimple check_alloca;
84650 + tree fntype, fndecl, alloca_size;
84651 +
84652 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
84653 + fndecl = build_fn_decl(check_function, fntype);
84654 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84655 +
84656 + // insert call to void pax_check_alloca(unsigned long size)
84657 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
84658 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
84659 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
84660 +}
84661 +
84662 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
84663 +{
84664 + gimple track_stack;
84665 + tree fntype, fndecl;
84666 +
84667 + fntype = build_function_type_list(void_type_node, NULL_TREE);
84668 + fndecl = build_fn_decl(track_function, fntype);
84669 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84670 +
84671 + // insert call to void pax_track_stack(void)
84672 + track_stack = gimple_build_call(fndecl, 0);
84673 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
84674 +}
84675 +
84676 +#if BUILDING_GCC_VERSION == 4005
84677 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
84678 +{
84679 + tree fndecl;
84680 +
84681 + if (!is_gimple_call(stmt))
84682 + return false;
84683 + fndecl = gimple_call_fndecl(stmt);
84684 + if (!fndecl)
84685 + return false;
84686 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
84687 + return false;
84688 +// print_node(stderr, "pax", fndecl, 4);
84689 + return DECL_FUNCTION_CODE(fndecl) == code;
84690 +}
84691 +#endif
84692 +
84693 +static bool is_alloca(gimple stmt)
84694 +{
84695 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
84696 + return true;
84697 +
84698 +#if BUILDING_GCC_VERSION >= 4007
84699 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
84700 + return true;
84701 +#endif
84702 +
84703 + return false;
84704 +}
84705 +
84706 +static unsigned int execute_stackleak_tree_instrument(void)
84707 +{
84708 + basic_block bb, entry_bb;
84709 + bool prologue_instrumented = false, is_leaf = true;
84710 +
84711 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
84712 +
84713 + // 1. loop through BBs and GIMPLE statements
84714 + FOR_EACH_BB(bb) {
84715 + gimple_stmt_iterator gsi;
84716 +
84717 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84718 + gimple stmt;
84719 +
84720 + stmt = gsi_stmt(gsi);
84721 +
84722 + if (is_gimple_call(stmt))
84723 + is_leaf = false;
84724 +
84725 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
84726 + if (!is_alloca(stmt))
84727 + continue;
84728 +
84729 + // 2. insert stack overflow check before each __builtin_alloca call
84730 + stackleak_check_alloca(&gsi);
84731 +
84732 + // 3. insert track call after each __builtin_alloca call
84733 + stackleak_add_instrumentation(&gsi);
84734 + if (bb == entry_bb)
84735 + prologue_instrumented = true;
84736 + }
84737 + }
84738 +
84739 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
84740 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
84741 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
84742 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
84743 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
84744 + return 0;
84745 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
84746 + return 0;
84747 +
84748 + // 4. insert track call at the beginning
84749 + if (!prologue_instrumented) {
84750 + gimple_stmt_iterator gsi;
84751 +
84752 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84753 + if (dom_info_available_p(CDI_DOMINATORS))
84754 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84755 + gsi = gsi_start_bb(bb);
84756 + stackleak_add_instrumentation(&gsi);
84757 + }
84758 +
84759 + return 0;
84760 +}
84761 +
84762 +static unsigned int execute_stackleak_final(void)
84763 +{
84764 + rtx insn;
84765 +
84766 + if (cfun->calls_alloca)
84767 + return 0;
84768 +
84769 + // keep calls only if function frame is big enough
84770 + if (get_frame_size() >= track_frame_size)
84771 + return 0;
84772 +
84773 + // 1. find pax_track_stack calls
84774 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84775 + // 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))
84776 + rtx body;
84777 +
84778 + if (!CALL_P(insn))
84779 + continue;
84780 + body = PATTERN(insn);
84781 + if (GET_CODE(body) != CALL)
84782 + continue;
84783 + body = XEXP(body, 0);
84784 + if (GET_CODE(body) != MEM)
84785 + continue;
84786 + body = XEXP(body, 0);
84787 + if (GET_CODE(body) != SYMBOL_REF)
84788 + continue;
84789 + if (strcmp(XSTR(body, 0), track_function))
84790 + continue;
84791 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84792 + // 2. delete call
84793 + insn = delete_insn_and_edges(insn);
84794 +#if BUILDING_GCC_VERSION >= 4007
84795 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
84796 + insn = delete_insn_and_edges(insn);
84797 +#endif
84798 + }
84799 +
84800 +// print_simple_rtl(stderr, get_insns());
84801 +// print_rtl(stderr, get_insns());
84802 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84803 +
84804 + return 0;
84805 +}
84806 +
84807 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84808 +{
84809 + const char * const plugin_name = plugin_info->base_name;
84810 + const int argc = plugin_info->argc;
84811 + const struct plugin_argument * const argv = plugin_info->argv;
84812 + int i;
84813 + struct register_pass_info stackleak_tree_instrument_pass_info = {
84814 + .pass = &stackleak_tree_instrument_pass.pass,
84815 +// .reference_pass_name = "tree_profile",
84816 + .reference_pass_name = "optimized",
84817 + .ref_pass_instance_number = 0,
84818 + .pos_op = PASS_POS_INSERT_BEFORE
84819 + };
84820 + struct register_pass_info stackleak_final_pass_info = {
84821 + .pass = &stackleak_final_rtl_opt_pass.pass,
84822 + .reference_pass_name = "final",
84823 + .ref_pass_instance_number = 0,
84824 + .pos_op = PASS_POS_INSERT_BEFORE
84825 + };
84826 +
84827 + if (!plugin_default_version_check(version, &gcc_version)) {
84828 + error(G_("incompatible gcc/plugin versions"));
84829 + return 1;
84830 + }
84831 +
84832 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
84833 +
84834 + for (i = 0; i < argc; ++i) {
84835 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
84836 + if (!argv[i].value) {
84837 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84838 + continue;
84839 + }
84840 + track_frame_size = atoi(argv[i].value);
84841 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
84842 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84843 + continue;
84844 + }
84845 + if (!strcmp(argv[i].key, "initialize-locals")) {
84846 + if (argv[i].value) {
84847 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84848 + continue;
84849 + }
84850 + init_locals = true;
84851 + continue;
84852 + }
84853 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84854 + }
84855 +
84856 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
84857 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
84858 +
84859 + return 0;
84860 +}
84861 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
84862 index 6789d78..4afd019 100644
84863 --- a/tools/perf/util/include/asm/alternative-asm.h
84864 +++ b/tools/perf/util/include/asm/alternative-asm.h
84865 @@ -5,4 +5,7 @@
84866
84867 #define altinstruction_entry #
84868
84869 + .macro pax_force_retaddr rip=0, reload=0
84870 + .endm
84871 +
84872 #endif
84873 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
84874 index af0f22f..9a7d479 100644
84875 --- a/usr/gen_init_cpio.c
84876 +++ b/usr/gen_init_cpio.c
84877 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
84878 int retval;
84879 int rc = -1;
84880 int namesize;
84881 - int i;
84882 + unsigned int i;
84883
84884 mode |= S_IFREG;
84885
84886 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
84887 *env_var = *expanded = '\0';
84888 strncat(env_var, start + 2, end - start - 2);
84889 strncat(expanded, new_location, start - new_location);
84890 - strncat(expanded, getenv(env_var), PATH_MAX);
84891 - strncat(expanded, end + 1, PATH_MAX);
84892 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
84893 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
84894 strncpy(new_location, expanded, PATH_MAX);
84895 + new_location[PATH_MAX] = 0;
84896 } else
84897 break;
84898 }
84899 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
84900 index 9739b53..6d457e3 100644
84901 --- a/virt/kvm/kvm_main.c
84902 +++ b/virt/kvm/kvm_main.c
84903 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
84904
84905 static cpumask_var_t cpus_hardware_enabled;
84906 static int kvm_usage_count = 0;
84907 -static atomic_t hardware_enable_failed;
84908 +static atomic_unchecked_t hardware_enable_failed;
84909
84910 struct kmem_cache *kvm_vcpu_cache;
84911 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
84912 @@ -2247,7 +2247,7 @@ static void hardware_enable_nolock(void *junk)
84913
84914 if (r) {
84915 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
84916 - atomic_inc(&hardware_enable_failed);
84917 + atomic_inc_unchecked(&hardware_enable_failed);
84918 printk(KERN_INFO "kvm: enabling virtualization on "
84919 "CPU%d failed\n", cpu);
84920 }
84921 @@ -2301,10 +2301,10 @@ static int hardware_enable_all(void)
84922
84923 kvm_usage_count++;
84924 if (kvm_usage_count == 1) {
84925 - atomic_set(&hardware_enable_failed, 0);
84926 + atomic_set_unchecked(&hardware_enable_failed, 0);
84927 on_each_cpu(hardware_enable_nolock, NULL, 1);
84928
84929 - if (atomic_read(&hardware_enable_failed)) {
84930 + if (atomic_read_unchecked(&hardware_enable_failed)) {
84931 hardware_disable_all_nolock();
84932 r = -EBUSY;
84933 }
84934 @@ -2667,7 +2667,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
84935 kvm_arch_vcpu_put(vcpu);
84936 }
84937
84938 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84939 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84940 struct module *module)
84941 {
84942 int r;
84943 @@ -2730,7 +2730,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84944 if (!vcpu_align)
84945 vcpu_align = __alignof__(struct kvm_vcpu);
84946 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
84947 - 0, NULL);
84948 + SLAB_USERCOPY, NULL);
84949 if (!kvm_vcpu_cache) {
84950 r = -ENOMEM;
84951 goto out_free_3;
84952 @@ -2740,9 +2740,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84953 if (r)
84954 goto out_free;
84955
84956 - kvm_chardev_ops.owner = module;
84957 - kvm_vm_fops.owner = module;
84958 - kvm_vcpu_fops.owner = module;
84959 + pax_open_kernel();
84960 + *(void **)&kvm_chardev_ops.owner = module;
84961 + *(void **)&kvm_vm_fops.owner = module;
84962 + *(void **)&kvm_vcpu_fops.owner = module;
84963 + pax_close_kernel();
84964
84965 r = misc_register(&kvm_dev);
84966 if (r) {